three.source.unit.js 1.5 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900599015990259903599045990559906599075990859909599105991159912599135991459915599165991759918599195992059921599225992359924599255992659927599285992959930599315993259933599345993559936599375993859939599405994159942599435994459945599465994759948599495995059951599525995359954599555995659957599585995959960599615996259963599645996559966599675996859969599705997159972599735997459975599765997759978599795998059981599825998359984599855998659987599885998959990599915999259993599945999559996599975999859999600006000160002600036000460005600066000760008600096001060011600126001360014600156001660017600186001960020600216002260023600246002560026600276002860029600306003160032600336003460035600366003760038600396004060041600426004360044600456004660047600486004960050600516005260053600546005560056600576005860059600606006160062600636006460065600666006760068600696007060071600726007360074600756007660077600786007960080600816008260083600846008560086600876008860089600906009160092600936009460095600966009760098600996010060101601026010360104601056010660107601086010960110601116011260113601146011560116601176011860119601206012160122601236012460125601266012760128601296013060131601326013360134601356013660137601386013960140601416014260143601446014560146601476014860149601506015160152601536015460155601566015760158601596016060161601626016360164601656016660167601686016960170601716017260173601746017560176601776017860179601806018160182601836018460185601866018760188601896019060191601926019360194601956019660197601986019960200602016020260203602046020560206602076020860209602106021160212602136021460215602166021760218602196022060221602226022360224602256022660227602286022960230602316023260233602346023560236602376023860239602406024160242602436024460245602466024760248602496025060251602526025360254602556025660257602586025960260602616026260263602646026560266602676026860269602706027160272602736027460275602766027760278602796028060281602826028360284602856028660287602886028960290602916029260293602946029560296602976029860299603006030160302603036030460305603066030760308603096031060311603126031360314603156031660317603186031960320603216032260323603246032560326603276032860329603306033160332603336033460335603366033760338603396034060341603426034360344603456034660347603486034960350603516035260353603546035560356603576035860359603606036160362603636036460365603666036760368603696037060371603726037360374603756037660377603786037960380603816038260383603846038560386603876038860389603906039160392603936039460395603966039760398603996040060401604026040360404604056040660407604086040960410604116041260413604146041560416604176041860419604206042160422604236042460425604266042760428604296043060431604326043360434604356043660437604386043960440604416044260443604446044560446604476044860449604506045160452604536045460455604566045760458604596046060461604626046360464604656046660467604686046960470604716047260473604746047560476604776047860479604806048160482604836048460485604866048760488604896049060491604926049360494604956049660497604986049960500605016050260503605046050560506605076050860509605106051160512605136051460515605166051760518605196052060521605226052360524605256052660527605286052960530605316053260533605346053560536605376053860539605406054160542605436054460545605466054760548605496055060551605526055360554605556055660557605586055960560605616056260563605646056560566605676056860569605706057160572605736057460575605766057760578605796058060581605826058360584605856058660587605886058960590605916059260593605946059560596605976059860599606006060160602606036060460605606066060760608606096061060611606126061360614606156061660617606186061960620606216062260623606246062560626606276062860629606306063160632606336063460635606366063760638606396064060641606426064360644606456064660647606486064960650606516065260653606546065560656606576065860659606606066160662606636066460665606666066760668606696067060671606726067360674606756067660677606786067960680606816068260683606846068560686606876068860689606906069160692606936069460695606966069760698606996070060701607026070360704607056070660707607086070960710607116071260713607146071560716607176071860719607206072160722607236072460725607266072760728607296073060731607326073360734607356073660737607386073960740607416074260743607446074560746607476074860749607506075160752607536075460755607566075760758607596076060761607626076360764607656076660767607686076960770607716077260773607746077560776607776077860779607806078160782607836078460785607866078760788607896079060791607926079360794607956079660797607986079960800608016080260803608046080560806608076080860809608106081160812608136081460815608166081760818608196082060821608226082360824608256082660827608286082960830608316083260833608346083560836608376083860839608406084160842608436084460845608466084760848608496085060851608526085360854608556085660857608586085960860608616086260863608646086560866608676086860869608706087160872608736087460875608766087760878608796088060881608826088360884608856088660887608886088960890608916089260893608946089560896608976089860899609006090160902609036090460905609066090760908609096091060911609126091360914609156091660917609186091960920609216092260923609246092560926609276092860929609306093160932609336093460935609366093760938609396094060941609426094360944609456094660947609486094960950609516095260953609546095560956609576095860959609606096160962609636096460965609666096760968609696097060971609726097360974609756097660977609786097960980609816098260983609846098560986609876098860989609906099160992609936099460995609966099760998609996100061001610026100361004610056100661007610086100961010610116101261013610146101561016610176101861019610206102161022610236102461025610266102761028610296103061031610326103361034610356103661037610386103961040610416104261043610446104561046610476104861049610506105161052610536105461055610566105761058610596106061061610626106361064610656106661067610686106961070610716107261073610746107561076610776107861079610806108161082610836108461085610866108761088610896109061091610926109361094610956109661097610986109961100611016110261103611046110561106611076110861109611106111161112611136111461115611166111761118611196112061121611226112361124611256112661127611286112961130611316113261133611346113561136611376113861139611406114161142611436114461145611466114761148611496115061151611526115361154611556115661157611586115961160611616116261163611646116561166611676116861169611706117161172611736117461175611766117761178611796118061181611826118361184611856118661187611886118961190611916119261193611946119561196611976119861199612006120161202612036120461205612066120761208612096121061211612126121361214612156121661217612186121961220612216122261223612246122561226612276122861229612306123161232612336123461235612366123761238612396124061241612426124361244612456124661247612486124961250612516125261253612546125561256612576125861259612606126161262612636126461265612666126761268612696127061271612726127361274612756127661277612786127961280612816128261283612846128561286612876128861289612906129161292612936129461295612966129761298612996130061301613026130361304613056130661307613086130961310613116131261313613146131561316613176131861319613206132161322613236132461325613266132761328613296133061331613326133361334613356133661337613386133961340613416134261343613446134561346613476134861349613506135161352613536135461355613566135761358613596136061361613626136361364613656136661367613686136961370613716137261373613746137561376613776137861379613806138161382613836138461385613866138761388613896139061391613926139361394613956139661397613986139961400614016140261403614046140561406614076140861409614106141161412614136141461415614166141761418614196142061421614226142361424614256142661427614286142961430614316143261433614346143561436614376143861439614406144161442614436144461445614466144761448614496145061451614526145361454614556145661457614586145961460614616146261463614646146561466614676146861469614706147161472614736147461475614766147761478614796148061481614826148361484614856148661487614886148961490614916149261493614946149561496614976149861499615006150161502615036150461505615066150761508615096151061511615126151361514615156151661517615186151961520615216152261523615246152561526615276152861529615306153161532615336153461535615366153761538615396154061541615426154361544615456154661547615486154961550615516155261553615546155561556615576155861559615606156161562615636156461565615666156761568615696157061571615726157361574615756157661577615786157961580615816158261583615846158561586615876158861589615906159161592615936159461595615966159761598615996160061601616026160361604616056160661607616086160961610616116161261613616146161561616616176161861619616206162161622616236162461625616266162761628616296163061631616326163361634616356163661637616386163961640616416164261643616446164561646616476164861649616506165161652616536165461655616566165761658616596166061661616626166361664616656166661667616686166961670616716167261673616746167561676616776167861679616806168161682616836168461685616866168761688616896169061691616926169361694616956169661697616986169961700617016170261703617046170561706617076170861709617106171161712617136171461715617166171761718617196172061721617226172361724617256172661727617286172961730617316173261733617346173561736617376173861739617406174161742617436174461745617466174761748617496175061751617526175361754617556175661757617586175961760617616176261763617646176561766617676176861769617706177161772617736177461775617766177761778617796178061781617826178361784617856178661787617886178961790617916179261793617946179561796617976179861799618006180161802618036180461805618066180761808618096181061811618126181361814618156181661817618186181961820618216182261823618246182561826618276182861829618306183161832618336183461835618366183761838618396184061841618426184361844618456184661847618486184961850618516185261853618546185561856618576185861859618606186161862618636186461865618666186761868618696187061871618726187361874618756187661877618786187961880618816188261883618846188561886618876188861889618906189161892618936189461895618966189761898618996190061901619026190361904619056190661907619086190961910619116191261913619146191561916619176191861919619206192161922619236192461925619266192761928619296193061931619326193361934619356193661937619386193961940619416194261943619446194561946619476194861949619506195161952619536195461955619566195761958619596196061961619626196361964619656196661967619686196961970619716197261973619746197561976619776197861979619806198161982619836198461985619866198761988619896199061991619926199361994619956199661997619986199962000620016200262003620046200562006620076200862009620106201162012620136201462015620166201762018620196202062021620226202362024620256202662027620286202962030620316203262033620346203562036620376203862039620406204162042620436204462045620466204762048620496205062051620526205362054620556205662057620586205962060620616206262063620646206562066620676206862069620706207162072620736207462075620766207762078620796208062081620826208362084620856208662087620886208962090620916209262093620946209562096620976209862099621006210162102621036210462105621066210762108621096211062111621126211362114621156211662117621186211962120621216212262123621246212562126621276212862129621306213162132621336213462135621366213762138621396214062141621426214362144621456214662147621486214962150621516215262153621546215562156621576215862159621606216162162621636216462165621666216762168621696217062171621726217362174621756217662177621786217962180621816218262183621846218562186621876218862189621906219162192621936219462195621966219762198621996220062201622026220362204622056220662207622086220962210622116221262213622146221562216622176221862219622206222162222622236222462225622266222762228622296223062231622326223362234622356223662237622386223962240622416224262243622446224562246622476224862249622506225162252622536225462255622566225762258622596226062261622626226362264622656226662267622686226962270622716227262273622746227562276622776227862279622806228162282622836228462285622866228762288622896229062291622926229362294622956229662297622986229962300623016230262303623046230562306623076230862309623106231162312623136231462315623166231762318623196232062321623226232362324623256232662327623286232962330623316233262333623346233562336623376233862339623406234162342623436234462345623466234762348623496235062351623526235362354623556235662357623586235962360623616236262363623646236562366623676236862369623706237162372623736237462375623766237762378623796238062381623826238362384623856238662387623886238962390623916239262393623946239562396623976239862399624006240162402624036240462405624066240762408624096241062411624126241362414624156241662417624186241962420624216242262423624246242562426624276242862429624306243162432624336243462435624366243762438624396244062441624426244362444624456244662447624486244962450624516245262453624546245562456624576245862459624606246162462624636246462465624666246762468624696247062471624726247362474624756247662477624786247962480624816248262483624846248562486624876248862489624906249162492624936249462495624966249762498624996250062501625026250362504625056250662507625086250962510625116251262513625146251562516625176251862519625206252162522625236252462525625266252762528625296253062531625326253362534625356253662537625386253962540625416254262543625446254562546625476254862549625506255162552625536255462555625566255762558625596256062561625626256362564625656256662567625686256962570625716257262573625746257562576625776257862579625806258162582625836258462585625866258762588625896259062591625926259362594625956259662597625986259962600626016260262603626046260562606626076260862609626106261162612626136261462615626166261762618626196262062621626226262362624626256262662627626286262962630626316263262633626346263562636626376263862639626406264162642626436264462645626466264762648626496265062651626526265362654626556265662657626586265962660626616266262663626646266562666626676266862669626706267162672626736267462675626766267762678626796268062681626826268362684626856268662687626886268962690626916269262693626946269562696626976269862699627006270162702627036270462705627066270762708627096271062711627126271362714627156271662717627186271962720627216272262723627246272562726627276272862729627306273162732627336273462735627366273762738627396274062741627426274362744627456274662747627486274962750627516275262753627546275562756627576275862759627606276162762627636276462765627666276762768627696277062771627726277362774627756277662777627786277962780627816278262783627846278562786627876278862789627906279162792627936279462795627966279762798627996280062801628026280362804628056280662807628086280962810628116281262813628146281562816628176281862819628206282162822628236282462825628266282762828628296283062831628326283362834628356283662837628386283962840628416284262843628446284562846628476284862849628506285162852628536285462855628566285762858628596286062861628626286362864628656286662867628686286962870628716287262873628746287562876628776287862879628806288162882628836288462885628866288762888628896289062891628926289362894628956289662897628986289962900629016290262903629046290562906629076290862909629106291162912629136291462915629166291762918629196292062921629226292362924629256292662927629286292962930629316293262933629346293562936629376293862939629406294162942629436294462945629466294762948629496295062951629526295362954629556295662957629586295962960629616296262963629646296562966629676296862969629706297162972629736297462975629766297762978629796298062981629826298362984629856298662987629886298962990629916299262993629946299562996629976299862999630006300163002630036300463005630066300763008630096301063011630126301363014630156301663017630186301963020630216302263023630246302563026630276302863029630306303163032630336303463035630366303763038630396304063041630426304363044630456304663047630486304963050630516305263053630546305563056630576305863059630606306163062630636306463065630666306763068630696307063071630726307363074630756307663077630786307963080630816308263083630846308563086630876308863089630906309163092630936309463095630966309763098630996310063101631026310363104631056310663107631086310963110631116311263113631146311563116631176311863119631206312163122631236312463125631266312763128631296313063131631326313363134631356313663137631386313963140631416314263143631446314563146631476314863149631506315163152631536315463155631566315763158631596316063161631626316363164631656316663167631686316963170631716317263173631746317563176631776317863179631806318163182631836318463185631866318763188631896319063191631926319363194631956319663197631986319963200632016320263203632046320563206632076320863209632106321163212632136321463215632166321763218632196322063221632226322363224632256322663227632286322963230632316323263233632346323563236632376323863239632406324163242632436324463245632466324763248632496325063251632526325363254632556325663257632586325963260632616326263263632646326563266632676326863269632706327163272632736327463275632766327763278632796328063281632826328363284632856328663287632886328963290632916329263293632946329563296632976329863299633006330163302633036330463305633066330763308633096331063311633126331363314633156331663317633186331963320633216332263323633246332563326633276332863329633306333163332633336333463335633366333763338633396334063341633426334363344633456334663347633486334963350633516335263353633546335563356633576335863359633606336163362633636336463365633666336763368633696337063371633726337363374633756337663377633786337963380633816338263383633846338563386633876338863389633906339163392633936339463395633966339763398633996340063401634026340363404634056340663407634086340963410634116341263413634146341563416634176341863419634206342163422634236342463425634266342763428634296343063431634326343363434634356343663437634386343963440634416344263443634446344563446634476344863449634506345163452634536345463455634566345763458634596346063461634626346363464634656346663467634686346963470634716347263473634746347563476634776347863479634806348163482634836348463485634866348763488634896349063491634926349363494634956349663497634986349963500635016350263503635046350563506635076350863509635106351163512635136351463515635166351763518635196352063521635226352363524635256352663527635286352963530635316353263533635346353563536635376353863539635406354163542635436354463545635466354763548635496355063551635526355363554635556355663557635586355963560635616356263563635646356563566635676356863569635706357163572635736357463575635766357763578635796358063581635826358363584635856358663587635886358963590635916359263593635946359563596635976359863599636006360163602636036360463605636066360763608636096361063611636126361363614636156361663617636186361963620636216362263623636246362563626636276362863629636306363163632636336363463635636366363763638636396364063641636426364363644636456364663647636486364963650636516365263653636546365563656636576365863659636606366163662636636366463665636666366763668636696367063671636726367363674636756367663677636786367963680636816368263683636846368563686636876368863689636906369163692636936369463695636966369763698636996370063701637026370363704637056370663707637086370963710637116371263713637146371563716637176371863719637206372163722637236372463725637266372763728637296373063731637326373363734637356373663737637386373963740637416374263743637446374563746637476374863749637506375163752637536375463755637566375763758637596376063761637626376363764637656376663767637686376963770637716377263773637746377563776637776377863779637806378163782637836378463785637866378763788637896379063791637926379363794637956379663797637986379963800638016380263803638046380563806638076380863809638106381163812638136381463815638166381763818638196382063821638226382363824638256382663827638286382963830638316383263833638346383563836638376383863839638406384163842638436384463845638466384763848638496385063851638526385363854638556385663857638586385963860638616386263863638646386563866638676386863869638706387163872638736387463875638766387763878638796388063881638826388363884638856388663887638886388963890638916389263893638946389563896638976389863899639006390163902639036390463905639066390763908639096391063911639126391363914639156391663917639186391963920639216392263923639246392563926639276392863929639306393163932639336393463935639366393763938639396394063941639426394363944639456394663947639486394963950639516395263953639546395563956639576395863959639606396163962639636396463965639666396763968639696397063971639726397363974639756397663977639786397963980639816398263983639846398563986639876398863989639906399163992639936399463995639966399763998639996400064001640026400364004640056400664007640086400964010640116401264013640146401564016640176401864019640206402164022640236402464025640266402764028640296403064031640326403364034640356403664037640386403964040640416404264043640446404564046640476404864049640506405164052640536405464055640566405764058640596406064061640626406364064640656406664067640686406964070640716407264073640746407564076640776407864079640806408164082640836408464085640866408764088640896409064091640926409364094640956409664097640986409964100641016410264103641046410564106641076410864109641106411164112641136411464115641166411764118641196412064121641226412364124641256412664127641286412964130641316413264133641346413564136641376413864139641406414164142641436414464145641466414764148641496415064151641526415364154641556415664157641586415964160641616416264163641646416564166641676416864169641706417164172641736417464175641766417764178641796418064181641826418364184641856418664187641886418964190641916419264193641946419564196641976419864199642006420164202642036420464205642066420764208642096421064211642126421364214642156421664217642186421964220642216422264223642246422564226642276422864229642306423164232642336423464235642366423764238642396424064241642426424364244642456424664247642486424964250642516425264253642546425564256642576425864259642606426164262642636426464265642666426764268642696427064271642726427364274642756427664277642786427964280642816428264283642846428564286642876428864289642906429164292642936429464295642966429764298642996430064301643026430364304643056430664307643086430964310643116431264313643146431564316643176431864319643206432164322643236432464325643266432764328643296433064331643326433364334643356433664337643386433964340643416434264343643446434564346643476434864349643506435164352643536435464355643566435764358643596436064361643626436364364643656436664367643686436964370643716437264373643746437564376643776437864379643806438164382643836438464385643866438764388643896439064391643926439364394643956439664397643986439964400644016440264403644046440564406644076440864409644106441164412644136441464415644166441764418644196442064421644226442364424644256442664427644286442964430644316443264433644346443564436644376443864439644406444164442644436444464445644466444764448644496445064451644526445364454644556445664457644586445964460644616446264463644646446564466644676446864469644706447164472644736447464475644766447764478644796448064481644826448364484644856448664487644886448964490644916449264493644946449564496644976449864499645006450164502645036450464505645066450764508645096451064511645126451364514645156451664517645186451964520645216452264523645246452564526645276452864529645306453164532645336453464535645366453764538645396454064541645426454364544645456454664547645486454964550645516455264553645546455564556645576455864559645606456164562645636456464565645666456764568645696457064571645726457364574645756457664577645786457964580645816458264583645846458564586645876458864589645906459164592645936459464595645966459764598645996460064601646026460364604646056460664607646086460964610646116461264613646146461564616646176461864619646206462164622646236462464625646266462764628646296463064631646326463364634646356463664637646386463964640646416464264643646446464564646646476464864649646506465164652646536465464655646566465764658646596466064661646626466364664646656466664667646686466964670646716467264673646746467564676646776467864679646806468164682646836468464685646866468764688646896469064691646926469364694646956469664697646986469964700647016470264703647046470564706647076470864709647106471164712647136471464715647166471764718647196472064721647226472364724647256472664727647286472964730647316473264733647346473564736647376473864739647406474164742647436474464745647466474764748647496475064751647526475364754647556475664757647586475964760647616476264763647646476564766647676476864769647706477164772647736477464775647766477764778647796478064781647826478364784647856478664787647886478964790647916479264793647946479564796647976479864799648006480164802648036480464805648066480764808648096481064811648126481364814648156481664817648186481964820648216482264823648246482564826648276482864829648306483164832648336483464835648366483764838648396484064841648426484364844648456484664847648486484964850648516485264853648546485564856648576485864859648606486164862648636486464865648666486764868648696487064871648726487364874648756487664877648786487964880648816488264883648846488564886648876488864889648906489164892648936489464895648966489764898648996490064901649026490364904649056490664907649086490964910649116491264913649146491564916649176491864919649206492164922649236492464925649266492764928649296493064931649326493364934649356493664937649386493964940649416494264943649446494564946649476494864949649506495164952649536495464955649566495764958649596496064961649626496364964649656496664967649686496964970649716497264973649746497564976649776497864979649806498164982649836498464985649866498764988649896499064991649926499364994649956499664997649986499965000650016500265003650046500565006650076500865009650106501165012650136501465015650166501765018650196502065021650226502365024650256502665027650286502965030650316503265033650346503565036650376503865039650406504165042650436504465045650466504765048650496505065051650526505365054650556505665057650586505965060650616506265063650646506565066650676506865069650706507165072650736507465075650766507765078650796508065081650826508365084650856508665087650886508965090650916509265093650946509565096650976509865099651006510165102651036510465105651066510765108651096511065111651126511365114651156511665117651186511965120651216512265123651246512565126651276512865129651306513165132651336513465135651366513765138651396514065141651426514365144651456514665147651486514965150651516515265153651546515565156651576515865159651606516165162651636516465165651666516765168651696517065171651726517365174651756517665177651786517965180651816518265183651846518565186651876518865189651906519165192651936519465195651966519765198651996520065201652026520365204652056520665207652086520965210652116521265213652146521565216652176521865219652206522165222652236522465225652266522765228652296523065231652326523365234652356523665237652386523965240652416524265243652446524565246652476524865249652506525165252652536525465255652566525765258652596526065261652626526365264652656526665267652686526965270652716527265273652746527565276652776527865279652806528165282652836528465285652866528765288652896529065291652926529365294652956529665297652986529965300653016530265303653046530565306653076530865309653106531165312653136531465315653166531765318653196532065321653226532365324653256532665327653286532965330653316533265333653346533565336653376533865339653406534165342653436534465345653466534765348653496535065351653526535365354653556535665357653586535965360653616536265363653646536565366653676536865369653706537165372653736537465375653766537765378653796538065381653826538365384653856538665387653886538965390653916539265393653946539565396653976539865399654006540165402654036540465405654066540765408654096541065411654126541365414654156541665417654186541965420654216542265423654246542565426654276542865429654306543165432654336543465435654366543765438654396544065441654426544365444654456544665447654486544965450654516545265453654546545565456654576545865459654606546165462654636546465465654666546765468654696547065471654726547365474654756547665477654786547965480654816548265483654846548565486654876548865489654906549165492654936549465495654966549765498654996550065501655026550365504655056550665507655086550965510655116551265513655146551565516655176551865519655206552165522655236552465525655266552765528655296553065531655326553365534655356553665537655386553965540655416554265543655446554565546655476554865549655506555165552655536555465555655566555765558655596556065561655626556365564655656556665567655686556965570655716557265573655746557565576655776557865579655806558165582655836558465585655866558765588655896559065591655926559365594655956559665597655986559965600656016560265603656046560565606656076560865609656106561165612656136561465615656166561765618656196562065621656226562365624656256562665627656286562965630656316563265633656346563565636656376563865639656406564165642656436564465645656466564765648656496565065651656526565365654656556565665657656586565965660656616566265663656646566565666656676566865669656706567165672656736567465675656766567765678656796568065681656826568365684656856568665687656886568965690656916569265693656946569565696656976569865699657006570165702657036570465705657066570765708657096571065711657126571365714657156571665717657186571965720657216572265723657246572565726657276572865729657306573165732657336573465735657366573765738657396574065741657426574365744657456574665747657486574965750657516575265753657546575565756657576575865759657606576165762657636576465765657666576765768657696577065771657726577365774657756577665777657786577965780657816578265783657846578565786657876578865789657906579165792657936579465795657966579765798657996580065801658026580365804658056580665807658086580965810658116581265813658146581565816658176581865819658206582165822658236582465825658266582765828658296583065831658326583365834658356583665837658386583965840658416584265843658446584565846658476584865849658506585165852658536585465855658566585765858658596586065861658626586365864658656586665867658686586965870658716587265873658746587565876658776587865879658806588165882658836588465885658866588765888658896589065891658926589365894658956589665897658986589965900659016590265903659046590565906659076590865909659106591165912659136591465915659166591765918659196592065921659226592365924659256592665927659286592965930659316593265933659346593565936659376593865939659406594165942659436594465945659466594765948659496595065951659526595365954659556595665957659586595965960659616596265963659646596565966659676596865969659706597165972659736597465975659766597765978659796598065981659826598365984659856598665987659886598965990659916599265993659946599565996659976599865999660006600166002660036600466005660066600766008660096601066011660126601366014660156601666017660186601966020660216602266023660246602566026660276602866029660306603166032660336603466035660366603766038660396604066041660426604366044660456604666047660486604966050660516605266053660546605566056660576605866059660606606166062660636606466065660666606766068660696607066071660726607366074660756607666077660786607966080660816608266083660846608566086660876608866089660906609166092660936609466095660966609766098660996610066101661026610366104661056610666107661086610966110661116611266113661146611566116661176611866119661206612166122661236612466125661266612766128661296613066131661326613366134661356613666137661386613966140661416614266143661446614566146661476614866149661506615166152661536615466155661566615766158661596616066161661626616366164661656616666167661686616966170661716617266173661746617566176661776617866179661806618166182661836618466185661866618766188661896619066191661926619366194661956619666197661986619966200662016620266203662046620566206662076620866209662106621166212662136621466215662166621766218662196622066221662226622366224662256622666227662286622966230662316623266233662346623566236662376623866239662406624166242662436624466245662466624766248662496625066251662526625366254662556625666257662586625966260662616626266263662646626566266662676626866269662706627166272662736627466275662766627766278662796628066281662826628366284662856628666287662886628966290662916629266293662946629566296662976629866299663006630166302663036630466305663066630766308663096631066311663126631366314663156631666317663186631966320663216632266323663246632566326663276632866329663306633166332663336633466335663366633766338663396634066341663426634366344663456634666347663486634966350663516635266353663546635566356663576635866359663606636166362663636636466365663666636766368663696637066371663726637366374663756637666377663786637966380663816638266383663846638566386663876638866389663906639166392663936639466395663966639766398663996640066401664026640366404664056640666407664086640966410664116641266413664146641566416664176641866419664206642166422664236642466425664266642766428664296643066431664326643366434664356643666437664386643966440664416644266443664446644566446664476644866449664506645166452664536645466455664566645766458664596646066461664626646366464664656646666467664686646966470664716647266473664746647566476664776647866479664806648166482664836648466485664866648766488664896649066491664926649366494664956649666497664986649966500665016650266503665046650566506665076650866509665106651166512665136651466515665166651766518665196652066521665226652366524665256652666527665286652966530665316653266533665346653566536665376653866539665406654166542665436654466545665466654766548665496655066551665526655366554665556655666557665586655966560665616656266563665646656566566665676656866569665706657166572665736657466575665766657766578665796658066581665826658366584665856658666587665886658966590665916659266593665946659566596665976659866599666006660166602666036660466605666066660766608666096661066611666126661366614666156661666617666186661966620666216662266623666246662566626666276662866629666306663166632666336663466635666366663766638666396664066641666426664366644666456664666647666486664966650666516665266653666546665566656666576665866659666606666166662666636666466665666666666766668666696667066671666726667366674666756667666677666786667966680666816668266683666846668566686666876668866689666906669166692666936669466695666966669766698666996670066701667026670366704667056670666707667086670966710667116671266713667146671566716667176671866719667206672166722667236672466725667266672766728667296673066731667326673366734667356673666737667386673966740667416674266743667446674566746667476674866749667506675166752667536675466755667566675766758667596676066761667626676366764667656676666767667686676966770667716677266773667746677566776667776677866779667806678166782667836678466785667866678766788667896679066791667926679366794667956679666797667986679966800668016680266803668046680566806668076680866809668106681166812668136681466815668166681766818668196682066821668226682366824668256682666827668286682966830668316683266833668346683566836668376683866839668406684166842668436684466845668466684766848668496685066851668526685366854668556685666857668586685966860668616686266863668646686566866668676686866869668706687166872668736687466875668766687766878668796688066881668826688366884668856688666887668886688966890668916689266893668946689566896668976689866899669006690166902669036690466905669066690766908669096691066911669126691366914669156691666917669186691966920669216692266923669246692566926669276692866929669306693166932669336693466935669366693766938669396694066941669426694366944669456694666947669486694966950669516695266953669546695566956669576695866959669606696166962669636696466965669666696766968669696697066971669726697366974669756697666977669786697966980669816698266983669846698566986669876698866989669906699166992669936699466995669966699766998669996700067001670026700367004670056700667007670086700967010670116701267013670146701567016670176701867019670206702167022670236702467025670266702767028670296703067031670326703367034670356703667037670386703967040670416704267043670446704567046670476704867049670506705167052670536705467055670566705767058670596706067061670626706367064670656706667067670686706967070670716707267073670746707567076670776707867079670806708167082
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (factory());
  5. }(this, (function () { 'use strict';
  6. QUnit.module( "Source", () => {
  7. var REVISION = '88dev';
  8. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  9. var CullFaceNone = 0;
  10. var CullFaceBack = 1;
  11. var CullFaceFront = 2;
  12. var CullFaceFrontBack = 3;
  13. var FrontFaceDirectionCW = 0;
  14. var FrontFaceDirectionCCW = 1;
  15. var BasicShadowMap = 0;
  16. var PCFShadowMap = 1;
  17. var PCFSoftShadowMap = 2;
  18. var FrontSide = 0;
  19. var BackSide = 1;
  20. var DoubleSide = 2;
  21. var FlatShading = 1;
  22. var SmoothShading = 2;
  23. var NoColors = 0;
  24. var FaceColors = 1;
  25. var VertexColors = 2;
  26. var NoBlending = 0;
  27. var NormalBlending = 1;
  28. var AdditiveBlending = 2;
  29. var SubtractiveBlending = 3;
  30. var MultiplyBlending = 4;
  31. var CustomBlending = 5;
  32. var AddEquation = 100;
  33. var SubtractEquation = 101;
  34. var ReverseSubtractEquation = 102;
  35. var MinEquation = 103;
  36. var MaxEquation = 104;
  37. var ZeroFactor = 200;
  38. var OneFactor = 201;
  39. var SrcColorFactor = 202;
  40. var OneMinusSrcColorFactor = 203;
  41. var SrcAlphaFactor = 204;
  42. var OneMinusSrcAlphaFactor = 205;
  43. var DstAlphaFactor = 206;
  44. var OneMinusDstAlphaFactor = 207;
  45. var DstColorFactor = 208;
  46. var OneMinusDstColorFactor = 209;
  47. var SrcAlphaSaturateFactor = 210;
  48. var NeverDepth = 0;
  49. var AlwaysDepth = 1;
  50. var LessDepth = 2;
  51. var LessEqualDepth = 3;
  52. var EqualDepth = 4;
  53. var GreaterEqualDepth = 5;
  54. var GreaterDepth = 6;
  55. var NotEqualDepth = 7;
  56. var MultiplyOperation = 0;
  57. var MixOperation = 1;
  58. var AddOperation = 2;
  59. var NoToneMapping = 0;
  60. var LinearToneMapping = 1;
  61. var ReinhardToneMapping = 2;
  62. var Uncharted2ToneMapping = 3;
  63. var CineonToneMapping = 4;
  64. var UVMapping = 300;
  65. var CubeReflectionMapping = 301;
  66. var CubeRefractionMapping = 302;
  67. var EquirectangularReflectionMapping = 303;
  68. var EquirectangularRefractionMapping = 304;
  69. var SphericalReflectionMapping = 305;
  70. var CubeUVReflectionMapping = 306;
  71. var CubeUVRefractionMapping = 307;
  72. var RepeatWrapping = 1000;
  73. var ClampToEdgeWrapping = 1001;
  74. var MirroredRepeatWrapping = 1002;
  75. var NearestFilter = 1003;
  76. var NearestMipMapNearestFilter = 1004;
  77. var NearestMipMapLinearFilter = 1005;
  78. var LinearFilter = 1006;
  79. var LinearMipMapNearestFilter = 1007;
  80. var LinearMipMapLinearFilter = 1008;
  81. var UnsignedByteType = 1009;
  82. var ByteType = 1010;
  83. var ShortType = 1011;
  84. var UnsignedShortType = 1012;
  85. var IntType = 1013;
  86. var UnsignedIntType = 1014;
  87. var FloatType = 1015;
  88. var HalfFloatType = 1016;
  89. var UnsignedShort4444Type = 1017;
  90. var UnsignedShort5551Type = 1018;
  91. var UnsignedShort565Type = 1019;
  92. var UnsignedInt248Type = 1020;
  93. var AlphaFormat = 1021;
  94. var RGBFormat = 1022;
  95. var RGBAFormat = 1023;
  96. var LuminanceFormat = 1024;
  97. var LuminanceAlphaFormat = 1025;
  98. var RGBEFormat = RGBAFormat;
  99. var DepthFormat = 1026;
  100. var DepthStencilFormat = 1027;
  101. var RGB_S3TC_DXT1_Format = 2001;
  102. var RGBA_S3TC_DXT1_Format = 2002;
  103. var RGBA_S3TC_DXT3_Format = 2003;
  104. var RGBA_S3TC_DXT5_Format = 2004;
  105. var RGB_PVRTC_4BPPV1_Format = 2100;
  106. var RGB_PVRTC_2BPPV1_Format = 2101;
  107. var RGBA_PVRTC_4BPPV1_Format = 2102;
  108. var RGBA_PVRTC_2BPPV1_Format = 2103;
  109. var RGB_ETC1_Format = 2151;
  110. var LoopOnce = 2200;
  111. var LoopRepeat = 2201;
  112. var LoopPingPong = 2202;
  113. var InterpolateDiscrete = 2300;
  114. var InterpolateLinear = 2301;
  115. var InterpolateSmooth = 2302;
  116. var ZeroCurvatureEnding = 2400;
  117. var ZeroSlopeEnding = 2401;
  118. var WrapAroundEnding = 2402;
  119. var TrianglesDrawMode = 0;
  120. var TriangleStripDrawMode = 1;
  121. var TriangleFanDrawMode = 2;
  122. var LinearEncoding = 3000;
  123. var sRGBEncoding = 3001;
  124. var GammaEncoding = 3007;
  125. var RGBEEncoding = 3002;
  126. var LogLuvEncoding = 3003;
  127. var RGBM7Encoding = 3004;
  128. var RGBM16Encoding = 3005;
  129. var RGBDEncoding = 3006;
  130. var BasicDepthPacking = 3200;
  131. var RGBADepthPacking = 3201;
  132. /**
  133. * @author TristanVALCKE / https://github.com/Itee
  134. */
  135. /* global QUnit */
  136. QUnit.module( 'Constants', () => {
  137. QUnit.test( "default values", ( assert ) => {
  138. assert.propEqual( MOUSE, { LEFT: 0, MIDDLE: 1, RIGHT: 2 }, 'MOUSE equal { LEFT: 0, MIDDLE: 1, RIGHT: 2 }' );
  139. assert.equal( CullFaceNone, 0, 'CullFaceNone equal 0' );
  140. assert.equal( CullFaceBack, 1, 'CullFaceBack equal 1' );
  141. assert.equal( CullFaceFront, 2, 'CullFaceFront is equal to 2' );
  142. assert.equal( CullFaceFrontBack, 3, 'CullFaceFrontBack is equal to 3' );
  143. assert.equal( FrontFaceDirectionCW, 0, 'FrontFaceDirectionCW is equal to 0' );
  144. assert.equal( FrontFaceDirectionCCW, 1, 'FrontFaceDirectionCCW is equal to 1' );
  145. assert.equal( BasicShadowMap, 0, 'BasicShadowMap is equal to 0' );
  146. assert.equal( PCFShadowMap, 1, 'PCFShadowMap is equal to 1' );
  147. assert.equal( PCFSoftShadowMap, 2, 'PCFSoftShadowMap is equal to 2' );
  148. assert.equal( FrontSide, 0, 'FrontSide is equal to 0' );
  149. assert.equal( BackSide, 1, 'BackSide is equal to 1' );
  150. assert.equal( DoubleSide, 2, 'DoubleSide is equal to 2' );
  151. assert.equal( FlatShading, 1, 'FlatShading is equal to 1' );
  152. assert.equal( SmoothShading, 2, 'SmoothShading is equal to 2' );
  153. assert.equal( NoColors, 0, 'NoColors is equal to 0' );
  154. assert.equal( FaceColors, 1, 'FaceColors is equal to 1' );
  155. assert.equal( VertexColors, 2, 'VertexColors is equal to 2' );
  156. assert.equal( NoBlending, 0, 'NoBlending is equal to 0' );
  157. assert.equal( NormalBlending, 1, 'NormalBlending is equal to 1' );
  158. assert.equal( AdditiveBlending, 2, 'AdditiveBlending is equal to 2' );
  159. assert.equal( SubtractiveBlending, 3, 'SubtractiveBlending is equal to 3' );
  160. assert.equal( MultiplyBlending, 4, 'MultiplyBlending is equal to 4' );
  161. assert.equal( CustomBlending, 5, 'CustomBlending is equal to 5' );
  162. assert.equal( AddEquation, 100, 'AddEquation is equal to 100' );
  163. assert.equal( SubtractEquation, 101, 'SubtractEquation is equal to 101' );
  164. assert.equal( ReverseSubtractEquation, 102, 'ReverseSubtractEquation is equal to 102' );
  165. assert.equal( MinEquation, 103, 'MinEquation is equal to 103' );
  166. assert.equal( MaxEquation, 104, 'MaxEquation is equal to 104' );
  167. assert.equal( ZeroFactor, 200, 'ZeroFactor is equal to 200' );
  168. assert.equal( OneFactor, 201, 'OneFactor is equal to 201' );
  169. assert.equal( SrcColorFactor, 202, 'SrcColorFactor is equal to 202' );
  170. assert.equal( OneMinusSrcColorFactor, 203, 'OneMinusSrcColorFactor is equal to 203' );
  171. assert.equal( SrcAlphaFactor, 204, 'SrcAlphaFactor is equal to 204' );
  172. assert.equal( OneMinusSrcAlphaFactor, 205, 'OneMinusSrcAlphaFactor is equal to 205' );
  173. assert.equal( DstAlphaFactor, 206, 'DstAlphaFactor is equal to 206' );
  174. assert.equal( OneMinusDstAlphaFactor, 207, 'OneMinusDstAlphaFactor is equal to 207' );
  175. assert.equal( DstColorFactor, 208, 'DstColorFactor is equal to 208' );
  176. assert.equal( OneMinusDstColorFactor, 209, 'OneMinusDstColorFactor is equal to 209' );
  177. assert.equal( SrcAlphaSaturateFactor, 210, 'SrcAlphaSaturateFactor is equal to 210' );
  178. assert.equal( NeverDepth, 0, 'NeverDepth is equal to 0' );
  179. assert.equal( AlwaysDepth, 1, 'AlwaysDepth is equal to 1' );
  180. assert.equal( LessDepth, 2, 'LessDepth is equal to 2' );
  181. assert.equal( LessEqualDepth, 3, 'LessEqualDepth is equal to 3' );
  182. assert.equal( EqualDepth, 4, 'EqualDepth is equal to 4' );
  183. assert.equal( GreaterEqualDepth, 5, 'GreaterEqualDepth is equal to 5' );
  184. assert.equal( GreaterDepth, 6, 'GreaterDepth is equal to 6' );
  185. assert.equal( NotEqualDepth, 7, 'NotEqualDepth is equal to 7' );
  186. assert.equal( MultiplyOperation, 0, 'MultiplyOperation is equal to 0' );
  187. assert.equal( MixOperation, 1, 'MixOperation is equal to 1' );
  188. assert.equal( AddOperation, 2, 'AddOperation is equal to 2' );
  189. assert.equal( NoToneMapping, 0, 'NoToneMapping is equal to 0' );
  190. assert.equal( LinearToneMapping, 1, 'LinearToneMapping is equal to 1' );
  191. assert.equal( ReinhardToneMapping, 2, 'ReinhardToneMapping is equal to 2' );
  192. assert.equal( Uncharted2ToneMapping, 3, 'Uncharted2ToneMapping is equal to 3' );
  193. assert.equal( CineonToneMapping, 4, 'CineonToneMapping is equal to 4' );
  194. assert.equal( UVMapping, 300, 'UVMapping is equal to 300' );
  195. assert.equal( CubeReflectionMapping, 301, 'CubeReflectionMapping is equal to 301' );
  196. assert.equal( CubeRefractionMapping, 302, 'CubeRefractionMapping is equal to 302' );
  197. assert.equal( EquirectangularReflectionMapping, 303, 'EquirectangularReflectionMapping is equal to 303' );
  198. assert.equal( EquirectangularRefractionMapping, 304, 'EquirectangularRefractionMapping is equal to 304' );
  199. assert.equal( SphericalReflectionMapping, 305, 'SphericalReflectionMapping is equal to 305' );
  200. assert.equal( CubeUVReflectionMapping, 306, 'CubeUVReflectionMapping is equal to 306' );
  201. assert.equal( CubeUVRefractionMapping, 307, 'CubeUVRefractionMapping is equal to 307' );
  202. assert.equal( RepeatWrapping, 1000, 'RepeatWrapping is equal to 1000' );
  203. assert.equal( ClampToEdgeWrapping, 1001, 'ClampToEdgeWrapping is equal to 1001' );
  204. assert.equal( MirroredRepeatWrapping, 1002, 'MirroredRepeatWrapping is equal to 1002' );
  205. assert.equal( NearestFilter, 1003, 'NearestFilter is equal to 1003' );
  206. assert.equal( NearestMipMapNearestFilter, 1004, 'NearestMipMapNearestFilter is equal to 1004' );
  207. assert.equal( NearestMipMapLinearFilter, 1005, 'NearestMipMapLinearFilter is equal to 1005' );
  208. assert.equal( LinearFilter, 1006, 'LinearFilter is equal to 1006' );
  209. assert.equal( LinearMipMapNearestFilter, 1007, 'LinearMipMapNearestFilter is equal to 1007' );
  210. assert.equal( LinearMipMapLinearFilter, 1008, 'LinearMipMapLinearFilter is equal to 1008' );
  211. assert.equal( UnsignedByteType, 1009, 'UnsignedByteType is equal to 1009' );
  212. assert.equal( ByteType, 1010, 'ByteType is equal to 1010' );
  213. assert.equal( ShortType, 1011, 'ShortType is equal to 1011' );
  214. assert.equal( UnsignedShortType, 1012, 'UnsignedShortType is equal to 1012' );
  215. assert.equal( IntType, 1013, 'IntType is equal to 1013' );
  216. assert.equal( UnsignedIntType, 1014, 'UnsignedIntType is equal to 1014' );
  217. assert.equal( FloatType, 1015, 'FloatType is equal to 1015' );
  218. assert.equal( HalfFloatType, 1016, 'HalfFloatType is equal to 1016' );
  219. assert.equal( UnsignedShort4444Type, 1017, 'UnsignedShort4444Type is equal to 1017' );
  220. assert.equal( UnsignedShort5551Type, 1018, 'UnsignedShort5551Type is equal to 1018' );
  221. assert.equal( UnsignedShort565Type, 1019, 'UnsignedShort565Type is equal to 1019' );
  222. assert.equal( UnsignedInt248Type, 1020, 'UnsignedInt248Type is equal to 1020' );
  223. assert.equal( AlphaFormat, 1021, 'AlphaFormat is equal to 1021' );
  224. assert.equal( RGBFormat, 1022, 'RGBFormat is equal to 1022' );
  225. assert.equal( RGBAFormat, 1023, 'RGBAFormat is equal to 1023' );
  226. assert.equal( LuminanceFormat, 1024, 'LuminanceFormat is equal to 1024' );
  227. assert.equal( LuminanceAlphaFormat, 1025, 'LuminanceAlphaFormat is equal to 1025' );
  228. assert.equal( RGBEFormat, RGBAFormat, 'RGBEFormat is equal to RGBAFormat' );
  229. assert.equal( DepthFormat, 1026, 'DepthFormat is equal to 1026' );
  230. assert.equal( DepthStencilFormat, 1027, 'DepthStencilFormat is equal to 1027' );
  231. assert.equal( RGB_S3TC_DXT1_Format, 2001, 'RGB_S3TC_DXT1_Format is equal to 2001' );
  232. assert.equal( RGBA_S3TC_DXT1_Format, 2002, 'RGBA_S3TC_DXT1_Format is equal to 2002' );
  233. assert.equal( RGBA_S3TC_DXT3_Format, 2003, 'RGBA_S3TC_DXT3_Format is equal to 2003' );
  234. assert.equal( RGBA_S3TC_DXT5_Format, 2004, 'RGBA_S3TC_DXT5_Format is equal to 2004' );
  235. assert.equal( RGB_PVRTC_4BPPV1_Format, 2100, 'RGB_PVRTC_4BPPV1_Format is equal to 2100' );
  236. assert.equal( RGB_PVRTC_2BPPV1_Format, 2101, 'RGB_PVRTC_2BPPV1_Format is equal to 2101' );
  237. assert.equal( RGBA_PVRTC_4BPPV1_Format, 2102, 'RGBA_PVRTC_4BPPV1_Format is equal to 2102' );
  238. assert.equal( RGBA_PVRTC_2BPPV1_Format, 2103, 'RGBA_PVRTC_2BPPV1_Format is equal to 2103' );
  239. assert.equal( RGB_ETC1_Format, 2151, 'RGB_ETC1_Format is equal to 2151' );
  240. assert.equal( LoopOnce, 2200, 'LoopOnce is equal to 2200' );
  241. assert.equal( LoopRepeat, 2201, 'LoopRepeat is equal to 2201' );
  242. assert.equal( LoopPingPong, 2202, 'LoopPingPong is equal to 2202' );
  243. assert.equal( InterpolateDiscrete, 2300, 'InterpolateDiscrete is equal to 2300' );
  244. assert.equal( InterpolateLinear, 2301, 'InterpolateLinear is equal to 2301' );
  245. assert.equal( InterpolateSmooth, 2302, 'InterpolateSmooth is equal to 2302' );
  246. assert.equal( ZeroCurvatureEnding, 2400, 'ZeroCurvatureEnding is equal to 2400' );
  247. assert.equal( ZeroSlopeEnding, 2401, 'ZeroSlopeEnding is equal to 2401' );
  248. assert.equal( WrapAroundEnding, 2402, 'WrapAroundEnding is equal to 2402' );
  249. assert.equal( TrianglesDrawMode, 0, 'TrianglesDrawMode is equal to 0' );
  250. assert.equal( TriangleStripDrawMode, 1, 'TriangleStripDrawMode is equal to 1' );
  251. assert.equal( TriangleFanDrawMode, 2, 'TriangleFanDrawMode is equal to 2' );
  252. assert.equal( LinearEncoding, 3000, 'LinearEncoding is equal to 3000' );
  253. assert.equal( sRGBEncoding, 3001, 'sRGBEncoding is equal to 3001' );
  254. assert.equal( GammaEncoding, 3007, 'GammaEncoding is equal to 3007' );
  255. assert.equal( RGBEEncoding, 3002, 'RGBEEncoding is equal to 3002' );
  256. assert.equal( LogLuvEncoding, 3003, 'LogLuvEncoding is equal to 3003' );
  257. assert.equal( RGBM7Encoding, 3004, 'RGBM7Encoding is equal to 3004' );
  258. assert.equal( RGBM16Encoding, 3005, 'RGBM16Encoding is equal to 3005' );
  259. assert.equal( RGBDEncoding, 3006, 'RGBDEncoding is equal to 3006' );
  260. assert.equal( BasicDepthPacking, 3200, 'BasicDepthPacking is equal to 3200' );
  261. assert.equal( RGBADepthPacking, 3201, 'RGBADepthPacking is equal to 3201' );
  262. } );
  263. } );
  264. // Polyfills
  265. if ( Number.EPSILON === undefined ) {
  266. Number.EPSILON = Math.pow( 2, - 52 );
  267. }
  268. if ( Number.isInteger === undefined ) {
  269. // Missing in IE
  270. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  271. Number.isInteger = function ( value ) {
  272. return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value;
  273. };
  274. }
  275. //
  276. if ( Math.sign === undefined ) {
  277. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  278. Math.sign = function ( x ) {
  279. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  280. };
  281. }
  282. if ( 'name' in Function.prototype === false ) {
  283. // Missing in IE
  284. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  285. Object.defineProperty( Function.prototype, 'name', {
  286. get: function () {
  287. return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
  288. }
  289. } );
  290. }
  291. if ( Object.assign === undefined ) {
  292. // Missing in IE
  293. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  294. ( function () {
  295. Object.assign = function ( target ) {
  296. 'use strict';
  297. if ( target === undefined || target === null ) {
  298. throw new TypeError( 'Cannot convert undefined or null to object' );
  299. }
  300. var output = Object( target );
  301. for ( var index = 1; index < arguments.length; index ++ ) {
  302. var source = arguments[ index ];
  303. if ( source !== undefined && source !== null ) {
  304. for ( var nextKey in source ) {
  305. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  306. output[ nextKey ] = source[ nextKey ];
  307. }
  308. }
  309. }
  310. }
  311. return output;
  312. };
  313. } )();
  314. }
  315. /**
  316. * @author alteredq / http://alteredqualia.com/
  317. * @author mrdoob / http://mrdoob.com/
  318. */
  319. var _Math = {
  320. DEG2RAD: Math.PI / 180,
  321. RAD2DEG: 180 / Math.PI,
  322. generateUUID: function () {
  323. // http://www.broofa.com/Tools/Math.uuid.htm
  324. // Replaced .join with string concatenation (@takahirox)
  325. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  326. var rnd = 0, r;
  327. return function generateUUID() {
  328. var uuid = '';
  329. for ( var i = 0; i < 36; i ++ ) {
  330. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  331. uuid += '-';
  332. } else if ( i === 14 ) {
  333. uuid += '4';
  334. } else {
  335. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  336. r = rnd & 0xf;
  337. rnd = rnd >> 4;
  338. uuid += chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  339. }
  340. }
  341. return uuid;
  342. };
  343. }(),
  344. clamp: function ( value, min, max ) {
  345. return Math.max( min, Math.min( max, value ) );
  346. },
  347. // compute euclidian modulo of m % n
  348. // https://en.wikipedia.org/wiki/Modulo_operation
  349. euclideanModulo: function ( n, m ) {
  350. return ( ( n % m ) + m ) % m;
  351. },
  352. // Linear mapping from range <a1, a2> to range <b1, b2>
  353. mapLinear: function ( x, a1, a2, b1, b2 ) {
  354. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  355. },
  356. // https://en.wikipedia.org/wiki/Linear_interpolation
  357. lerp: function ( x, y, t ) {
  358. return ( 1 - t ) * x + t * y;
  359. },
  360. // http://en.wikipedia.org/wiki/Smoothstep
  361. smoothstep: function ( x, min, max ) {
  362. if ( x <= min ) return 0;
  363. if ( x >= max ) return 1;
  364. x = ( x - min ) / ( max - min );
  365. return x * x * ( 3 - 2 * x );
  366. },
  367. smootherstep: function ( x, min, max ) {
  368. if ( x <= min ) return 0;
  369. if ( x >= max ) return 1;
  370. x = ( x - min ) / ( max - min );
  371. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  372. },
  373. // Random integer from <low, high> interval
  374. randInt: function ( low, high ) {
  375. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  376. },
  377. // Random float from <low, high> interval
  378. randFloat: function ( low, high ) {
  379. return low + Math.random() * ( high - low );
  380. },
  381. // Random float from <-range/2, range/2> interval
  382. randFloatSpread: function ( range ) {
  383. return range * ( 0.5 - Math.random() );
  384. },
  385. degToRad: function ( degrees ) {
  386. return degrees * _Math.DEG2RAD;
  387. },
  388. radToDeg: function ( radians ) {
  389. return radians * _Math.RAD2DEG;
  390. },
  391. isPowerOfTwo: function ( value ) {
  392. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  393. },
  394. ceilPowerOfTwo: function ( value ) {
  395. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  396. },
  397. floorPowerOfTwo: function ( value ) {
  398. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  399. }
  400. };
  401. /**
  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. return this.crossVectors( this, v );
  1678. },
  1679. crossVectors: function ( a, b ) {
  1680. var ax = a.x, ay = a.y, az = a.z;
  1681. var bx = b.x, by = b.y, bz = b.z;
  1682. this.x = ay * bz - az * by;
  1683. this.y = az * bx - ax * bz;
  1684. this.z = ax * by - ay * bx;
  1685. return this;
  1686. },
  1687. projectOnVector: function ( vector ) {
  1688. var scalar = vector.dot( this ) / vector.lengthSq();
  1689. return this.copy( vector ).multiplyScalar( scalar );
  1690. },
  1691. projectOnPlane: function () {
  1692. var v1 = new Vector3();
  1693. return function projectOnPlane( planeNormal ) {
  1694. v1.copy( this ).projectOnVector( planeNormal );
  1695. return this.sub( v1 );
  1696. };
  1697. }(),
  1698. reflect: function () {
  1699. // reflect incident vector off plane orthogonal to normal
  1700. // normal is assumed to have unit length
  1701. var v1 = new Vector3();
  1702. return function reflect( normal ) {
  1703. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1704. };
  1705. }(),
  1706. angleTo: function ( v ) {
  1707. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1708. // clamp, to handle numerical problems
  1709. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1710. },
  1711. distanceTo: function ( v ) {
  1712. return Math.sqrt( this.distanceToSquared( v ) );
  1713. },
  1714. distanceToSquared: function ( v ) {
  1715. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1716. return dx * dx + dy * dy + dz * dz;
  1717. },
  1718. manhattanDistanceTo: function ( v ) {
  1719. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1720. },
  1721. setFromSpherical: function ( s ) {
  1722. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1723. this.x = sinPhiRadius * Math.sin( s.theta );
  1724. this.y = Math.cos( s.phi ) * s.radius;
  1725. this.z = sinPhiRadius * Math.cos( s.theta );
  1726. return this;
  1727. },
  1728. setFromCylindrical: function ( c ) {
  1729. this.x = c.radius * Math.sin( c.theta );
  1730. this.y = c.y;
  1731. this.z = c.radius * Math.cos( c.theta );
  1732. return this;
  1733. },
  1734. setFromMatrixPosition: function ( m ) {
  1735. var e = m.elements;
  1736. this.x = e[ 12 ];
  1737. this.y = e[ 13 ];
  1738. this.z = e[ 14 ];
  1739. return this;
  1740. },
  1741. setFromMatrixScale: function ( m ) {
  1742. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1743. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1744. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1745. this.x = sx;
  1746. this.y = sy;
  1747. this.z = sz;
  1748. return this;
  1749. },
  1750. setFromMatrixColumn: function ( m, index ) {
  1751. return this.fromArray( m.elements, index * 4 );
  1752. },
  1753. equals: function ( v ) {
  1754. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1755. },
  1756. fromArray: function ( array, offset ) {
  1757. if ( offset === undefined ) offset = 0;
  1758. this.x = array[ offset ];
  1759. this.y = array[ offset + 1 ];
  1760. this.z = array[ offset + 2 ];
  1761. return this;
  1762. },
  1763. toArray: function ( array, offset ) {
  1764. if ( array === undefined ) array = [];
  1765. if ( offset === undefined ) offset = 0;
  1766. array[ offset ] = this.x;
  1767. array[ offset + 1 ] = this.y;
  1768. array[ offset + 2 ] = this.z;
  1769. return array;
  1770. },
  1771. fromBufferAttribute: function ( attribute, index, offset ) {
  1772. if ( offset !== undefined ) {
  1773. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1774. }
  1775. this.x = attribute.getX( index );
  1776. this.y = attribute.getY( index );
  1777. this.z = attribute.getZ( index );
  1778. return this;
  1779. }
  1780. } );
  1781. /**
  1782. * @author TristanVALCKE / https://github.com/Itee
  1783. */
  1784. /* global QUnit */
  1785. QUnit.module.todo( 'Polyfills', () => {
  1786. // PUBLIC STUFF
  1787. QUnit.test( "Number.EPSILON", ( assert ) => {
  1788. assert.ok( false, "everything's gonna be alright" );
  1789. } );
  1790. QUnit.test( "Number.isInteger", ( assert ) => {
  1791. assert.ok( false, "everything's gonna be alright" );
  1792. } );
  1793. //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  1794. //http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.sign
  1795. /*
  1796. 20.2.2.29 Math.sign(x)
  1797. Returns the sign of the x, indicating whether x is positive, negative or zero.
  1798. If x is NaN, the result is NaN.
  1799. If x is -0, the result is -0.
  1800. If x is +0, the result is +0.
  1801. If x is negative and not -0, the result is -1.
  1802. If x is positive and not +0, the result is +1.
  1803. */
  1804. QUnit.test( "Math.sign", ( assert ) => {
  1805. assert.ok( isNaN( Math.sign( NaN ) ), "If x is NaN<NaN>, the result is NaN." );
  1806. assert.ok( isNaN( Math.sign( new Vector3() ) ), "If x is NaN<object>, the result is NaN." );
  1807. assert.ok( isNaN( Math.sign() ), "If x is NaN<undefined>, the result is NaN." );
  1808. assert.ok( isNaN( Math.sign( '--3' ) ), "If x is NaN<'--3'>, the result is NaN." );
  1809. assert.ok( isNegativeZero( Math.sign( - 0 ) ), "If x is -0, the result is -0." );
  1810. assert.ok( Math.sign( + 0 ) === + 0, "If x is +0, the result is +0." );
  1811. assert.ok( Math.sign( - Infinity ) === - 1, "If x is negative<-Infinity> and not -0, the result is -1." );
  1812. assert.ok( Math.sign( '-3' ) === - 1, "If x is negative<'-3'> and not -0, the result is -1." );
  1813. assert.ok( Math.sign( '-1e-10' ) === - 1, "If x is negative<'-1e-10'> and not -0, the result is -1." );
  1814. assert.ok( Math.sign( + Infinity ) === + 1, "If x is positive<+Infinity> and not +0, the result is +1." );
  1815. assert.ok( Math.sign( '+3' ) === + 1, "If x is positive<'+3'> and not +0, the result is +1." );
  1816. // Comparing with -0 is tricky because 0 === -0. But
  1817. // luckily 1 / -0 === -Infinity so we can use that.
  1818. function isNegativeZero( value ) {
  1819. return value === 0 && 1 / value < 0;
  1820. }
  1821. } );
  1822. QUnit.test( "'name' in Function.prototype", ( assert ) => {
  1823. assert.ok( false, "everything's gonna be alright" );
  1824. } );
  1825. QUnit.test( "Object.assign", ( assert ) => {
  1826. assert.ok( false, "everything's gonna be alright" );
  1827. } );
  1828. } );
  1829. /**
  1830. * @author mrdoob / http://mrdoob.com/
  1831. */
  1832. function arrayMin( array ) {
  1833. if ( array.length === 0 ) return Infinity;
  1834. var min = array[ 0 ];
  1835. for ( var i = 1, l = array.length; i < l; ++ i ) {
  1836. if ( array[ i ] < min ) min = array[ i ];
  1837. }
  1838. return min;
  1839. }
  1840. function arrayMax( array ) {
  1841. if ( array.length === 0 ) return - Infinity;
  1842. var max = array[ 0 ];
  1843. for ( var i = 1, l = array.length; i < l; ++ i ) {
  1844. if ( array[ i ] > max ) max = array[ i ];
  1845. }
  1846. return max;
  1847. }
  1848. /**
  1849. * @author alemures / https://github.com/alemures
  1850. * @author TristanVALCKE / https://github.com/Itee
  1851. */
  1852. /* global QUnit */
  1853. QUnit.module( 'utils', () => {
  1854. QUnit.test( 'arrayMin', ( assert ) => {
  1855. assert.equal( arrayMin( [] ), Infinity, 'Empty array return positive infinit' );
  1856. assert.equal( arrayMin( [ 5 ] ), 5, 'Single valued array should return the unique value as minimum' );
  1857. assert.equal( arrayMin( [ 1, 5, 10 ] ), 1, 'The array [ 1, 5, 10 ] return 1' );
  1858. assert.equal( arrayMin( [ 5, 1, 10 ] ), 1, 'The array [ 5, 1, 10 ] return 1' );
  1859. assert.equal( arrayMin( [ 10, 5, 1 ] ), 1, 'The array [ 10, 5, 1 ] return 1' );
  1860. assert.equal( arrayMax( [ - 0, 0 ] ), - 0, 'The array [ - 0, 0 ] return -0' );
  1861. assert.equal( arrayMin( [ - Infinity, 0, Infinity ] ), - Infinity, 'The array [ - Infinity, 0, Infinity ] return -Infinity' );
  1862. } );
  1863. QUnit.test( 'arrayMax', ( assert ) => {
  1864. assert.equal( arrayMax( [] ), - Infinity, 'Empty array return negative infinit' );
  1865. assert.equal( arrayMax( [ 5 ] ), 5, 'Single valued array should return the unique value as maximum' );
  1866. assert.equal( arrayMax( [ 10, 5, 1 ] ), 10, 'The array [ 10, 5, 1 ] return 10' );
  1867. assert.equal( arrayMax( [ 1, 10, 5 ] ), 10, 'The array [ 1, 10, 5 ] return 10' );
  1868. assert.equal( arrayMax( [ 1, 5, 10 ] ), 10, 'The array [ 1, 5, 10 ] return 10' );
  1869. assert.equal( arrayMax( [ - 0, 0 ] ), 0, 'The array [ - 0, 0 ] return 0' );
  1870. assert.equal( arrayMax( [ - Infinity, 0, Infinity ] ), Infinity, 'The array [ - Infinity, 0, Infinity ] return Infinity' );
  1871. } );
  1872. } );
  1873. /**
  1874. *
  1875. * Action provided by AnimationMixer for scheduling clip playback on specific
  1876. * objects.
  1877. *
  1878. * @author Ben Houston / http://clara.io/
  1879. * @author David Sarno / http://lighthaus.us/
  1880. * @author tschw
  1881. *
  1882. */
  1883. function AnimationAction( mixer, clip, localRoot ) {
  1884. this._mixer = mixer;
  1885. this._clip = clip;
  1886. this._localRoot = localRoot || null;
  1887. var tracks = clip.tracks,
  1888. nTracks = tracks.length,
  1889. interpolants = new Array( nTracks );
  1890. var interpolantSettings = {
  1891. endingStart: ZeroCurvatureEnding,
  1892. endingEnd: ZeroCurvatureEnding
  1893. };
  1894. for ( var i = 0; i !== nTracks; ++ i ) {
  1895. var interpolant = tracks[ i ].createInterpolant( null );
  1896. interpolants[ i ] = interpolant;
  1897. interpolant.settings = interpolantSettings;
  1898. }
  1899. this._interpolantSettings = interpolantSettings;
  1900. this._interpolants = interpolants; // bound by the mixer
  1901. // inside: PropertyMixer (managed by the mixer)
  1902. this._propertyBindings = new Array( nTracks );
  1903. this._cacheIndex = null; // for the memory manager
  1904. this._byClipCacheIndex = null; // for the memory manager
  1905. this._timeScaleInterpolant = null;
  1906. this._weightInterpolant = null;
  1907. this.loop = LoopRepeat;
  1908. this._loopCount = - 1;
  1909. // global mixer time when the action is to be started
  1910. // it's set back to 'null' upon start of the action
  1911. this._startTime = null;
  1912. // scaled local time of the action
  1913. // gets clamped or wrapped to 0..clip.duration according to loop
  1914. this.time = 0;
  1915. this.timeScale = 1;
  1916. this._effectiveTimeScale = 1;
  1917. this.weight = 1;
  1918. this._effectiveWeight = 1;
  1919. this.repetitions = Infinity; // no. of repetitions when looping
  1920. this.paused = false; // true -> zero effective time scale
  1921. this.enabled = true; // false -> zero effective weight
  1922. this.clampWhenFinished = false; // keep feeding the last frame?
  1923. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  1924. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  1925. }
  1926. Object.assign( AnimationAction.prototype, {
  1927. // State & Scheduling
  1928. play: function () {
  1929. this._mixer._activateAction( this );
  1930. return this;
  1931. },
  1932. stop: function () {
  1933. this._mixer._deactivateAction( this );
  1934. return this.reset();
  1935. },
  1936. reset: function () {
  1937. this.paused = false;
  1938. this.enabled = true;
  1939. this.time = 0; // restart clip
  1940. this._loopCount = - 1; // forget previous loops
  1941. this._startTime = null; // forget scheduling
  1942. return this.stopFading().stopWarping();
  1943. },
  1944. isRunning: function () {
  1945. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  1946. this._startTime === null && this._mixer._isActiveAction( this );
  1947. },
  1948. // return true when play has been called
  1949. isScheduled: function () {
  1950. return this._mixer._isActiveAction( this );
  1951. },
  1952. startAt: function ( time ) {
  1953. this._startTime = time;
  1954. return this;
  1955. },
  1956. setLoop: function ( mode, repetitions ) {
  1957. this.loop = mode;
  1958. this.repetitions = repetitions;
  1959. return this;
  1960. },
  1961. // Weight
  1962. // set the weight stopping any scheduled fading
  1963. // although .enabled = false yields an effective weight of zero, this
  1964. // method does *not* change .enabled, because it would be confusing
  1965. setEffectiveWeight: function ( weight ) {
  1966. this.weight = weight;
  1967. // note: same logic as when updated at runtime
  1968. this._effectiveWeight = this.enabled ? weight : 0;
  1969. return this.stopFading();
  1970. },
  1971. // return the weight considering fading and .enabled
  1972. getEffectiveWeight: function () {
  1973. return this._effectiveWeight;
  1974. },
  1975. fadeIn: function ( duration ) {
  1976. return this._scheduleFading( duration, 0, 1 );
  1977. },
  1978. fadeOut: function ( duration ) {
  1979. return this._scheduleFading( duration, 1, 0 );
  1980. },
  1981. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  1982. fadeOutAction.fadeOut( duration );
  1983. this.fadeIn( duration );
  1984. if ( warp ) {
  1985. var fadeInDuration = this._clip.duration,
  1986. fadeOutDuration = fadeOutAction._clip.duration,
  1987. startEndRatio = fadeOutDuration / fadeInDuration,
  1988. endStartRatio = fadeInDuration / fadeOutDuration;
  1989. fadeOutAction.warp( 1.0, startEndRatio, duration );
  1990. this.warp( endStartRatio, 1.0, duration );
  1991. }
  1992. return this;
  1993. },
  1994. crossFadeTo: function ( fadeInAction, duration, warp ) {
  1995. return fadeInAction.crossFadeFrom( this, duration, warp );
  1996. },
  1997. stopFading: function () {
  1998. var weightInterpolant = this._weightInterpolant;
  1999. if ( weightInterpolant !== null ) {
  2000. this._weightInterpolant = null;
  2001. this._mixer._takeBackControlInterpolant( weightInterpolant );
  2002. }
  2003. return this;
  2004. },
  2005. // Time Scale Control
  2006. // set the time scale stopping any scheduled warping
  2007. // although .paused = true yields an effective time scale of zero, this
  2008. // method does *not* change .paused, because it would be confusing
  2009. setEffectiveTimeScale: function ( timeScale ) {
  2010. this.timeScale = timeScale;
  2011. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  2012. return this.stopWarping();
  2013. },
  2014. // return the time scale considering warping and .paused
  2015. getEffectiveTimeScale: function () {
  2016. return this._effectiveTimeScale;
  2017. },
  2018. setDuration: function ( duration ) {
  2019. this.timeScale = this._clip.duration / duration;
  2020. return this.stopWarping();
  2021. },
  2022. syncWith: function ( action ) {
  2023. this.time = action.time;
  2024. this.timeScale = action.timeScale;
  2025. return this.stopWarping();
  2026. },
  2027. halt: function ( duration ) {
  2028. return this.warp( this._effectiveTimeScale, 0, duration );
  2029. },
  2030. warp: function ( startTimeScale, endTimeScale, duration ) {
  2031. var mixer = this._mixer, now = mixer.time,
  2032. interpolant = this._timeScaleInterpolant,
  2033. timeScale = this.timeScale;
  2034. if ( interpolant === null ) {
  2035. interpolant = mixer._lendControlInterpolant();
  2036. this._timeScaleInterpolant = interpolant;
  2037. }
  2038. var times = interpolant.parameterPositions,
  2039. values = interpolant.sampleValues;
  2040. times[ 0 ] = now;
  2041. times[ 1 ] = now + duration;
  2042. values[ 0 ] = startTimeScale / timeScale;
  2043. values[ 1 ] = endTimeScale / timeScale;
  2044. return this;
  2045. },
  2046. stopWarping: function () {
  2047. var timeScaleInterpolant = this._timeScaleInterpolant;
  2048. if ( timeScaleInterpolant !== null ) {
  2049. this._timeScaleInterpolant = null;
  2050. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  2051. }
  2052. return this;
  2053. },
  2054. // Object Accessors
  2055. getMixer: function () {
  2056. return this._mixer;
  2057. },
  2058. getClip: function () {
  2059. return this._clip;
  2060. },
  2061. getRoot: function () {
  2062. return this._localRoot || this._mixer._root;
  2063. },
  2064. // Interna
  2065. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  2066. // called by the mixer
  2067. if ( ! this.enabled ) {
  2068. // call ._updateWeight() to update ._effectiveWeight
  2069. this._updateWeight( time );
  2070. return;
  2071. }
  2072. var startTime = this._startTime;
  2073. if ( startTime !== null ) {
  2074. // check for scheduled start of action
  2075. var timeRunning = ( time - startTime ) * timeDirection;
  2076. if ( timeRunning < 0 || timeDirection === 0 ) {
  2077. return; // yet to come / don't decide when delta = 0
  2078. }
  2079. // start
  2080. this._startTime = null; // unschedule
  2081. deltaTime = timeDirection * timeRunning;
  2082. }
  2083. // apply time scale and advance time
  2084. deltaTime *= this._updateTimeScale( time );
  2085. var clipTime = this._updateTime( deltaTime );
  2086. // note: _updateTime may disable the action resulting in
  2087. // an effective weight of 0
  2088. var weight = this._updateWeight( time );
  2089. if ( weight > 0 ) {
  2090. var interpolants = this._interpolants;
  2091. var propertyMixers = this._propertyBindings;
  2092. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  2093. interpolants[ j ].evaluate( clipTime );
  2094. propertyMixers[ j ].accumulate( accuIndex, weight );
  2095. }
  2096. }
  2097. },
  2098. _updateWeight: function ( time ) {
  2099. var weight = 0;
  2100. if ( this.enabled ) {
  2101. weight = this.weight;
  2102. var interpolant = this._weightInterpolant;
  2103. if ( interpolant !== null ) {
  2104. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  2105. weight *= interpolantValue;
  2106. if ( time > interpolant.parameterPositions[ 1 ] ) {
  2107. this.stopFading();
  2108. if ( interpolantValue === 0 ) {
  2109. // faded out, disable
  2110. this.enabled = false;
  2111. }
  2112. }
  2113. }
  2114. }
  2115. this._effectiveWeight = weight;
  2116. return weight;
  2117. },
  2118. _updateTimeScale: function ( time ) {
  2119. var timeScale = 0;
  2120. if ( ! this.paused ) {
  2121. timeScale = this.timeScale;
  2122. var interpolant = this._timeScaleInterpolant;
  2123. if ( interpolant !== null ) {
  2124. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  2125. timeScale *= interpolantValue;
  2126. if ( time > interpolant.parameterPositions[ 1 ] ) {
  2127. this.stopWarping();
  2128. if ( timeScale === 0 ) {
  2129. // motion has halted, pause
  2130. this.paused = true;
  2131. } else {
  2132. // warp done - apply final time scale
  2133. this.timeScale = timeScale;
  2134. }
  2135. }
  2136. }
  2137. }
  2138. this._effectiveTimeScale = timeScale;
  2139. return timeScale;
  2140. },
  2141. _updateTime: function ( deltaTime ) {
  2142. var time = this.time + deltaTime;
  2143. if ( deltaTime === 0 ) return time;
  2144. var duration = this._clip.duration,
  2145. loop = this.loop,
  2146. loopCount = this._loopCount;
  2147. if ( loop === LoopOnce ) {
  2148. if ( loopCount === - 1 ) {
  2149. // just started
  2150. this._loopCount = 0;
  2151. this._setEndings( true, true, false );
  2152. }
  2153. handle_stop: {
  2154. if ( time >= duration ) {
  2155. time = duration;
  2156. } else if ( time < 0 ) {
  2157. time = 0;
  2158. } else break handle_stop;
  2159. if ( this.clampWhenFinished ) this.paused = true;
  2160. else this.enabled = false;
  2161. this._mixer.dispatchEvent( {
  2162. type: 'finished', action: this,
  2163. direction: deltaTime < 0 ? - 1 : 1
  2164. } );
  2165. }
  2166. } else { // repetitive Repeat or PingPong
  2167. var pingPong = ( loop === LoopPingPong );
  2168. if ( loopCount === - 1 ) {
  2169. // just started
  2170. if ( deltaTime >= 0 ) {
  2171. loopCount = 0;
  2172. this._setEndings( true, this.repetitions === 0, pingPong );
  2173. } else {
  2174. // when looping in reverse direction, the initial
  2175. // transition through zero counts as a repetition,
  2176. // so leave loopCount at -1
  2177. this._setEndings( this.repetitions === 0, true, pingPong );
  2178. }
  2179. }
  2180. if ( time >= duration || time < 0 ) {
  2181. // wrap around
  2182. var loopDelta = Math.floor( time / duration ); // signed
  2183. time -= duration * loopDelta;
  2184. loopCount += Math.abs( loopDelta );
  2185. var pending = this.repetitions - loopCount;
  2186. if ( pending < 0 ) {
  2187. // have to stop (switch state, clamp time, fire event)
  2188. if ( this.clampWhenFinished ) this.paused = true;
  2189. else this.enabled = false;
  2190. time = deltaTime > 0 ? duration : 0;
  2191. this._mixer.dispatchEvent( {
  2192. type: 'finished', action: this,
  2193. direction: deltaTime > 0 ? 1 : - 1
  2194. } );
  2195. } else {
  2196. // keep running
  2197. if ( pending === 0 ) {
  2198. // entering the last round
  2199. var atStart = deltaTime < 0;
  2200. this._setEndings( atStart, ! atStart, pingPong );
  2201. } else {
  2202. this._setEndings( false, false, pingPong );
  2203. }
  2204. this._loopCount = loopCount;
  2205. this._mixer.dispatchEvent( {
  2206. type: 'loop', action: this, loopDelta: loopDelta
  2207. } );
  2208. }
  2209. }
  2210. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  2211. // invert time for the "pong round"
  2212. this.time = time;
  2213. return duration - time;
  2214. }
  2215. }
  2216. this.time = time;
  2217. return time;
  2218. },
  2219. _setEndings: function ( atStart, atEnd, pingPong ) {
  2220. var settings = this._interpolantSettings;
  2221. if ( pingPong ) {
  2222. settings.endingStart = ZeroSlopeEnding;
  2223. settings.endingEnd = ZeroSlopeEnding;
  2224. } else {
  2225. // assuming for LoopOnce atStart == atEnd == true
  2226. if ( atStart ) {
  2227. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  2228. } else {
  2229. settings.endingStart = WrapAroundEnding;
  2230. }
  2231. if ( atEnd ) {
  2232. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  2233. } else {
  2234. settings.endingEnd = WrapAroundEnding;
  2235. }
  2236. }
  2237. },
  2238. _scheduleFading: function ( duration, weightNow, weightThen ) {
  2239. var mixer = this._mixer, now = mixer.time,
  2240. interpolant = this._weightInterpolant;
  2241. if ( interpolant === null ) {
  2242. interpolant = mixer._lendControlInterpolant();
  2243. this._weightInterpolant = interpolant;
  2244. }
  2245. var times = interpolant.parameterPositions,
  2246. values = interpolant.sampleValues;
  2247. times[ 0 ] = now; values[ 0 ] = weightNow;
  2248. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  2249. return this;
  2250. }
  2251. } );
  2252. /**
  2253. * https://github.com/mrdoob/eventdispatcher.js/
  2254. */
  2255. function EventDispatcher() {}
  2256. Object.assign( EventDispatcher.prototype, {
  2257. addEventListener: function ( type, listener ) {
  2258. if ( this._listeners === undefined ) this._listeners = {};
  2259. var listeners = this._listeners;
  2260. if ( listeners[ type ] === undefined ) {
  2261. listeners[ type ] = [];
  2262. }
  2263. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  2264. listeners[ type ].push( listener );
  2265. }
  2266. },
  2267. hasEventListener: function ( type, listener ) {
  2268. if ( this._listeners === undefined ) return false;
  2269. var listeners = this._listeners;
  2270. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  2271. },
  2272. removeEventListener: function ( type, listener ) {
  2273. if ( this._listeners === undefined ) return;
  2274. var listeners = this._listeners;
  2275. var listenerArray = listeners[ type ];
  2276. if ( listenerArray !== undefined ) {
  2277. var index = listenerArray.indexOf( listener );
  2278. if ( index !== - 1 ) {
  2279. listenerArray.splice( index, 1 );
  2280. }
  2281. }
  2282. },
  2283. dispatchEvent: function ( event ) {
  2284. if ( this._listeners === undefined ) return;
  2285. var listeners = this._listeners;
  2286. var listenerArray = listeners[ event.type ];
  2287. if ( listenerArray !== undefined ) {
  2288. event.target = this;
  2289. var array = listenerArray.slice( 0 );
  2290. for ( var i = 0, l = array.length; i < l; i ++ ) {
  2291. array[ i ].call( this, event );
  2292. }
  2293. }
  2294. }
  2295. } );
  2296. /**
  2297. * Abstract base class of interpolants over parametric samples.
  2298. *
  2299. * The parameter domain is one dimensional, typically the time or a path
  2300. * along a curve defined by the data.
  2301. *
  2302. * The sample values can have any dimensionality and derived classes may
  2303. * apply special interpretations to the data.
  2304. *
  2305. * This class provides the interval seek in a Template Method, deferring
  2306. * the actual interpolation to derived classes.
  2307. *
  2308. * Time complexity is O(1) for linear access crossing at most two points
  2309. * and O(log N) for random access, where N is the number of positions.
  2310. *
  2311. * References:
  2312. *
  2313. * http://www.oodesign.com/template-method-pattern.html
  2314. *
  2315. * @author tschw
  2316. */
  2317. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  2318. this.parameterPositions = parameterPositions;
  2319. this._cachedIndex = 0;
  2320. this.resultBuffer = resultBuffer !== undefined ?
  2321. resultBuffer : new sampleValues.constructor( sampleSize );
  2322. this.sampleValues = sampleValues;
  2323. this.valueSize = sampleSize;
  2324. }
  2325. Object.assign( Interpolant.prototype, {
  2326. evaluate: function ( t ) {
  2327. var pp = this.parameterPositions,
  2328. i1 = this._cachedIndex,
  2329. t1 = pp[ i1 ],
  2330. t0 = pp[ i1 - 1 ];
  2331. validate_interval: {
  2332. seek: {
  2333. var right;
  2334. linear_scan: {
  2335. //- See http://jsperf.com/comparison-to-undefined/3
  2336. //- slower code:
  2337. //-
  2338. //- if ( t >= t1 || t1 === undefined ) {
  2339. forward_scan: if ( ! ( t < t1 ) ) {
  2340. for ( var giveUpAt = i1 + 2; ; ) {
  2341. if ( t1 === undefined ) {
  2342. if ( t < t0 ) break forward_scan;
  2343. // after end
  2344. i1 = pp.length;
  2345. this._cachedIndex = i1;
  2346. return this.afterEnd_( i1 - 1, t, t0 );
  2347. }
  2348. if ( i1 === giveUpAt ) break; // this loop
  2349. t0 = t1;
  2350. t1 = pp[ ++ i1 ];
  2351. if ( t < t1 ) {
  2352. // we have arrived at the sought interval
  2353. break seek;
  2354. }
  2355. }
  2356. // prepare binary search on the right side of the index
  2357. right = pp.length;
  2358. break linear_scan;
  2359. }
  2360. //- slower code:
  2361. //- if ( t < t0 || t0 === undefined ) {
  2362. if ( ! ( t >= t0 ) ) {
  2363. // looping?
  2364. var t1global = pp[ 1 ];
  2365. if ( t < t1global ) {
  2366. i1 = 2; // + 1, using the scan for the details
  2367. t0 = t1global;
  2368. }
  2369. // linear reverse scan
  2370. for ( var giveUpAt = i1 - 2; ; ) {
  2371. if ( t0 === undefined ) {
  2372. // before start
  2373. this._cachedIndex = 0;
  2374. return this.beforeStart_( 0, t, t1 );
  2375. }
  2376. if ( i1 === giveUpAt ) break; // this loop
  2377. t1 = t0;
  2378. t0 = pp[ -- i1 - 1 ];
  2379. if ( t >= t0 ) {
  2380. // we have arrived at the sought interval
  2381. break seek;
  2382. }
  2383. }
  2384. // prepare binary search on the left side of the index
  2385. right = i1;
  2386. i1 = 0;
  2387. break linear_scan;
  2388. }
  2389. // the interval is valid
  2390. break validate_interval;
  2391. } // linear scan
  2392. // binary search
  2393. while ( i1 < right ) {
  2394. var mid = ( i1 + right ) >>> 1;
  2395. if ( t < pp[ mid ] ) {
  2396. right = mid;
  2397. } else {
  2398. i1 = mid + 1;
  2399. }
  2400. }
  2401. t1 = pp[ i1 ];
  2402. t0 = pp[ i1 - 1 ];
  2403. // check boundary cases, again
  2404. if ( t0 === undefined ) {
  2405. this._cachedIndex = 0;
  2406. return this.beforeStart_( 0, t, t1 );
  2407. }
  2408. if ( t1 === undefined ) {
  2409. i1 = pp.length;
  2410. this._cachedIndex = i1;
  2411. return this.afterEnd_( i1 - 1, t0, t );
  2412. }
  2413. } // seek
  2414. this._cachedIndex = i1;
  2415. this.intervalChanged_( i1, t0, t1 );
  2416. } // validate_interval
  2417. return this.interpolate_( i1, t0, t, t1 );
  2418. },
  2419. settings: null, // optional, subclass-specific settings structure
  2420. // Note: The indirection allows central control of many interpolants.
  2421. // --- Protected interface
  2422. DefaultSettings_: {},
  2423. getSettings_: function () {
  2424. return this.settings || this.DefaultSettings_;
  2425. },
  2426. copySampleValue_: function ( index ) {
  2427. // copies a sample value to the result buffer
  2428. var result = this.resultBuffer,
  2429. values = this.sampleValues,
  2430. stride = this.valueSize,
  2431. offset = index * stride;
  2432. for ( var i = 0; i !== stride; ++ i ) {
  2433. result[ i ] = values[ offset + i ];
  2434. }
  2435. return result;
  2436. },
  2437. // Template methods for derived classes:
  2438. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  2439. throw new Error( 'call to abstract method' );
  2440. // implementations shall return this.resultBuffer
  2441. },
  2442. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  2443. // empty
  2444. }
  2445. } );
  2446. //!\ DECLARE ALIAS AFTER assign prototype !
  2447. Object.assign( Interpolant.prototype, {
  2448. //( 0, t, t0 ), returns this.resultBuffer
  2449. beforeStart_: Interpolant.prototype.copySampleValue_,
  2450. //( N-1, tN-1, t ), returns this.resultBuffer
  2451. afterEnd_: Interpolant.prototype.copySampleValue_,
  2452. } );
  2453. /**
  2454. * @author tschw
  2455. */
  2456. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  2457. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  2458. }
  2459. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  2460. constructor: LinearInterpolant,
  2461. interpolate_: function ( i1, t0, t, t1 ) {
  2462. var result = this.resultBuffer,
  2463. values = this.sampleValues,
  2464. stride = this.valueSize,
  2465. offset1 = i1 * stride,
  2466. offset0 = offset1 - stride,
  2467. weight1 = ( t - t0 ) / ( t1 - t0 ),
  2468. weight0 = 1 - weight1;
  2469. for ( var i = 0; i !== stride; ++ i ) {
  2470. result[ i ] =
  2471. values[ offset0 + i ] * weight0 +
  2472. values[ offset1 + i ] * weight1;
  2473. }
  2474. return result;
  2475. }
  2476. } );
  2477. /**
  2478. *
  2479. * A reference to a real property in the scene graph.
  2480. *
  2481. *
  2482. * @author Ben Houston / http://clara.io/
  2483. * @author David Sarno / http://lighthaus.us/
  2484. * @author tschw
  2485. */
  2486. function Composite( targetGroup, path, optionalParsedPath ) {
  2487. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  2488. this._targetGroup = targetGroup;
  2489. this._bindings = targetGroup.subscribe_( path, parsedPath );
  2490. }
  2491. Object.assign( Composite.prototype, {
  2492. getValue: function ( array, offset ) {
  2493. this.bind(); // bind all binding
  2494. var firstValidIndex = this._targetGroup.nCachedObjects_,
  2495. binding = this._bindings[ firstValidIndex ];
  2496. // and only call .getValue on the first
  2497. if ( binding !== undefined ) binding.getValue( array, offset );
  2498. },
  2499. setValue: function ( array, offset ) {
  2500. var bindings = this._bindings;
  2501. for ( var i = this._targetGroup.nCachedObjects_,
  2502. n = bindings.length; i !== n; ++ i ) {
  2503. bindings[ i ].setValue( array, offset );
  2504. }
  2505. },
  2506. bind: function () {
  2507. var bindings = this._bindings;
  2508. for ( var i = this._targetGroup.nCachedObjects_,
  2509. n = bindings.length; i !== n; ++ i ) {
  2510. bindings[ i ].bind();
  2511. }
  2512. },
  2513. unbind: function () {
  2514. var bindings = this._bindings;
  2515. for ( var i = this._targetGroup.nCachedObjects_,
  2516. n = bindings.length; i !== n; ++ i ) {
  2517. bindings[ i ].unbind();
  2518. }
  2519. }
  2520. } );
  2521. function PropertyBinding( rootNode, path, parsedPath ) {
  2522. this.path = path;
  2523. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  2524. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  2525. this.rootNode = rootNode;
  2526. }
  2527. Object.assign( PropertyBinding, {
  2528. Composite: Composite,
  2529. create: function ( root, path, parsedPath ) {
  2530. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  2531. return new PropertyBinding( root, path, parsedPath );
  2532. } else {
  2533. return new PropertyBinding.Composite( root, path, parsedPath );
  2534. }
  2535. },
  2536. /**
  2537. * Replaces spaces with underscores and removes unsupported characters from
  2538. * node names, to ensure compatibility with parseTrackName().
  2539. *
  2540. * @param {string} name Node name to be sanitized.
  2541. * @return {string}
  2542. */
  2543. sanitizeNodeName: function ( name ) {
  2544. return name.replace( /\s/g, '_' ).replace( /[^\w-]/g, '' );
  2545. },
  2546. parseTrackName: function () {
  2547. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  2548. // be matched to parse the rest of the track name.
  2549. var directoryRe = /((?:[\w-]+[\/:])*)/;
  2550. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  2551. var nodeRe = /([\w-\.]+)?/;
  2552. // Object on target node, and accessor. Name may contain only word
  2553. // characters. Accessor may contain any character except closing bracket.
  2554. var objectRe = /(?:\.([\w-]+)(?:\[(.+)\])?)?/;
  2555. // Property and accessor. May contain only word characters. Accessor may
  2556. // contain any non-bracket characters.
  2557. var propertyRe = /\.([\w-]+)(?:\[(.+)\])?/;
  2558. var trackRe = new RegExp( ''
  2559. + '^'
  2560. + directoryRe.source
  2561. + nodeRe.source
  2562. + objectRe.source
  2563. + propertyRe.source
  2564. + '$'
  2565. );
  2566. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  2567. return function ( trackName ) {
  2568. var matches = trackRe.exec( trackName );
  2569. if ( ! matches ) {
  2570. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  2571. }
  2572. var results = {
  2573. // directoryName: matches[ 1 ], // (tschw) currently unused
  2574. nodeName: matches[ 2 ],
  2575. objectName: matches[ 3 ],
  2576. objectIndex: matches[ 4 ],
  2577. propertyName: matches[ 5 ], // required
  2578. propertyIndex: matches[ 6 ]
  2579. };
  2580. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  2581. if ( lastDot !== undefined && lastDot !== - 1 ) {
  2582. var objectName = results.nodeName.substring( lastDot + 1 );
  2583. // Object names must be checked against a whitelist. Otherwise, there
  2584. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  2585. // 'bar' could be the objectName, or part of a nodeName (which can
  2586. // include '.' characters).
  2587. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  2588. results.nodeName = results.nodeName.substring( 0, lastDot );
  2589. results.objectName = objectName;
  2590. }
  2591. }
  2592. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  2593. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  2594. }
  2595. return results;
  2596. };
  2597. }(),
  2598. findNode: function ( root, nodeName ) {
  2599. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  2600. return root;
  2601. }
  2602. // search into skeleton bones.
  2603. if ( root.skeleton ) {
  2604. var searchSkeleton = function ( skeleton ) {
  2605. for ( var i = 0; i < skeleton.bones.length; i ++ ) {
  2606. var bone = skeleton.bones[ i ];
  2607. if ( bone.name === nodeName ) {
  2608. return bone;
  2609. }
  2610. }
  2611. return null;
  2612. };
  2613. var bone = searchSkeleton( root.skeleton );
  2614. if ( bone ) {
  2615. return bone;
  2616. }
  2617. }
  2618. // search into node subtree.
  2619. if ( root.children ) {
  2620. var searchNodeSubtree = function ( children ) {
  2621. for ( var i = 0; i < children.length; i ++ ) {
  2622. var childNode = children[ i ];
  2623. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  2624. return childNode;
  2625. }
  2626. var result = searchNodeSubtree( childNode.children );
  2627. if ( result ) return result;
  2628. }
  2629. return null;
  2630. };
  2631. var subTreeNode = searchNodeSubtree( root.children );
  2632. if ( subTreeNode ) {
  2633. return subTreeNode;
  2634. }
  2635. }
  2636. return null;
  2637. }
  2638. } );
  2639. Object.assign( PropertyBinding.prototype, { // prototype, continued
  2640. // these are used to "bind" a nonexistent property
  2641. _getValue_unavailable: function () {},
  2642. _setValue_unavailable: function () {},
  2643. BindingType: {
  2644. Direct: 0,
  2645. EntireArray: 1,
  2646. ArrayElement: 2,
  2647. HasFromToArray: 3
  2648. },
  2649. Versioning: {
  2650. None: 0,
  2651. NeedsUpdate: 1,
  2652. MatrixWorldNeedsUpdate: 2
  2653. },
  2654. GetterByBindingType: [
  2655. function getValue_direct( buffer, offset ) {
  2656. buffer[ offset ] = this.node[ this.propertyName ];
  2657. },
  2658. function getValue_array( buffer, offset ) {
  2659. var source = this.resolvedProperty;
  2660. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  2661. buffer[ offset ++ ] = source[ i ];
  2662. }
  2663. },
  2664. function getValue_arrayElement( buffer, offset ) {
  2665. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  2666. },
  2667. function getValue_toArray( buffer, offset ) {
  2668. this.resolvedProperty.toArray( buffer, offset );
  2669. }
  2670. ],
  2671. SetterByBindingTypeAndVersioning: [
  2672. [
  2673. // Direct
  2674. function setValue_direct( buffer, offset ) {
  2675. this.targetObject[ this.propertyName ] = buffer[ offset ];
  2676. },
  2677. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  2678. this.targetObject[ this.propertyName ] = buffer[ offset ];
  2679. this.targetObject.needsUpdate = true;
  2680. },
  2681. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  2682. this.targetObject[ this.propertyName ] = buffer[ offset ];
  2683. this.targetObject.matrixWorldNeedsUpdate = true;
  2684. }
  2685. ], [
  2686. // EntireArray
  2687. function setValue_array( buffer, offset ) {
  2688. var dest = this.resolvedProperty;
  2689. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  2690. dest[ i ] = buffer[ offset ++ ];
  2691. }
  2692. },
  2693. function setValue_array_setNeedsUpdate( buffer, offset ) {
  2694. var dest = this.resolvedProperty;
  2695. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  2696. dest[ i ] = buffer[ offset ++ ];
  2697. }
  2698. this.targetObject.needsUpdate = true;
  2699. },
  2700. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  2701. var dest = this.resolvedProperty;
  2702. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  2703. dest[ i ] = buffer[ offset ++ ];
  2704. }
  2705. this.targetObject.matrixWorldNeedsUpdate = true;
  2706. }
  2707. ], [
  2708. // ArrayElement
  2709. function setValue_arrayElement( buffer, offset ) {
  2710. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  2711. },
  2712. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  2713. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  2714. this.targetObject.needsUpdate = true;
  2715. },
  2716. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  2717. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  2718. this.targetObject.matrixWorldNeedsUpdate = true;
  2719. }
  2720. ], [
  2721. // HasToFromArray
  2722. function setValue_fromArray( buffer, offset ) {
  2723. this.resolvedProperty.fromArray( buffer, offset );
  2724. },
  2725. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  2726. this.resolvedProperty.fromArray( buffer, offset );
  2727. this.targetObject.needsUpdate = true;
  2728. },
  2729. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  2730. this.resolvedProperty.fromArray( buffer, offset );
  2731. this.targetObject.matrixWorldNeedsUpdate = true;
  2732. }
  2733. ]
  2734. ],
  2735. getValue: function getValue_unbound( targetArray, offset ) {
  2736. this.bind();
  2737. this.getValue( targetArray, offset );
  2738. // Note: This class uses a State pattern on a per-method basis:
  2739. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  2740. // prototype version of these methods with one that represents
  2741. // the bound state. When the property is not found, the methods
  2742. // become no-ops.
  2743. },
  2744. setValue: function getValue_unbound( sourceArray, offset ) {
  2745. this.bind();
  2746. this.setValue( sourceArray, offset );
  2747. },
  2748. // create getter / setter pair for a property in the scene graph
  2749. bind: function () {
  2750. var targetObject = this.node,
  2751. parsedPath = this.parsedPath,
  2752. objectName = parsedPath.objectName,
  2753. propertyName = parsedPath.propertyName,
  2754. propertyIndex = parsedPath.propertyIndex;
  2755. if ( ! targetObject ) {
  2756. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  2757. this.node = targetObject;
  2758. }
  2759. // set fail state so we can just 'return' on error
  2760. this.getValue = this._getValue_unavailable;
  2761. this.setValue = this._setValue_unavailable;
  2762. // ensure there is a value node
  2763. if ( ! targetObject ) {
  2764. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  2765. return;
  2766. }
  2767. if ( objectName ) {
  2768. var objectIndex = parsedPath.objectIndex;
  2769. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  2770. switch ( objectName ) {
  2771. case 'materials':
  2772. if ( ! targetObject.material ) {
  2773. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  2774. return;
  2775. }
  2776. if ( ! targetObject.material.materials ) {
  2777. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  2778. return;
  2779. }
  2780. targetObject = targetObject.material.materials;
  2781. break;
  2782. case 'bones':
  2783. if ( ! targetObject.skeleton ) {
  2784. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  2785. return;
  2786. }
  2787. // potential future optimization: skip this if propertyIndex is already an integer
  2788. // and convert the integer string to a true integer.
  2789. targetObject = targetObject.skeleton.bones;
  2790. // support resolving morphTarget names into indices.
  2791. for ( var i = 0; i < targetObject.length; i ++ ) {
  2792. if ( targetObject[ i ].name === objectIndex ) {
  2793. objectIndex = i;
  2794. break;
  2795. }
  2796. }
  2797. break;
  2798. default:
  2799. if ( targetObject[ objectName ] === undefined ) {
  2800. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  2801. return;
  2802. }
  2803. targetObject = targetObject[ objectName ];
  2804. }
  2805. if ( objectIndex !== undefined ) {
  2806. if ( targetObject[ objectIndex ] === undefined ) {
  2807. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  2808. return;
  2809. }
  2810. targetObject = targetObject[ objectIndex ];
  2811. }
  2812. }
  2813. // resolve property
  2814. var nodeProperty = targetObject[ propertyName ];
  2815. if ( nodeProperty === undefined ) {
  2816. var nodeName = parsedPath.nodeName;
  2817. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  2818. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  2819. return;
  2820. }
  2821. // determine versioning scheme
  2822. var versioning = this.Versioning.None;
  2823. if ( targetObject.needsUpdate !== undefined ) { // material
  2824. versioning = this.Versioning.NeedsUpdate;
  2825. this.targetObject = targetObject;
  2826. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  2827. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  2828. this.targetObject = targetObject;
  2829. }
  2830. // determine how the property gets bound
  2831. var bindingType = this.BindingType.Direct;
  2832. if ( propertyIndex !== undefined ) {
  2833. // access a sub element of the property array (only primitives are supported right now)
  2834. if ( propertyName === "morphTargetInfluences" ) {
  2835. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  2836. // support resolving morphTarget names into indices.
  2837. if ( ! targetObject.geometry ) {
  2838. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  2839. return;
  2840. }
  2841. if ( targetObject.geometry.isBufferGeometry ) {
  2842. if ( ! targetObject.geometry.morphAttributes ) {
  2843. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  2844. return;
  2845. }
  2846. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  2847. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  2848. propertyIndex = i;
  2849. break;
  2850. }
  2851. }
  2852. } else {
  2853. if ( ! targetObject.geometry.morphTargets ) {
  2854. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  2855. return;
  2856. }
  2857. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  2858. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  2859. propertyIndex = i;
  2860. break;
  2861. }
  2862. }
  2863. }
  2864. }
  2865. bindingType = this.BindingType.ArrayElement;
  2866. this.resolvedProperty = nodeProperty;
  2867. this.propertyIndex = propertyIndex;
  2868. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  2869. // must use copy for Object3D.Euler/Quaternion
  2870. bindingType = this.BindingType.HasFromToArray;
  2871. this.resolvedProperty = nodeProperty;
  2872. } else if ( Array.isArray( nodeProperty ) ) {
  2873. bindingType = this.BindingType.EntireArray;
  2874. this.resolvedProperty = nodeProperty;
  2875. } else {
  2876. this.propertyName = propertyName;
  2877. }
  2878. // select getter / setter
  2879. this.getValue = this.GetterByBindingType[ bindingType ];
  2880. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  2881. },
  2882. unbind: function () {
  2883. this.node = null;
  2884. // back to the prototype version of getValue / setValue
  2885. // note: avoiding to mutate the shape of 'this' via 'delete'
  2886. this.getValue = this._getValue_unbound;
  2887. this.setValue = this._setValue_unbound;
  2888. }
  2889. } );
  2890. //!\ DECLARE ALIAS AFTER assign prototype !
  2891. Object.assign( PropertyBinding.prototype, {
  2892. // initial state of these methods that calls 'bind'
  2893. _getValue_unbound: PropertyBinding.prototype.getValue,
  2894. _setValue_unbound: PropertyBinding.prototype.setValue,
  2895. } );
  2896. /**
  2897. *
  2898. * Buffered scene graph property that allows weighted accumulation.
  2899. *
  2900. *
  2901. * @author Ben Houston / http://clara.io/
  2902. * @author David Sarno / http://lighthaus.us/
  2903. * @author tschw
  2904. */
  2905. function PropertyMixer( binding, typeName, valueSize ) {
  2906. this.binding = binding;
  2907. this.valueSize = valueSize;
  2908. var bufferType = Float64Array,
  2909. mixFunction;
  2910. switch ( typeName ) {
  2911. case 'quaternion':
  2912. mixFunction = this._slerp;
  2913. break;
  2914. case 'string':
  2915. case 'bool':
  2916. bufferType = Array;
  2917. mixFunction = this._select;
  2918. break;
  2919. default:
  2920. mixFunction = this._lerp;
  2921. }
  2922. this.buffer = new bufferType( valueSize * 4 );
  2923. // layout: [ incoming | accu0 | accu1 | orig ]
  2924. //
  2925. // interpolators can use .buffer as their .result
  2926. // the data then goes to 'incoming'
  2927. //
  2928. // 'accu0' and 'accu1' are used frame-interleaved for
  2929. // the cumulative result and are compared to detect
  2930. // changes
  2931. //
  2932. // 'orig' stores the original state of the property
  2933. this._mixBufferRegion = mixFunction;
  2934. this.cumulativeWeight = 0;
  2935. this.useCount = 0;
  2936. this.referenceCount = 0;
  2937. }
  2938. Object.assign( PropertyMixer.prototype, {
  2939. // accumulate data in the 'incoming' region into 'accu<i>'
  2940. accumulate: function ( accuIndex, weight ) {
  2941. // note: happily accumulating nothing when weight = 0, the caller knows
  2942. // the weight and shouldn't have made the call in the first place
  2943. var buffer = this.buffer,
  2944. stride = this.valueSize,
  2945. offset = accuIndex * stride + stride,
  2946. currentWeight = this.cumulativeWeight;
  2947. if ( currentWeight === 0 ) {
  2948. // accuN := incoming * weight
  2949. for ( var i = 0; i !== stride; ++ i ) {
  2950. buffer[ offset + i ] = buffer[ i ];
  2951. }
  2952. currentWeight = weight;
  2953. } else {
  2954. // accuN := accuN + incoming * weight
  2955. currentWeight += weight;
  2956. var mix = weight / currentWeight;
  2957. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  2958. }
  2959. this.cumulativeWeight = currentWeight;
  2960. },
  2961. // apply the state of 'accu<i>' to the binding when accus differ
  2962. apply: function ( accuIndex ) {
  2963. var stride = this.valueSize,
  2964. buffer = this.buffer,
  2965. offset = accuIndex * stride + stride,
  2966. weight = this.cumulativeWeight,
  2967. binding = this.binding;
  2968. this.cumulativeWeight = 0;
  2969. if ( weight < 1 ) {
  2970. // accuN := accuN + original * ( 1 - cumulativeWeight )
  2971. var originalValueOffset = stride * 3;
  2972. this._mixBufferRegion(
  2973. buffer, offset, originalValueOffset, 1 - weight, stride );
  2974. }
  2975. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  2976. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  2977. // value has changed -> update scene graph
  2978. binding.setValue( buffer, offset );
  2979. break;
  2980. }
  2981. }
  2982. },
  2983. // remember the state of the bound property and copy it to both accus
  2984. saveOriginalState: function () {
  2985. var binding = this.binding;
  2986. var buffer = this.buffer,
  2987. stride = this.valueSize,
  2988. originalValueOffset = stride * 3;
  2989. binding.getValue( buffer, originalValueOffset );
  2990. // accu[0..1] := orig -- initially detect changes against the original
  2991. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  2992. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  2993. }
  2994. this.cumulativeWeight = 0;
  2995. },
  2996. // apply the state previously taken via 'saveOriginalState' to the binding
  2997. restoreOriginalState: function () {
  2998. var originalValueOffset = this.valueSize * 3;
  2999. this.binding.setValue( this.buffer, originalValueOffset );
  3000. },
  3001. // mix functions
  3002. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  3003. if ( t >= 0.5 ) {
  3004. for ( var i = 0; i !== stride; ++ i ) {
  3005. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  3006. }
  3007. }
  3008. },
  3009. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  3010. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  3011. },
  3012. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  3013. var s = 1 - t;
  3014. for ( var i = 0; i !== stride; ++ i ) {
  3015. var j = dstOffset + i;
  3016. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  3017. }
  3018. }
  3019. } );
  3020. /**
  3021. * @author tschw
  3022. * @author Ben Houston / http://clara.io/
  3023. * @author David Sarno / http://lighthaus.us/
  3024. */
  3025. var AnimationUtils = {
  3026. // same as Array.prototype.slice, but also works on typed arrays
  3027. arraySlice: function ( array, from, to ) {
  3028. if ( AnimationUtils.isTypedArray( array ) ) {
  3029. // in ios9 array.subarray(from, undefined) will return empty array
  3030. // but array.subarray(from) or array.subarray(from, len) is correct
  3031. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  3032. }
  3033. return array.slice( from, to );
  3034. },
  3035. // converts an array to a specific type
  3036. convertArray: function ( array, type, forceClone ) {
  3037. if ( ! array || // let 'undefined' and 'null' pass
  3038. ! forceClone && array.constructor === type ) return array;
  3039. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  3040. return new type( array ); // create typed array
  3041. }
  3042. return Array.prototype.slice.call( array ); // create Array
  3043. },
  3044. isTypedArray: function ( object ) {
  3045. return ArrayBuffer.isView( object ) &&
  3046. ! ( object instanceof DataView );
  3047. },
  3048. // returns an array by which times and values can be sorted
  3049. getKeyframeOrder: function ( times ) {
  3050. function compareTime( i, j ) {
  3051. return times[ i ] - times[ j ];
  3052. }
  3053. var n = times.length;
  3054. var result = new Array( n );
  3055. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  3056. result.sort( compareTime );
  3057. return result;
  3058. },
  3059. // uses the array previously returned by 'getKeyframeOrder' to sort data
  3060. sortedArray: function ( values, stride, order ) {
  3061. var nValues = values.length;
  3062. var result = new values.constructor( nValues );
  3063. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  3064. var srcOffset = order[ i ] * stride;
  3065. for ( var j = 0; j !== stride; ++ j ) {
  3066. result[ dstOffset ++ ] = values[ srcOffset + j ];
  3067. }
  3068. }
  3069. return result;
  3070. },
  3071. // function for parsing AOS keyframe formats
  3072. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  3073. var i = 1, key = jsonKeys[ 0 ];
  3074. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  3075. key = jsonKeys[ i ++ ];
  3076. }
  3077. if ( key === undefined ) return; // no data
  3078. var value = key[ valuePropertyName ];
  3079. if ( value === undefined ) return; // no data
  3080. if ( Array.isArray( value ) ) {
  3081. do {
  3082. value = key[ valuePropertyName ];
  3083. if ( value !== undefined ) {
  3084. times.push( key.time );
  3085. values.push.apply( values, value ); // push all elements
  3086. }
  3087. key = jsonKeys[ i ++ ];
  3088. } while ( key !== undefined );
  3089. } else if ( value.toArray !== undefined ) {
  3090. // ...assume THREE.Math-ish
  3091. do {
  3092. value = key[ valuePropertyName ];
  3093. if ( value !== undefined ) {
  3094. times.push( key.time );
  3095. value.toArray( values, values.length );
  3096. }
  3097. key = jsonKeys[ i ++ ];
  3098. } while ( key !== undefined );
  3099. } else {
  3100. // otherwise push as-is
  3101. do {
  3102. value = key[ valuePropertyName ];
  3103. if ( value !== undefined ) {
  3104. times.push( key.time );
  3105. values.push( value );
  3106. }
  3107. key = jsonKeys[ i ++ ];
  3108. } while ( key !== undefined );
  3109. }
  3110. }
  3111. };
  3112. /**
  3113. * Fast and simple cubic spline interpolant.
  3114. *
  3115. * It was derived from a Hermitian construction setting the first derivative
  3116. * at each sample position to the linear slope between neighboring positions
  3117. * over their parameter interval.
  3118. *
  3119. * @author tschw
  3120. */
  3121. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  3122. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  3123. this._weightPrev = - 0;
  3124. this._offsetPrev = - 0;
  3125. this._weightNext = - 0;
  3126. this._offsetNext = - 0;
  3127. }
  3128. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  3129. constructor: CubicInterpolant,
  3130. DefaultSettings_: {
  3131. endingStart: ZeroCurvatureEnding,
  3132. endingEnd: ZeroCurvatureEnding
  3133. },
  3134. intervalChanged_: function ( i1, t0, t1 ) {
  3135. var pp = this.parameterPositions,
  3136. iPrev = i1 - 2,
  3137. iNext = i1 + 1,
  3138. tPrev = pp[ iPrev ],
  3139. tNext = pp[ iNext ];
  3140. if ( tPrev === undefined ) {
  3141. switch ( this.getSettings_().endingStart ) {
  3142. case ZeroSlopeEnding:
  3143. // f'(t0) = 0
  3144. iPrev = i1;
  3145. tPrev = 2 * t0 - t1;
  3146. break;
  3147. case WrapAroundEnding:
  3148. // use the other end of the curve
  3149. iPrev = pp.length - 2;
  3150. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  3151. break;
  3152. default: // ZeroCurvatureEnding
  3153. // f''(t0) = 0 a.k.a. Natural Spline
  3154. iPrev = i1;
  3155. tPrev = t1;
  3156. }
  3157. }
  3158. if ( tNext === undefined ) {
  3159. switch ( this.getSettings_().endingEnd ) {
  3160. case ZeroSlopeEnding:
  3161. // f'(tN) = 0
  3162. iNext = i1;
  3163. tNext = 2 * t1 - t0;
  3164. break;
  3165. case WrapAroundEnding:
  3166. // use the other end of the curve
  3167. iNext = 1;
  3168. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  3169. break;
  3170. default: // ZeroCurvatureEnding
  3171. // f''(tN) = 0, a.k.a. Natural Spline
  3172. iNext = i1 - 1;
  3173. tNext = t0;
  3174. }
  3175. }
  3176. var halfDt = ( t1 - t0 ) * 0.5,
  3177. stride = this.valueSize;
  3178. this._weightPrev = halfDt / ( t0 - tPrev );
  3179. this._weightNext = halfDt / ( tNext - t1 );
  3180. this._offsetPrev = iPrev * stride;
  3181. this._offsetNext = iNext * stride;
  3182. },
  3183. interpolate_: function ( i1, t0, t, t1 ) {
  3184. var result = this.resultBuffer,
  3185. values = this.sampleValues,
  3186. stride = this.valueSize,
  3187. o1 = i1 * stride, o0 = o1 - stride,
  3188. oP = this._offsetPrev, oN = this._offsetNext,
  3189. wP = this._weightPrev, wN = this._weightNext,
  3190. p = ( t - t0 ) / ( t1 - t0 ),
  3191. pp = p * p,
  3192. ppp = pp * p;
  3193. // evaluate polynomials
  3194. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  3195. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  3196. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  3197. var sN = wN * ppp - wN * pp;
  3198. // combine data linearly
  3199. for ( var i = 0; i !== stride; ++ i ) {
  3200. result[ i ] =
  3201. sP * values[ oP + i ] +
  3202. s0 * values[ o0 + i ] +
  3203. s1 * values[ o1 + i ] +
  3204. sN * values[ oN + i ];
  3205. }
  3206. return result;
  3207. }
  3208. } );
  3209. /**
  3210. *
  3211. * Interpolant that evaluates to the sample value at the position preceeding
  3212. * the parameter.
  3213. *
  3214. * @author tschw
  3215. */
  3216. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  3217. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  3218. }
  3219. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  3220. constructor: DiscreteInterpolant,
  3221. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  3222. return this.copySampleValue_( i1 - 1 );
  3223. }
  3224. } );
  3225. var KeyframeTrackPrototype;
  3226. KeyframeTrackPrototype = {
  3227. TimeBufferType: Float32Array,
  3228. ValueBufferType: Float32Array,
  3229. DefaultInterpolation: InterpolateLinear,
  3230. InterpolantFactoryMethodDiscrete: function ( result ) {
  3231. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  3232. },
  3233. InterpolantFactoryMethodLinear: function ( result ) {
  3234. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  3235. },
  3236. InterpolantFactoryMethodSmooth: function ( result ) {
  3237. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  3238. },
  3239. setInterpolation: function ( interpolation ) {
  3240. var factoryMethod;
  3241. switch ( interpolation ) {
  3242. case InterpolateDiscrete:
  3243. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  3244. break;
  3245. case InterpolateLinear:
  3246. factoryMethod = this.InterpolantFactoryMethodLinear;
  3247. break;
  3248. case InterpolateSmooth:
  3249. factoryMethod = this.InterpolantFactoryMethodSmooth;
  3250. break;
  3251. }
  3252. if ( factoryMethod === undefined ) {
  3253. var message = "unsupported interpolation for " +
  3254. this.ValueTypeName + " keyframe track named " + this.name;
  3255. if ( this.createInterpolant === undefined ) {
  3256. // fall back to default, unless the default itself is messed up
  3257. if ( interpolation !== this.DefaultInterpolation ) {
  3258. this.setInterpolation( this.DefaultInterpolation );
  3259. } else {
  3260. throw new Error( message ); // fatal, in this case
  3261. }
  3262. }
  3263. console.warn( 'THREE.KeyframeTrackPrototype:', message );
  3264. return;
  3265. }
  3266. this.createInterpolant = factoryMethod;
  3267. },
  3268. getInterpolation: function () {
  3269. switch ( this.createInterpolant ) {
  3270. case this.InterpolantFactoryMethodDiscrete:
  3271. return InterpolateDiscrete;
  3272. case this.InterpolantFactoryMethodLinear:
  3273. return InterpolateLinear;
  3274. case this.InterpolantFactoryMethodSmooth:
  3275. return InterpolateSmooth;
  3276. }
  3277. },
  3278. getValueSize: function () {
  3279. return this.values.length / this.times.length;
  3280. },
  3281. // move all keyframes either forwards or backwards in time
  3282. shift: function ( timeOffset ) {
  3283. if ( timeOffset !== 0.0 ) {
  3284. var times = this.times;
  3285. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  3286. times[ i ] += timeOffset;
  3287. }
  3288. }
  3289. return this;
  3290. },
  3291. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  3292. scale: function ( timeScale ) {
  3293. if ( timeScale !== 1.0 ) {
  3294. var times = this.times;
  3295. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  3296. times[ i ] *= timeScale;
  3297. }
  3298. }
  3299. return this;
  3300. },
  3301. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  3302. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  3303. trim: function ( startTime, endTime ) {
  3304. var times = this.times,
  3305. nKeys = times.length,
  3306. from = 0,
  3307. to = nKeys - 1;
  3308. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  3309. while ( to !== - 1 && times[ to ] > endTime ) -- to;
  3310. ++ to; // inclusive -> exclusive bound
  3311. if ( from !== 0 || to !== nKeys ) {
  3312. // empty tracks are forbidden, so keep at least one keyframe
  3313. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  3314. var stride = this.getValueSize();
  3315. this.times = AnimationUtils.arraySlice( times, from, to );
  3316. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  3317. }
  3318. return this;
  3319. },
  3320. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  3321. validate: function () {
  3322. var valid = true;
  3323. var valueSize = this.getValueSize();
  3324. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  3325. console.error( 'THREE.KeyframeTrackPrototype: Invalid value size in track.', this );
  3326. valid = false;
  3327. }
  3328. var times = this.times,
  3329. values = this.values,
  3330. nKeys = times.length;
  3331. if ( nKeys === 0 ) {
  3332. console.error( 'THREE.KeyframeTrackPrototype: Track is empty.', this );
  3333. valid = false;
  3334. }
  3335. var prevTime = null;
  3336. for ( var i = 0; i !== nKeys; i ++ ) {
  3337. var currTime = times[ i ];
  3338. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  3339. console.error( 'THREE.KeyframeTrackPrototype: Time is not a valid number.', this, i, currTime );
  3340. valid = false;
  3341. break;
  3342. }
  3343. if ( prevTime !== null && prevTime > currTime ) {
  3344. console.error( 'THREE.KeyframeTrackPrototype: Out of order keys.', this, i, currTime, prevTime );
  3345. valid = false;
  3346. break;
  3347. }
  3348. prevTime = currTime;
  3349. }
  3350. if ( values !== undefined ) {
  3351. if ( AnimationUtils.isTypedArray( values ) ) {
  3352. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  3353. var value = values[ i ];
  3354. if ( isNaN( value ) ) {
  3355. console.error( 'THREE.KeyframeTrackPrototype: Value is not a valid number.', this, i, value );
  3356. valid = false;
  3357. break;
  3358. }
  3359. }
  3360. }
  3361. }
  3362. return valid;
  3363. },
  3364. // removes equivalent sequential keys as common in morph target sequences
  3365. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  3366. optimize: function () {
  3367. var times = this.times,
  3368. values = this.values,
  3369. stride = this.getValueSize(),
  3370. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  3371. writeIndex = 1,
  3372. lastIndex = times.length - 1;
  3373. for ( var i = 1; i < lastIndex; ++ i ) {
  3374. var keep = false;
  3375. var time = times[ i ];
  3376. var timeNext = times[ i + 1 ];
  3377. // remove adjacent keyframes scheduled at the same time
  3378. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  3379. if ( ! smoothInterpolation ) {
  3380. // remove unnecessary keyframes same as their neighbors
  3381. var offset = i * stride,
  3382. offsetP = offset - stride,
  3383. offsetN = offset + stride;
  3384. for ( var j = 0; j !== stride; ++ j ) {
  3385. var value = values[ offset + j ];
  3386. if ( value !== values[ offsetP + j ] ||
  3387. value !== values[ offsetN + j ] ) {
  3388. keep = true;
  3389. break;
  3390. }
  3391. }
  3392. } else keep = true;
  3393. }
  3394. // in-place compaction
  3395. if ( keep ) {
  3396. if ( i !== writeIndex ) {
  3397. times[ writeIndex ] = times[ i ];
  3398. var readOffset = i * stride,
  3399. writeOffset = writeIndex * stride;
  3400. for ( var j = 0; j !== stride; ++ j )
  3401. values[ writeOffset + j ] = values[ readOffset + j ];
  3402. }
  3403. ++ writeIndex;
  3404. }
  3405. }
  3406. // flush last keyframe (compaction looks ahead)
  3407. if ( lastIndex > 0 ) {
  3408. times[ writeIndex ] = times[ lastIndex ];
  3409. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j )
  3410. values[ writeOffset + j ] = values[ readOffset + j ];
  3411. ++ writeIndex;
  3412. }
  3413. if ( writeIndex !== times.length ) {
  3414. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  3415. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  3416. }
  3417. return this;
  3418. }
  3419. };
  3420. function KeyframeTrackConstructor( name, times, values, interpolation ) {
  3421. if ( name === undefined ) throw new Error( 'track name is undefined' );
  3422. if ( times === undefined || times.length === 0 ) {
  3423. throw new Error( 'no keyframes in track named ' + name );
  3424. }
  3425. this.name = name;
  3426. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  3427. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  3428. this.setInterpolation( interpolation || this.DefaultInterpolation );
  3429. this.validate();
  3430. this.optimize();
  3431. }
  3432. /**
  3433. *
  3434. * A Track of vectored keyframe values.
  3435. *
  3436. *
  3437. * @author Ben Houston / http://clara.io/
  3438. * @author David Sarno / http://lighthaus.us/
  3439. * @author tschw
  3440. */
  3441. function VectorKeyframeTrack( name, times, values, interpolation ) {
  3442. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3443. }
  3444. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3445. constructor: VectorKeyframeTrack,
  3446. ValueTypeName: 'vector'
  3447. // ValueBufferType is inherited
  3448. // DefaultInterpolation is inherited
  3449. } );
  3450. /**
  3451. * Spherical linear unit quaternion interpolant.
  3452. *
  3453. * @author tschw
  3454. */
  3455. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  3456. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  3457. }
  3458. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  3459. constructor: QuaternionLinearInterpolant,
  3460. interpolate_: function ( i1, t0, t, t1 ) {
  3461. var result = this.resultBuffer,
  3462. values = this.sampleValues,
  3463. stride = this.valueSize,
  3464. offset = i1 * stride,
  3465. alpha = ( t - t0 ) / ( t1 - t0 );
  3466. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  3467. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  3468. }
  3469. return result;
  3470. }
  3471. } );
  3472. /**
  3473. *
  3474. * A Track of quaternion keyframe values.
  3475. *
  3476. * @author Ben Houston / http://clara.io/
  3477. * @author David Sarno / http://lighthaus.us/
  3478. * @author tschw
  3479. */
  3480. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  3481. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3482. }
  3483. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3484. constructor: QuaternionKeyframeTrack,
  3485. ValueTypeName: 'quaternion',
  3486. // ValueBufferType is inherited
  3487. DefaultInterpolation: InterpolateLinear,
  3488. InterpolantFactoryMethodLinear: function ( result ) {
  3489. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  3490. },
  3491. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  3492. } );
  3493. /**
  3494. *
  3495. * A Track of numeric keyframe values.
  3496. *
  3497. * @author Ben Houston / http://clara.io/
  3498. * @author David Sarno / http://lighthaus.us/
  3499. * @author tschw
  3500. */
  3501. function NumberKeyframeTrack( name, times, values, interpolation ) {
  3502. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3503. }
  3504. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3505. constructor: NumberKeyframeTrack,
  3506. ValueTypeName: 'number'
  3507. // ValueBufferType is inherited
  3508. // DefaultInterpolation is inherited
  3509. } );
  3510. /**
  3511. *
  3512. * A Track that interpolates Strings
  3513. *
  3514. *
  3515. * @author Ben Houston / http://clara.io/
  3516. * @author David Sarno / http://lighthaus.us/
  3517. * @author tschw
  3518. */
  3519. function StringKeyframeTrack( name, times, values, interpolation ) {
  3520. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3521. }
  3522. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3523. constructor: StringKeyframeTrack,
  3524. ValueTypeName: 'string',
  3525. ValueBufferType: Array,
  3526. DefaultInterpolation: InterpolateDiscrete,
  3527. InterpolantFactoryMethodLinear: undefined,
  3528. InterpolantFactoryMethodSmooth: undefined
  3529. } );
  3530. /**
  3531. *
  3532. * A Track of Boolean keyframe values.
  3533. *
  3534. *
  3535. * @author Ben Houston / http://clara.io/
  3536. * @author David Sarno / http://lighthaus.us/
  3537. * @author tschw
  3538. */
  3539. function BooleanKeyframeTrack( name, times, values ) {
  3540. KeyframeTrackConstructor.call( this, name, times, values );
  3541. }
  3542. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3543. constructor: BooleanKeyframeTrack,
  3544. ValueTypeName: 'bool',
  3545. ValueBufferType: Array,
  3546. DefaultInterpolation: InterpolateDiscrete,
  3547. InterpolantFactoryMethodLinear: undefined,
  3548. InterpolantFactoryMethodSmooth: undefined
  3549. // Note: Actually this track could have a optimized / compressed
  3550. // representation of a single value and a custom interpolant that
  3551. // computes "firstValue ^ isOdd( index )".
  3552. } );
  3553. /**
  3554. *
  3555. * A Track of keyframe values that represent color.
  3556. *
  3557. *
  3558. * @author Ben Houston / http://clara.io/
  3559. * @author David Sarno / http://lighthaus.us/
  3560. * @author tschw
  3561. */
  3562. function ColorKeyframeTrack( name, times, values, interpolation ) {
  3563. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3564. }
  3565. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3566. constructor: ColorKeyframeTrack,
  3567. ValueTypeName: 'color'
  3568. // ValueBufferType is inherited
  3569. // DefaultInterpolation is inherited
  3570. // Note: Very basic implementation and nothing special yet.
  3571. // However, this is the place for color space parameterization.
  3572. } );
  3573. /**
  3574. *
  3575. * A timed sequence of keyframes for a specific property.
  3576. *
  3577. *
  3578. * @author Ben Houston / http://clara.io/
  3579. * @author David Sarno / http://lighthaus.us/
  3580. * @author tschw
  3581. */
  3582. function KeyframeTrack( name, times, values, interpolation ) {
  3583. KeyframeTrackConstructor.apply( this, name, times, values, interpolation );
  3584. }
  3585. KeyframeTrack.prototype = KeyframeTrackPrototype;
  3586. KeyframeTrackPrototype.constructor = KeyframeTrack;
  3587. // Static methods:
  3588. Object.assign( KeyframeTrack, {
  3589. // Serialization (in static context, because of constructor invocation
  3590. // and automatic invocation of .toJSON):
  3591. parse: function ( json ) {
  3592. if ( json.type === undefined ) {
  3593. throw new Error( 'track type undefined, can not parse' );
  3594. }
  3595. var trackType = KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  3596. if ( json.times === undefined ) {
  3597. var times = [], values = [];
  3598. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  3599. json.times = times;
  3600. json.values = values;
  3601. }
  3602. // derived classes can define a static parse method
  3603. if ( trackType.parse !== undefined ) {
  3604. return trackType.parse( json );
  3605. } else {
  3606. // by default, we assume a constructor compatible with the base
  3607. return new trackType( json.name, json.times, json.values, json.interpolation );
  3608. }
  3609. },
  3610. toJSON: function ( track ) {
  3611. var trackType = track.constructor;
  3612. var json;
  3613. // derived classes can define a static toJSON method
  3614. if ( trackType.toJSON !== undefined ) {
  3615. json = trackType.toJSON( track );
  3616. } else {
  3617. // by default, we assume the data can be serialized as-is
  3618. json = {
  3619. 'name': track.name,
  3620. 'times': AnimationUtils.convertArray( track.times, Array ),
  3621. 'values': AnimationUtils.convertArray( track.values, Array )
  3622. };
  3623. var interpolation = track.getInterpolation();
  3624. if ( interpolation !== track.DefaultInterpolation ) {
  3625. json.interpolation = interpolation;
  3626. }
  3627. }
  3628. json.type = track.ValueTypeName; // mandatory
  3629. return json;
  3630. },
  3631. _getTrackTypeForValueTypeName: function ( typeName ) {
  3632. switch ( typeName.toLowerCase() ) {
  3633. case 'scalar':
  3634. case 'double':
  3635. case 'float':
  3636. case 'number':
  3637. case 'integer':
  3638. return NumberKeyframeTrack;
  3639. case 'vector':
  3640. case 'vector2':
  3641. case 'vector3':
  3642. case 'vector4':
  3643. return VectorKeyframeTrack;
  3644. case 'color':
  3645. return ColorKeyframeTrack;
  3646. case 'quaternion':
  3647. return QuaternionKeyframeTrack;
  3648. case 'bool':
  3649. case 'boolean':
  3650. return BooleanKeyframeTrack;
  3651. case 'string':
  3652. return StringKeyframeTrack;
  3653. }
  3654. throw new Error( 'Unsupported typeName: ' + typeName );
  3655. }
  3656. } );
  3657. /**
  3658. *
  3659. * Reusable set of Tracks that represent an animation.
  3660. *
  3661. * @author Ben Houston / http://clara.io/
  3662. * @author David Sarno / http://lighthaus.us/
  3663. */
  3664. function AnimationClip( name, duration, tracks ) {
  3665. this.name = name;
  3666. this.tracks = tracks;
  3667. this.duration = ( duration !== undefined ) ? duration : - 1;
  3668. this.uuid = _Math.generateUUID();
  3669. // this means it should figure out its duration by scanning the tracks
  3670. if ( this.duration < 0 ) {
  3671. this.resetDuration();
  3672. }
  3673. this.optimize();
  3674. }
  3675. Object.assign( AnimationClip, {
  3676. parse: function ( json ) {
  3677. var tracks = [],
  3678. jsonTracks = json.tracks,
  3679. frameTime = 1.0 / ( json.fps || 1.0 );
  3680. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  3681. tracks.push( KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  3682. }
  3683. return new AnimationClip( json.name, json.duration, tracks );
  3684. },
  3685. toJSON: function ( clip ) {
  3686. var tracks = [],
  3687. clipTracks = clip.tracks;
  3688. var json = {
  3689. 'name': clip.name,
  3690. 'duration': clip.duration,
  3691. 'tracks': tracks
  3692. };
  3693. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  3694. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  3695. }
  3696. return json;
  3697. },
  3698. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  3699. var numMorphTargets = morphTargetSequence.length;
  3700. var tracks = [];
  3701. for ( var i = 0; i < numMorphTargets; i ++ ) {
  3702. var times = [];
  3703. var values = [];
  3704. times.push(
  3705. ( i + numMorphTargets - 1 ) % numMorphTargets,
  3706. i,
  3707. ( i + 1 ) % numMorphTargets );
  3708. values.push( 0, 1, 0 );
  3709. var order = AnimationUtils.getKeyframeOrder( times );
  3710. times = AnimationUtils.sortedArray( times, 1, order );
  3711. values = AnimationUtils.sortedArray( values, 1, order );
  3712. // if there is a key at the first frame, duplicate it as the
  3713. // last frame as well for perfect loop.
  3714. if ( ! noLoop && times[ 0 ] === 0 ) {
  3715. times.push( numMorphTargets );
  3716. values.push( values[ 0 ] );
  3717. }
  3718. tracks.push(
  3719. new NumberKeyframeTrack(
  3720. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  3721. times, values
  3722. ).scale( 1.0 / fps ) );
  3723. }
  3724. return new AnimationClip( name, - 1, tracks );
  3725. },
  3726. findByName: function ( objectOrClipArray, name ) {
  3727. var clipArray = objectOrClipArray;
  3728. if ( ! Array.isArray( objectOrClipArray ) ) {
  3729. var o = objectOrClipArray;
  3730. clipArray = o.geometry && o.geometry.animations || o.animations;
  3731. }
  3732. for ( var i = 0; i < clipArray.length; i ++ ) {
  3733. if ( clipArray[ i ].name === name ) {
  3734. return clipArray[ i ];
  3735. }
  3736. }
  3737. return null;
  3738. },
  3739. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  3740. var animationToMorphTargets = {};
  3741. // tested with https://regex101.com/ on trick sequences
  3742. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  3743. var pattern = /^([\w-]*?)([\d]+)$/;
  3744. // sort morph target names into animation groups based
  3745. // patterns like Walk_001, Walk_002, Run_001, Run_002
  3746. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  3747. var morphTarget = morphTargets[ i ];
  3748. var parts = morphTarget.name.match( pattern );
  3749. if ( parts && parts.length > 1 ) {
  3750. var name = parts[ 1 ];
  3751. var animationMorphTargets = animationToMorphTargets[ name ];
  3752. if ( ! animationMorphTargets ) {
  3753. animationToMorphTargets[ name ] = animationMorphTargets = [];
  3754. }
  3755. animationMorphTargets.push( morphTarget );
  3756. }
  3757. }
  3758. var clips = [];
  3759. for ( var name in animationToMorphTargets ) {
  3760. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  3761. }
  3762. return clips;
  3763. },
  3764. // parse the animation.hierarchy format
  3765. parseAnimation: function ( animation, bones ) {
  3766. if ( ! animation ) {
  3767. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  3768. return null;
  3769. }
  3770. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  3771. // only return track if there are actually keys.
  3772. if ( animationKeys.length !== 0 ) {
  3773. var times = [];
  3774. var values = [];
  3775. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  3776. // empty keys are filtered out, so check again
  3777. if ( times.length !== 0 ) {
  3778. destTracks.push( new trackType( trackName, times, values ) );
  3779. }
  3780. }
  3781. };
  3782. var tracks = [];
  3783. var clipName = animation.name || 'default';
  3784. // automatic length determination in AnimationClip.
  3785. var duration = animation.length || - 1;
  3786. var fps = animation.fps || 30;
  3787. var hierarchyTracks = animation.hierarchy || [];
  3788. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  3789. var animationKeys = hierarchyTracks[ h ].keys;
  3790. // skip empty tracks
  3791. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  3792. // process morph targets
  3793. if ( animationKeys[ 0 ].morphTargets ) {
  3794. // figure out all morph targets used in this track
  3795. var morphTargetNames = {};
  3796. for ( var k = 0; k < animationKeys.length; k ++ ) {
  3797. if ( animationKeys[ k ].morphTargets ) {
  3798. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  3799. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  3800. }
  3801. }
  3802. }
  3803. // create a track for each morph target with all zero
  3804. // morphTargetInfluences except for the keys in which
  3805. // the morphTarget is named.
  3806. for ( var morphTargetName in morphTargetNames ) {
  3807. var times = [];
  3808. var values = [];
  3809. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  3810. var animationKey = animationKeys[ k ];
  3811. times.push( animationKey.time );
  3812. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  3813. }
  3814. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  3815. }
  3816. duration = morphTargetNames.length * ( fps || 1.0 );
  3817. } else {
  3818. // ...assume skeletal animation
  3819. var boneName = '.bones[' + bones[ h ].name + ']';
  3820. addNonemptyTrack(
  3821. VectorKeyframeTrack, boneName + '.position',
  3822. animationKeys, 'pos', tracks );
  3823. addNonemptyTrack(
  3824. QuaternionKeyframeTrack, boneName + '.quaternion',
  3825. animationKeys, 'rot', tracks );
  3826. addNonemptyTrack(
  3827. VectorKeyframeTrack, boneName + '.scale',
  3828. animationKeys, 'scl', tracks );
  3829. }
  3830. }
  3831. if ( tracks.length === 0 ) {
  3832. return null;
  3833. }
  3834. var clip = new AnimationClip( clipName, duration, tracks );
  3835. return clip;
  3836. }
  3837. } );
  3838. Object.assign( AnimationClip.prototype, {
  3839. resetDuration: function () {
  3840. var tracks = this.tracks, duration = 0;
  3841. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  3842. var track = this.tracks[ i ];
  3843. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  3844. }
  3845. this.duration = duration;
  3846. },
  3847. trim: function () {
  3848. for ( var i = 0; i < this.tracks.length; i ++ ) {
  3849. this.tracks[ i ].trim( 0, this.duration );
  3850. }
  3851. return this;
  3852. },
  3853. optimize: function () {
  3854. for ( var i = 0; i < this.tracks.length; i ++ ) {
  3855. this.tracks[ i ].optimize();
  3856. }
  3857. return this;
  3858. }
  3859. } );
  3860. /**
  3861. *
  3862. * Player for AnimationClips.
  3863. *
  3864. *
  3865. * @author Ben Houston / http://clara.io/
  3866. * @author David Sarno / http://lighthaus.us/
  3867. * @author tschw
  3868. */
  3869. function AnimationMixer( root ) {
  3870. this._root = root;
  3871. this._initMemoryManager();
  3872. this._accuIndex = 0;
  3873. this.time = 0;
  3874. this.timeScale = 1.0;
  3875. }
  3876. Object.assign( AnimationMixer.prototype, EventDispatcher.prototype, {
  3877. _bindAction: function ( action, prototypeAction ) {
  3878. var root = action._localRoot || this._root,
  3879. tracks = action._clip.tracks,
  3880. nTracks = tracks.length,
  3881. bindings = action._propertyBindings,
  3882. interpolants = action._interpolants,
  3883. rootUuid = root.uuid,
  3884. bindingsByRoot = this._bindingsByRootAndName,
  3885. bindingsByName = bindingsByRoot[ rootUuid ];
  3886. if ( bindingsByName === undefined ) {
  3887. bindingsByName = {};
  3888. bindingsByRoot[ rootUuid ] = bindingsByName;
  3889. }
  3890. for ( var i = 0; i !== nTracks; ++ i ) {
  3891. var track = tracks[ i ],
  3892. trackName = track.name,
  3893. binding = bindingsByName[ trackName ];
  3894. if ( binding !== undefined ) {
  3895. bindings[ i ] = binding;
  3896. } else {
  3897. binding = bindings[ i ];
  3898. if ( binding !== undefined ) {
  3899. // existing binding, make sure the cache knows
  3900. if ( binding._cacheIndex === null ) {
  3901. ++ binding.referenceCount;
  3902. this._addInactiveBinding( binding, rootUuid, trackName );
  3903. }
  3904. continue;
  3905. }
  3906. var path = prototypeAction && prototypeAction.
  3907. _propertyBindings[ i ].binding.parsedPath;
  3908. binding = new PropertyMixer(
  3909. PropertyBinding.create( root, trackName, path ),
  3910. track.ValueTypeName, track.getValueSize() );
  3911. ++ binding.referenceCount;
  3912. this._addInactiveBinding( binding, rootUuid, trackName );
  3913. bindings[ i ] = binding;
  3914. }
  3915. interpolants[ i ].resultBuffer = binding.buffer;
  3916. }
  3917. },
  3918. _activateAction: function ( action ) {
  3919. if ( ! this._isActiveAction( action ) ) {
  3920. if ( action._cacheIndex === null ) {
  3921. // this action has been forgotten by the cache, but the user
  3922. // appears to be still using it -> rebind
  3923. var rootUuid = ( action._localRoot || this._root ).uuid,
  3924. clipUuid = action._clip.uuid,
  3925. actionsForClip = this._actionsByClip[ clipUuid ];
  3926. this._bindAction( action,
  3927. actionsForClip && actionsForClip.knownActions[ 0 ] );
  3928. this._addInactiveAction( action, clipUuid, rootUuid );
  3929. }
  3930. var bindings = action._propertyBindings;
  3931. // increment reference counts / sort out state
  3932. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  3933. var binding = bindings[ i ];
  3934. if ( binding.useCount ++ === 0 ) {
  3935. this._lendBinding( binding );
  3936. binding.saveOriginalState();
  3937. }
  3938. }
  3939. this._lendAction( action );
  3940. }
  3941. },
  3942. _deactivateAction: function ( action ) {
  3943. if ( this._isActiveAction( action ) ) {
  3944. var bindings = action._propertyBindings;
  3945. // decrement reference counts / sort out state
  3946. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  3947. var binding = bindings[ i ];
  3948. if ( -- binding.useCount === 0 ) {
  3949. binding.restoreOriginalState();
  3950. this._takeBackBinding( binding );
  3951. }
  3952. }
  3953. this._takeBackAction( action );
  3954. }
  3955. },
  3956. // Memory manager
  3957. _initMemoryManager: function () {
  3958. this._actions = []; // 'nActiveActions' followed by inactive ones
  3959. this._nActiveActions = 0;
  3960. this._actionsByClip = {};
  3961. // inside:
  3962. // {
  3963. // knownActions: Array< AnimationAction > - used as prototypes
  3964. // actionByRoot: AnimationAction - lookup
  3965. // }
  3966. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  3967. this._nActiveBindings = 0;
  3968. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  3969. this._controlInterpolants = []; // same game as above
  3970. this._nActiveControlInterpolants = 0;
  3971. var scope = this;
  3972. this.stats = {
  3973. actions: {
  3974. get total() {
  3975. return scope._actions.length;
  3976. },
  3977. get inUse() {
  3978. return scope._nActiveActions;
  3979. }
  3980. },
  3981. bindings: {
  3982. get total() {
  3983. return scope._bindings.length;
  3984. },
  3985. get inUse() {
  3986. return scope._nActiveBindings;
  3987. }
  3988. },
  3989. controlInterpolants: {
  3990. get total() {
  3991. return scope._controlInterpolants.length;
  3992. },
  3993. get inUse() {
  3994. return scope._nActiveControlInterpolants;
  3995. }
  3996. }
  3997. };
  3998. },
  3999. // Memory management for AnimationAction objects
  4000. _isActiveAction: function ( action ) {
  4001. var index = action._cacheIndex;
  4002. return index !== null && index < this._nActiveActions;
  4003. },
  4004. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  4005. var actions = this._actions,
  4006. actionsByClip = this._actionsByClip,
  4007. actionsForClip = actionsByClip[ clipUuid ];
  4008. if ( actionsForClip === undefined ) {
  4009. actionsForClip = {
  4010. knownActions: [ action ],
  4011. actionByRoot: {}
  4012. };
  4013. action._byClipCacheIndex = 0;
  4014. actionsByClip[ clipUuid ] = actionsForClip;
  4015. } else {
  4016. var knownActions = actionsForClip.knownActions;
  4017. action._byClipCacheIndex = knownActions.length;
  4018. knownActions.push( action );
  4019. }
  4020. action._cacheIndex = actions.length;
  4021. actions.push( action );
  4022. actionsForClip.actionByRoot[ rootUuid ] = action;
  4023. },
  4024. _removeInactiveAction: function ( action ) {
  4025. var actions = this._actions,
  4026. lastInactiveAction = actions[ actions.length - 1 ],
  4027. cacheIndex = action._cacheIndex;
  4028. lastInactiveAction._cacheIndex = cacheIndex;
  4029. actions[ cacheIndex ] = lastInactiveAction;
  4030. actions.pop();
  4031. action._cacheIndex = null;
  4032. var clipUuid = action._clip.uuid,
  4033. actionsByClip = this._actionsByClip,
  4034. actionsForClip = actionsByClip[ clipUuid ],
  4035. knownActionsForClip = actionsForClip.knownActions,
  4036. lastKnownAction =
  4037. knownActionsForClip[ knownActionsForClip.length - 1 ],
  4038. byClipCacheIndex = action._byClipCacheIndex;
  4039. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  4040. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  4041. knownActionsForClip.pop();
  4042. action._byClipCacheIndex = null;
  4043. var actionByRoot = actionsForClip.actionByRoot,
  4044. rootUuid = ( action._localRoot || this._root ).uuid;
  4045. delete actionByRoot[ rootUuid ];
  4046. if ( knownActionsForClip.length === 0 ) {
  4047. delete actionsByClip[ clipUuid ];
  4048. }
  4049. this._removeInactiveBindingsForAction( action );
  4050. },
  4051. _removeInactiveBindingsForAction: function ( action ) {
  4052. var bindings = action._propertyBindings;
  4053. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  4054. var binding = bindings[ i ];
  4055. if ( -- binding.referenceCount === 0 ) {
  4056. this._removeInactiveBinding( binding );
  4057. }
  4058. }
  4059. },
  4060. _lendAction: function ( action ) {
  4061. // [ active actions | inactive actions ]
  4062. // [ active actions >| inactive actions ]
  4063. // s a
  4064. // <-swap->
  4065. // a s
  4066. var actions = this._actions,
  4067. prevIndex = action._cacheIndex,
  4068. lastActiveIndex = this._nActiveActions ++,
  4069. firstInactiveAction = actions[ lastActiveIndex ];
  4070. action._cacheIndex = lastActiveIndex;
  4071. actions[ lastActiveIndex ] = action;
  4072. firstInactiveAction._cacheIndex = prevIndex;
  4073. actions[ prevIndex ] = firstInactiveAction;
  4074. },
  4075. _takeBackAction: function ( action ) {
  4076. // [ active actions | inactive actions ]
  4077. // [ active actions |< inactive actions ]
  4078. // a s
  4079. // <-swap->
  4080. // s a
  4081. var actions = this._actions,
  4082. prevIndex = action._cacheIndex,
  4083. firstInactiveIndex = -- this._nActiveActions,
  4084. lastActiveAction = actions[ firstInactiveIndex ];
  4085. action._cacheIndex = firstInactiveIndex;
  4086. actions[ firstInactiveIndex ] = action;
  4087. lastActiveAction._cacheIndex = prevIndex;
  4088. actions[ prevIndex ] = lastActiveAction;
  4089. },
  4090. // Memory management for PropertyMixer objects
  4091. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  4092. var bindingsByRoot = this._bindingsByRootAndName,
  4093. bindingByName = bindingsByRoot[ rootUuid ],
  4094. bindings = this._bindings;
  4095. if ( bindingByName === undefined ) {
  4096. bindingByName = {};
  4097. bindingsByRoot[ rootUuid ] = bindingByName;
  4098. }
  4099. bindingByName[ trackName ] = binding;
  4100. binding._cacheIndex = bindings.length;
  4101. bindings.push( binding );
  4102. },
  4103. _removeInactiveBinding: function ( binding ) {
  4104. var bindings = this._bindings,
  4105. propBinding = binding.binding,
  4106. rootUuid = propBinding.rootNode.uuid,
  4107. trackName = propBinding.path,
  4108. bindingsByRoot = this._bindingsByRootAndName,
  4109. bindingByName = bindingsByRoot[ rootUuid ],
  4110. lastInactiveBinding = bindings[ bindings.length - 1 ],
  4111. cacheIndex = binding._cacheIndex;
  4112. lastInactiveBinding._cacheIndex = cacheIndex;
  4113. bindings[ cacheIndex ] = lastInactiveBinding;
  4114. bindings.pop();
  4115. delete bindingByName[ trackName ];
  4116. remove_empty_map: {
  4117. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  4118. delete bindingsByRoot[ rootUuid ];
  4119. }
  4120. },
  4121. _lendBinding: function ( binding ) {
  4122. var bindings = this._bindings,
  4123. prevIndex = binding._cacheIndex,
  4124. lastActiveIndex = this._nActiveBindings ++,
  4125. firstInactiveBinding = bindings[ lastActiveIndex ];
  4126. binding._cacheIndex = lastActiveIndex;
  4127. bindings[ lastActiveIndex ] = binding;
  4128. firstInactiveBinding._cacheIndex = prevIndex;
  4129. bindings[ prevIndex ] = firstInactiveBinding;
  4130. },
  4131. _takeBackBinding: function ( binding ) {
  4132. var bindings = this._bindings,
  4133. prevIndex = binding._cacheIndex,
  4134. firstInactiveIndex = -- this._nActiveBindings,
  4135. lastActiveBinding = bindings[ firstInactiveIndex ];
  4136. binding._cacheIndex = firstInactiveIndex;
  4137. bindings[ firstInactiveIndex ] = binding;
  4138. lastActiveBinding._cacheIndex = prevIndex;
  4139. bindings[ prevIndex ] = lastActiveBinding;
  4140. },
  4141. // Memory management of Interpolants for weight and time scale
  4142. _lendControlInterpolant: function () {
  4143. var interpolants = this._controlInterpolants,
  4144. lastActiveIndex = this._nActiveControlInterpolants ++,
  4145. interpolant = interpolants[ lastActiveIndex ];
  4146. if ( interpolant === undefined ) {
  4147. interpolant = new LinearInterpolant(
  4148. new Float32Array( 2 ), new Float32Array( 2 ),
  4149. 1, this._controlInterpolantsResultBuffer );
  4150. interpolant.__cacheIndex = lastActiveIndex;
  4151. interpolants[ lastActiveIndex ] = interpolant;
  4152. }
  4153. return interpolant;
  4154. },
  4155. _takeBackControlInterpolant: function ( interpolant ) {
  4156. var interpolants = this._controlInterpolants,
  4157. prevIndex = interpolant.__cacheIndex,
  4158. firstInactiveIndex = -- this._nActiveControlInterpolants,
  4159. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  4160. interpolant.__cacheIndex = firstInactiveIndex;
  4161. interpolants[ firstInactiveIndex ] = interpolant;
  4162. lastActiveInterpolant.__cacheIndex = prevIndex;
  4163. interpolants[ prevIndex ] = lastActiveInterpolant;
  4164. },
  4165. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  4166. // return an action for a clip optionally using a custom root target
  4167. // object (this method allocates a lot of dynamic memory in case a
  4168. // previously unknown clip/root combination is specified)
  4169. clipAction: function ( clip, optionalRoot ) {
  4170. var root = optionalRoot || this._root,
  4171. rootUuid = root.uuid,
  4172. clipObject = typeof clip === 'string' ?
  4173. AnimationClip.findByName( root, clip ) : clip,
  4174. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  4175. actionsForClip = this._actionsByClip[ clipUuid ],
  4176. prototypeAction = null;
  4177. if ( actionsForClip !== undefined ) {
  4178. var existingAction =
  4179. actionsForClip.actionByRoot[ rootUuid ];
  4180. if ( existingAction !== undefined ) {
  4181. return existingAction;
  4182. }
  4183. // we know the clip, so we don't have to parse all
  4184. // the bindings again but can just copy
  4185. prototypeAction = actionsForClip.knownActions[ 0 ];
  4186. // also, take the clip from the prototype action
  4187. if ( clipObject === null )
  4188. clipObject = prototypeAction._clip;
  4189. }
  4190. // clip must be known when specified via string
  4191. if ( clipObject === null ) return null;
  4192. // allocate all resources required to run it
  4193. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  4194. this._bindAction( newAction, prototypeAction );
  4195. // and make the action known to the memory manager
  4196. this._addInactiveAction( newAction, clipUuid, rootUuid );
  4197. return newAction;
  4198. },
  4199. // get an existing action
  4200. existingAction: function ( clip, optionalRoot ) {
  4201. var root = optionalRoot || this._root,
  4202. rootUuid = root.uuid,
  4203. clipObject = typeof clip === 'string' ?
  4204. AnimationClip.findByName( root, clip ) : clip,
  4205. clipUuid = clipObject ? clipObject.uuid : clip,
  4206. actionsForClip = this._actionsByClip[ clipUuid ];
  4207. if ( actionsForClip !== undefined ) {
  4208. return actionsForClip.actionByRoot[ rootUuid ] || null;
  4209. }
  4210. return null;
  4211. },
  4212. // deactivates all previously scheduled actions
  4213. stopAllAction: function () {
  4214. var actions = this._actions,
  4215. nActions = this._nActiveActions,
  4216. bindings = this._bindings,
  4217. nBindings = this._nActiveBindings;
  4218. this._nActiveActions = 0;
  4219. this._nActiveBindings = 0;
  4220. for ( var i = 0; i !== nActions; ++ i ) {
  4221. actions[ i ].reset();
  4222. }
  4223. for ( var i = 0; i !== nBindings; ++ i ) {
  4224. bindings[ i ].useCount = 0;
  4225. }
  4226. return this;
  4227. },
  4228. // advance the time and update apply the animation
  4229. update: function ( deltaTime ) {
  4230. deltaTime *= this.timeScale;
  4231. var actions = this._actions,
  4232. nActions = this._nActiveActions,
  4233. time = this.time += deltaTime,
  4234. timeDirection = Math.sign( deltaTime ),
  4235. accuIndex = this._accuIndex ^= 1;
  4236. // run active actions
  4237. for ( var i = 0; i !== nActions; ++ i ) {
  4238. var action = actions[ i ];
  4239. action._update( time, deltaTime, timeDirection, accuIndex );
  4240. }
  4241. // update scene graph
  4242. var bindings = this._bindings,
  4243. nBindings = this._nActiveBindings;
  4244. for ( var i = 0; i !== nBindings; ++ i ) {
  4245. bindings[ i ].apply( accuIndex );
  4246. }
  4247. return this;
  4248. },
  4249. // return this mixer's root target object
  4250. getRoot: function () {
  4251. return this._root;
  4252. },
  4253. // free all resources specific to a particular clip
  4254. uncacheClip: function ( clip ) {
  4255. var actions = this._actions,
  4256. clipUuid = clip.uuid,
  4257. actionsByClip = this._actionsByClip,
  4258. actionsForClip = actionsByClip[ clipUuid ];
  4259. if ( actionsForClip !== undefined ) {
  4260. // note: just calling _removeInactiveAction would mess up the
  4261. // iteration state and also require updating the state we can
  4262. // just throw away
  4263. var actionsToRemove = actionsForClip.knownActions;
  4264. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  4265. var action = actionsToRemove[ i ];
  4266. this._deactivateAction( action );
  4267. var cacheIndex = action._cacheIndex,
  4268. lastInactiveAction = actions[ actions.length - 1 ];
  4269. action._cacheIndex = null;
  4270. action._byClipCacheIndex = null;
  4271. lastInactiveAction._cacheIndex = cacheIndex;
  4272. actions[ cacheIndex ] = lastInactiveAction;
  4273. actions.pop();
  4274. this._removeInactiveBindingsForAction( action );
  4275. }
  4276. delete actionsByClip[ clipUuid ];
  4277. }
  4278. },
  4279. // free all resources specific to a particular root target object
  4280. uncacheRoot: function ( root ) {
  4281. var rootUuid = root.uuid,
  4282. actionsByClip = this._actionsByClip;
  4283. for ( var clipUuid in actionsByClip ) {
  4284. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  4285. action = actionByRoot[ rootUuid ];
  4286. if ( action !== undefined ) {
  4287. this._deactivateAction( action );
  4288. this._removeInactiveAction( action );
  4289. }
  4290. }
  4291. var bindingsByRoot = this._bindingsByRootAndName,
  4292. bindingByName = bindingsByRoot[ rootUuid ];
  4293. if ( bindingByName !== undefined ) {
  4294. for ( var trackName in bindingByName ) {
  4295. var binding = bindingByName[ trackName ];
  4296. binding.restoreOriginalState();
  4297. this._removeInactiveBinding( binding );
  4298. }
  4299. }
  4300. },
  4301. // remove a targeted clip from the cache
  4302. uncacheAction: function ( clip, optionalRoot ) {
  4303. var action = this.existingAction( clip, optionalRoot );
  4304. if ( action !== null ) {
  4305. this._deactivateAction( action );
  4306. this._removeInactiveAction( action );
  4307. }
  4308. }
  4309. } );
  4310. /**
  4311. * @author TristanVALCKE / https://github.com/Itee
  4312. */
  4313. /* global QUnit */
  4314. QUnit.module( 'Animation', () => {
  4315. QUnit.module.todo( 'AnimationAction', () => {
  4316. // INSTANCING
  4317. QUnit.test( "Instancing", ( assert ) => {
  4318. var mixer = new AnimationMixer();
  4319. var clip = new AnimationClip();
  4320. assert.throws(
  4321. function () {
  4322. new AnimationAction();
  4323. },
  4324. new Error( "Mixer can't be null or undefined !" ),
  4325. "raised error instance about undefined or null mixer"
  4326. );
  4327. assert.throws(
  4328. function () {
  4329. new AnimationAction( mixer );
  4330. },
  4331. new Error( "Clip can't be null or undefined !" ),
  4332. "raised error instance about undefined or null clip"
  4333. );
  4334. var animationAction = new AnimationAction( mixer, clip );
  4335. assert.ok( animationAction, "animationAction instanciated" );
  4336. } );
  4337. // PRIVATE STUFF
  4338. QUnit.test( "_update", ( assert ) => {
  4339. assert.ok( false, "everything's gonna be alright" );
  4340. } );
  4341. QUnit.test( "_updateWeight", ( assert ) => {
  4342. assert.ok( false, "everything's gonna be alright" );
  4343. } );
  4344. QUnit.test( "_updateTimeScale", ( assert ) => {
  4345. assert.ok( false, "everything's gonna be alright" );
  4346. } );
  4347. QUnit.test( "_updateTime", ( assert ) => {
  4348. assert.ok( false, "everything's gonna be alright" );
  4349. } );
  4350. QUnit.test( "_setEndings", ( assert ) => {
  4351. assert.ok( false, "everything's gonna be alright" );
  4352. } );
  4353. QUnit.test( "_scheduleFading", ( assert ) => {
  4354. assert.ok( false, "everything's gonna be alright" );
  4355. } );
  4356. // PUBLIC STUFF
  4357. QUnit.test( "play", ( assert ) => {
  4358. assert.ok( false, "everything's gonna be alright" );
  4359. } );
  4360. QUnit.test( "stop", ( assert ) => {
  4361. assert.ok( false, "everything's gonna be alright" );
  4362. } );
  4363. QUnit.test( "reset", ( assert ) => {
  4364. assert.ok( false, "everything's gonna be alright" );
  4365. } );
  4366. QUnit.test( "isRunning", ( assert ) => {
  4367. assert.ok( false, "everything's gonna be alright" );
  4368. } );
  4369. QUnit.test( "isScheduled", ( assert ) => {
  4370. assert.ok( false, "everything's gonna be alright" );
  4371. } );
  4372. QUnit.test( "startAt", ( assert ) => {
  4373. assert.ok( false, "everything's gonna be alright" );
  4374. } );
  4375. QUnit.test( "setLoop", ( assert ) => {
  4376. assert.ok( false, "everything's gonna be alright" );
  4377. } );
  4378. QUnit.test( "setEffectiveWeight", ( assert ) => {
  4379. assert.ok( false, "everything's gonna be alright" );
  4380. } );
  4381. QUnit.test( "getEffectiveWeight", ( assert ) => {
  4382. assert.ok( false, "everything's gonna be alright" );
  4383. } );
  4384. QUnit.test( "fadeIn", ( assert ) => {
  4385. assert.ok( false, "everything's gonna be alright" );
  4386. } );
  4387. QUnit.test( "fadeOut", ( assert ) => {
  4388. assert.ok( false, "everything's gonna be alright" );
  4389. } );
  4390. QUnit.test( "crossFadeFrom", ( assert ) => {
  4391. assert.ok( false, "everything's gonna be alright" );
  4392. } );
  4393. QUnit.test( "crossFadeTo", ( assert ) => {
  4394. assert.ok( false, "everything's gonna be alright" );
  4395. } );
  4396. QUnit.test( "stopFading", ( assert ) => {
  4397. assert.ok( false, "everything's gonna be alright" );
  4398. } );
  4399. QUnit.test( "setEffectiveTimeScale", ( assert ) => {
  4400. assert.ok( false, "everything's gonna be alright" );
  4401. } );
  4402. QUnit.test( "getEffectiveTimeScale", ( assert ) => {
  4403. assert.ok( false, "everything's gonna be alright" );
  4404. } );
  4405. QUnit.test( "setDuration", ( assert ) => {
  4406. assert.ok( false, "everything's gonna be alright" );
  4407. } );
  4408. QUnit.test( "syncWith", ( assert ) => {
  4409. assert.ok( false, "everything's gonna be alright" );
  4410. } );
  4411. QUnit.test( "halt", ( assert ) => {
  4412. assert.ok( false, "everything's gonna be alright" );
  4413. } );
  4414. QUnit.test( "warp", ( assert ) => {
  4415. assert.ok( false, "everything's gonna be alright" );
  4416. } );
  4417. QUnit.test( "stopWarping", ( assert ) => {
  4418. assert.ok( false, "everything's gonna be alright" );
  4419. } );
  4420. QUnit.test( "getMixer", ( assert ) => {
  4421. assert.ok( false, "everything's gonna be alright" );
  4422. } );
  4423. QUnit.test( "getClip", ( assert ) => {
  4424. assert.ok( false, "everything's gonna be alright" );
  4425. } );
  4426. QUnit.test( "getRoot", ( assert ) => {
  4427. assert.ok( false, "everything's gonna be alright" );
  4428. } );
  4429. } );
  4430. } );
  4431. /**
  4432. * @author TristanVALCKE / https://github.com/Itee
  4433. */
  4434. /* global QUnit */
  4435. QUnit.module( 'Animation', () => {
  4436. QUnit.module.todo( 'AnimationClip', () => {
  4437. // INSTANCING
  4438. QUnit.test( "Instancing", ( assert ) => {
  4439. assert.ok( false, "everything's gonna be alright" );
  4440. } );
  4441. // STATIC STUFF
  4442. QUnit.test( "parse", ( assert ) => {
  4443. assert.ok( false, "everything's gonna be alright" );
  4444. } );
  4445. QUnit.test( "toJSON", ( assert ) => {
  4446. assert.ok( false, "everything's gonna be alright" );
  4447. } );
  4448. QUnit.test( "CreateFromMorphTargetSequence", ( assert ) => {
  4449. assert.ok( false, "everything's gonna be alright" );
  4450. } );
  4451. QUnit.test( "findByName", ( assert ) => {
  4452. assert.ok( false, "everything's gonna be alright" );
  4453. } );
  4454. QUnit.test( "CreateClipsFromMorphTargetSequences", ( assert ) => {
  4455. assert.ok( false, "everything's gonna be alright" );
  4456. } );
  4457. QUnit.test( "parseAnimation", ( assert ) => {
  4458. assert.ok( false, "everything's gonna be alright" );
  4459. } );
  4460. // PUBLIC STUFF
  4461. QUnit.test( "resetDuration", ( assert ) => {
  4462. assert.ok( false, "everything's gonna be alright" );
  4463. } );
  4464. QUnit.test( "trim", ( assert ) => {
  4465. assert.ok( false, "everything's gonna be alright" );
  4466. } );
  4467. QUnit.test( "optimize", ( assert ) => {
  4468. assert.ok( false, "everything's gonna be alright" );
  4469. } );
  4470. } );
  4471. } );
  4472. /**
  4473. * @author TristanVALCKE / https://github.com/Itee
  4474. */
  4475. /* global QUnit */
  4476. QUnit.module( 'Animation', () => {
  4477. QUnit.module.todo( 'AnimationMixer', () => {
  4478. // INHERITANCE
  4479. QUnit.test( "Extending", ( assert ) => {
  4480. assert.ok( false, "everything's gonna be alright" );
  4481. } );
  4482. // INSTANCING
  4483. QUnit.test( "Instancing", ( assert ) => {
  4484. assert.ok( false, "everything's gonna be alright" );
  4485. } );
  4486. // PRIVATE STUFF
  4487. QUnit.test( "_bindAction", ( assert ) => {
  4488. assert.ok( false, "everything's gonna be alright" );
  4489. } );
  4490. QUnit.test( "_activateAction", ( assert ) => {
  4491. assert.ok( false, "everything's gonna be alright" );
  4492. } );
  4493. QUnit.test( "_deactivateAction", ( assert ) => {
  4494. assert.ok( false, "everything's gonna be alright" );
  4495. } );
  4496. QUnit.test( "_initMemoryManager", ( assert ) => {
  4497. assert.ok( false, "everything's gonna be alright" );
  4498. } );
  4499. QUnit.test( "_isActiveAction", ( assert ) => {
  4500. assert.ok( false, "everything's gonna be alright" );
  4501. } );
  4502. QUnit.test( "_addInactiveAction", ( assert ) => {
  4503. assert.ok( false, "everything's gonna be alright" );
  4504. } );
  4505. QUnit.test( "_removeInactiveAction", ( assert ) => {
  4506. assert.ok( false, "everything's gonna be alright" );
  4507. } );
  4508. QUnit.test( "_removeInactiveBindingsForAction", ( assert ) => {
  4509. assert.ok( false, "everything's gonna be alright" );
  4510. } );
  4511. QUnit.test( "_lendAction", ( assert ) => {
  4512. assert.ok( false, "everything's gonna be alright" );
  4513. } );
  4514. QUnit.test( "_takeBackAction", ( assert ) => {
  4515. assert.ok( false, "everything's gonna be alright" );
  4516. } );
  4517. QUnit.test( "_addInactiveBinding", ( assert ) => {
  4518. assert.ok( false, "everything's gonna be alright" );
  4519. } );
  4520. QUnit.test( "_removeInactiveBinding", ( assert ) => {
  4521. assert.ok( false, "everything's gonna be alright" );
  4522. } );
  4523. QUnit.test( "_lendBinding", ( assert ) => {
  4524. assert.ok( false, "everything's gonna be alright" );
  4525. } );
  4526. QUnit.test( "_takeBackBinding", ( assert ) => {
  4527. assert.ok( false, "everything's gonna be alright" );
  4528. } );
  4529. QUnit.test( "_lendControlInterpolant", ( assert ) => {
  4530. assert.ok( false, "everything's gonna be alright" );
  4531. } );
  4532. QUnit.test( "_takeBackControlInterpolant", ( assert ) => {
  4533. assert.ok( false, "everything's gonna be alright" );
  4534. } );
  4535. QUnit.test( "_controlInterpolantsResultBuffer", ( assert ) => {
  4536. assert.ok( false, "everything's gonna be alright" );
  4537. } );
  4538. // PUBLIC STUFF
  4539. QUnit.test( "clipAction", ( assert ) => {
  4540. assert.ok( false, "everything's gonna be alright" );
  4541. } );
  4542. QUnit.test( "existingAction", ( assert ) => {
  4543. assert.ok( false, "everything's gonna be alright" );
  4544. } );
  4545. QUnit.test( "stopAllAction", ( assert ) => {
  4546. assert.ok( false, "everything's gonna be alright" );
  4547. } );
  4548. QUnit.test( "update", ( assert ) => {
  4549. assert.ok( false, "everything's gonna be alright" );
  4550. } );
  4551. QUnit.test( "getRoot", ( assert ) => {
  4552. assert.ok( false, "everything's gonna be alright" );
  4553. } );
  4554. QUnit.test( "uncacheClip", ( assert ) => {
  4555. assert.ok( false, "everything's gonna be alright" );
  4556. } );
  4557. QUnit.test( "uncacheRoot", ( assert ) => {
  4558. assert.ok( false, "everything's gonna be alright" );
  4559. } );
  4560. QUnit.test( "uncacheAction", ( assert ) => {
  4561. assert.ok( false, "everything's gonna be alright" );
  4562. } );
  4563. } );
  4564. } );
  4565. /**
  4566. *
  4567. * A group of objects that receives a shared animation state.
  4568. *
  4569. * Usage:
  4570. *
  4571. * - Add objects you would otherwise pass as 'root' to the
  4572. * constructor or the .clipAction method of AnimationMixer.
  4573. *
  4574. * - Instead pass this object as 'root'.
  4575. *
  4576. * - You can also add and remove objects later when the mixer
  4577. * is running.
  4578. *
  4579. * Note:
  4580. *
  4581. * Objects of this class appear as one object to the mixer,
  4582. * so cache control of the individual objects must be done
  4583. * on the group.
  4584. *
  4585. * Limitation:
  4586. *
  4587. * - The animated properties must be compatible among the
  4588. * all objects in the group.
  4589. *
  4590. * - A single property can either be controlled through a
  4591. * target group or directly, but not both.
  4592. *
  4593. * @author tschw
  4594. */
  4595. function AnimationObjectGroup() {
  4596. this.uuid = _Math.generateUUID();
  4597. // cached objects followed by the active ones
  4598. this._objects = Array.prototype.slice.call( arguments );
  4599. this.nCachedObjects_ = 0; // threshold
  4600. // note: read by PropertyBinding.Composite
  4601. var indices = {};
  4602. this._indicesByUUID = indices; // for bookkeeping
  4603. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  4604. indices[ arguments[ i ].uuid ] = i;
  4605. }
  4606. this._paths = []; // inside: string
  4607. this._parsedPaths = []; // inside: { we don't care, here }
  4608. this._bindings = []; // inside: Array< PropertyBinding >
  4609. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  4610. var scope = this;
  4611. this.stats = {
  4612. objects: {
  4613. get total() {
  4614. return scope._objects.length;
  4615. },
  4616. get inUse() {
  4617. return this.total - scope.nCachedObjects_;
  4618. }
  4619. },
  4620. get bindingsPerObject() {
  4621. return scope._bindings.length;
  4622. }
  4623. };
  4624. }
  4625. Object.assign( AnimationObjectGroup.prototype, {
  4626. isAnimationObjectGroup: true,
  4627. add: function () {
  4628. var objects = this._objects,
  4629. nObjects = objects.length,
  4630. nCachedObjects = this.nCachedObjects_,
  4631. indicesByUUID = this._indicesByUUID,
  4632. paths = this._paths,
  4633. parsedPaths = this._parsedPaths,
  4634. bindings = this._bindings,
  4635. nBindings = bindings.length;
  4636. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  4637. var object = arguments[ i ],
  4638. uuid = object.uuid,
  4639. index = indicesByUUID[ uuid ],
  4640. knownObject = undefined;
  4641. if ( index === undefined ) {
  4642. // unknown object -> add it to the ACTIVE region
  4643. index = nObjects ++;
  4644. indicesByUUID[ uuid ] = index;
  4645. objects.push( object );
  4646. // accounting is done, now do the same for all bindings
  4647. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4648. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  4649. }
  4650. } else if ( index < nCachedObjects ) {
  4651. knownObject = objects[ index ];
  4652. // move existing object to the ACTIVE region
  4653. var firstActiveIndex = -- nCachedObjects,
  4654. lastCachedObject = objects[ firstActiveIndex ];
  4655. indicesByUUID[ lastCachedObject.uuid ] = index;
  4656. objects[ index ] = lastCachedObject;
  4657. indicesByUUID[ uuid ] = firstActiveIndex;
  4658. objects[ firstActiveIndex ] = object;
  4659. // accounting is done, now do the same for all bindings
  4660. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4661. var bindingsForPath = bindings[ j ],
  4662. lastCached = bindingsForPath[ firstActiveIndex ],
  4663. binding = bindingsForPath[ index ];
  4664. bindingsForPath[ index ] = lastCached;
  4665. if ( binding === undefined ) {
  4666. // since we do not bother to create new bindings
  4667. // for objects that are cached, the binding may
  4668. // or may not exist
  4669. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  4670. }
  4671. bindingsForPath[ firstActiveIndex ] = binding;
  4672. }
  4673. } else if ( objects[ index ] !== knownObject ) {
  4674. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  4675. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  4676. } // else the object is already where we want it to be
  4677. } // for arguments
  4678. this.nCachedObjects_ = nCachedObjects;
  4679. },
  4680. remove: function () {
  4681. var objects = this._objects,
  4682. nCachedObjects = this.nCachedObjects_,
  4683. indicesByUUID = this._indicesByUUID,
  4684. bindings = this._bindings,
  4685. nBindings = bindings.length;
  4686. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  4687. var object = arguments[ i ],
  4688. uuid = object.uuid,
  4689. index = indicesByUUID[ uuid ];
  4690. if ( index !== undefined && index >= nCachedObjects ) {
  4691. // move existing object into the CACHED region
  4692. var lastCachedIndex = nCachedObjects ++,
  4693. firstActiveObject = objects[ lastCachedIndex ];
  4694. indicesByUUID[ firstActiveObject.uuid ] = index;
  4695. objects[ index ] = firstActiveObject;
  4696. indicesByUUID[ uuid ] = lastCachedIndex;
  4697. objects[ lastCachedIndex ] = object;
  4698. // accounting is done, now do the same for all bindings
  4699. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4700. var bindingsForPath = bindings[ j ],
  4701. firstActive = bindingsForPath[ lastCachedIndex ],
  4702. binding = bindingsForPath[ index ];
  4703. bindingsForPath[ index ] = firstActive;
  4704. bindingsForPath[ lastCachedIndex ] = binding;
  4705. }
  4706. }
  4707. } // for arguments
  4708. this.nCachedObjects_ = nCachedObjects;
  4709. },
  4710. // remove & forget
  4711. uncache: function () {
  4712. var objects = this._objects,
  4713. nObjects = objects.length,
  4714. nCachedObjects = this.nCachedObjects_,
  4715. indicesByUUID = this._indicesByUUID,
  4716. bindings = this._bindings,
  4717. nBindings = bindings.length;
  4718. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  4719. var object = arguments[ i ],
  4720. uuid = object.uuid,
  4721. index = indicesByUUID[ uuid ];
  4722. if ( index !== undefined ) {
  4723. delete indicesByUUID[ uuid ];
  4724. if ( index < nCachedObjects ) {
  4725. // object is cached, shrink the CACHED region
  4726. var firstActiveIndex = -- nCachedObjects,
  4727. lastCachedObject = objects[ firstActiveIndex ],
  4728. lastIndex = -- nObjects,
  4729. lastObject = objects[ lastIndex ];
  4730. // last cached object takes this object's place
  4731. indicesByUUID[ lastCachedObject.uuid ] = index;
  4732. objects[ index ] = lastCachedObject;
  4733. // last object goes to the activated slot and pop
  4734. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  4735. objects[ firstActiveIndex ] = lastObject;
  4736. objects.pop();
  4737. // accounting is done, now do the same for all bindings
  4738. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4739. var bindingsForPath = bindings[ j ],
  4740. lastCached = bindingsForPath[ firstActiveIndex ],
  4741. last = bindingsForPath[ lastIndex ];
  4742. bindingsForPath[ index ] = lastCached;
  4743. bindingsForPath[ firstActiveIndex ] = last;
  4744. bindingsForPath.pop();
  4745. }
  4746. } else {
  4747. // object is active, just swap with the last and pop
  4748. var lastIndex = -- nObjects,
  4749. lastObject = objects[ lastIndex ];
  4750. indicesByUUID[ lastObject.uuid ] = index;
  4751. objects[ index ] = lastObject;
  4752. objects.pop();
  4753. // accounting is done, now do the same for all bindings
  4754. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4755. var bindingsForPath = bindings[ j ];
  4756. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  4757. bindingsForPath.pop();
  4758. }
  4759. } // cached or active
  4760. } // if object is known
  4761. } // for arguments
  4762. this.nCachedObjects_ = nCachedObjects;
  4763. },
  4764. // Internal interface used by befriended PropertyBinding.Composite:
  4765. subscribe_: function ( path, parsedPath ) {
  4766. // returns an array of bindings for the given path that is changed
  4767. // according to the contained objects in the group
  4768. var indicesByPath = this._bindingsIndicesByPath,
  4769. index = indicesByPath[ path ],
  4770. bindings = this._bindings;
  4771. if ( index !== undefined ) return bindings[ index ];
  4772. var paths = this._paths,
  4773. parsedPaths = this._parsedPaths,
  4774. objects = this._objects,
  4775. nObjects = objects.length,
  4776. nCachedObjects = this.nCachedObjects_,
  4777. bindingsForPath = new Array( nObjects );
  4778. index = bindings.length;
  4779. indicesByPath[ path ] = index;
  4780. paths.push( path );
  4781. parsedPaths.push( parsedPath );
  4782. bindings.push( bindingsForPath );
  4783. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  4784. var object = objects[ i ];
  4785. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  4786. }
  4787. return bindingsForPath;
  4788. },
  4789. unsubscribe_: function ( path ) {
  4790. // tells the group to forget about a property path and no longer
  4791. // update the array previously obtained with 'subscribe_'
  4792. var indicesByPath = this._bindingsIndicesByPath,
  4793. index = indicesByPath[ path ];
  4794. if ( index !== undefined ) {
  4795. var paths = this._paths,
  4796. parsedPaths = this._parsedPaths,
  4797. bindings = this._bindings,
  4798. lastBindingsIndex = bindings.length - 1,
  4799. lastBindings = bindings[ lastBindingsIndex ],
  4800. lastBindingsPath = path[ lastBindingsIndex ];
  4801. indicesByPath[ lastBindingsPath ] = index;
  4802. bindings[ index ] = lastBindings;
  4803. bindings.pop();
  4804. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  4805. parsedPaths.pop();
  4806. paths[ index ] = paths[ lastBindingsIndex ];
  4807. paths.pop();
  4808. }
  4809. }
  4810. } );
  4811. /**
  4812. * @author mrdoob / http://mrdoob.com/
  4813. * @author WestLangley / http://github.com/WestLangley
  4814. * @author bhouston / http://clara.io
  4815. */
  4816. function Euler( x, y, z, order ) {
  4817. this._x = x || 0;
  4818. this._y = y || 0;
  4819. this._z = z || 0;
  4820. this._order = order || Euler.DefaultOrder;
  4821. }
  4822. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  4823. Euler.DefaultOrder = 'XYZ';
  4824. Object.defineProperties( Euler.prototype, {
  4825. x: {
  4826. get: function () {
  4827. return this._x;
  4828. },
  4829. set: function ( value ) {
  4830. this._x = value;
  4831. this.onChangeCallback();
  4832. }
  4833. },
  4834. y: {
  4835. get: function () {
  4836. return this._y;
  4837. },
  4838. set: function ( value ) {
  4839. this._y = value;
  4840. this.onChangeCallback();
  4841. }
  4842. },
  4843. z: {
  4844. get: function () {
  4845. return this._z;
  4846. },
  4847. set: function ( value ) {
  4848. this._z = value;
  4849. this.onChangeCallback();
  4850. }
  4851. },
  4852. order: {
  4853. get: function () {
  4854. return this._order;
  4855. },
  4856. set: function ( value ) {
  4857. this._order = value;
  4858. this.onChangeCallback();
  4859. }
  4860. }
  4861. } );
  4862. Object.assign( Euler.prototype, {
  4863. isEuler: true,
  4864. set: function ( x, y, z, order ) {
  4865. this._x = x;
  4866. this._y = y;
  4867. this._z = z;
  4868. this._order = order || this._order;
  4869. this.onChangeCallback();
  4870. return this;
  4871. },
  4872. clone: function () {
  4873. return new this.constructor( this._x, this._y, this._z, this._order );
  4874. },
  4875. copy: function ( euler ) {
  4876. this._x = euler._x;
  4877. this._y = euler._y;
  4878. this._z = euler._z;
  4879. this._order = euler._order;
  4880. this.onChangeCallback();
  4881. return this;
  4882. },
  4883. setFromRotationMatrix: function ( m, order, update ) {
  4884. var clamp = _Math.clamp;
  4885. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4886. var te = m.elements;
  4887. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4888. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4889. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4890. order = order || this._order;
  4891. if ( order === 'XYZ' ) {
  4892. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4893. if ( Math.abs( m13 ) < 0.99999 ) {
  4894. this._x = Math.atan2( - m23, m33 );
  4895. this._z = Math.atan2( - m12, m11 );
  4896. } else {
  4897. this._x = Math.atan2( m32, m22 );
  4898. this._z = 0;
  4899. }
  4900. } else if ( order === 'YXZ' ) {
  4901. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4902. if ( Math.abs( m23 ) < 0.99999 ) {
  4903. this._y = Math.atan2( m13, m33 );
  4904. this._z = Math.atan2( m21, m22 );
  4905. } else {
  4906. this._y = Math.atan2( - m31, m11 );
  4907. this._z = 0;
  4908. }
  4909. } else if ( order === 'ZXY' ) {
  4910. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4911. if ( Math.abs( m32 ) < 0.99999 ) {
  4912. this._y = Math.atan2( - m31, m33 );
  4913. this._z = Math.atan2( - m12, m22 );
  4914. } else {
  4915. this._y = 0;
  4916. this._z = Math.atan2( m21, m11 );
  4917. }
  4918. } else if ( order === 'ZYX' ) {
  4919. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4920. if ( Math.abs( m31 ) < 0.99999 ) {
  4921. this._x = Math.atan2( m32, m33 );
  4922. this._z = Math.atan2( m21, m11 );
  4923. } else {
  4924. this._x = 0;
  4925. this._z = Math.atan2( - m12, m22 );
  4926. }
  4927. } else if ( order === 'YZX' ) {
  4928. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4929. if ( Math.abs( m21 ) < 0.99999 ) {
  4930. this._x = Math.atan2( - m23, m22 );
  4931. this._y = Math.atan2( - m31, m11 );
  4932. } else {
  4933. this._x = 0;
  4934. this._y = Math.atan2( m13, m33 );
  4935. }
  4936. } else if ( order === 'XZY' ) {
  4937. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4938. if ( Math.abs( m12 ) < 0.99999 ) {
  4939. this._x = Math.atan2( m32, m22 );
  4940. this._y = Math.atan2( m13, m11 );
  4941. } else {
  4942. this._x = Math.atan2( - m23, m33 );
  4943. this._y = 0;
  4944. }
  4945. } else {
  4946. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  4947. }
  4948. this._order = order;
  4949. if ( update !== false ) this.onChangeCallback();
  4950. return this;
  4951. },
  4952. setFromQuaternion: function () {
  4953. var matrix = new Matrix4();
  4954. return function setFromQuaternion( q, order, update ) {
  4955. matrix.makeRotationFromQuaternion( q );
  4956. return this.setFromRotationMatrix( matrix, order, update );
  4957. };
  4958. }(),
  4959. setFromVector3: function ( v, order ) {
  4960. return this.set( v.x, v.y, v.z, order || this._order );
  4961. },
  4962. reorder: function () {
  4963. // WARNING: this discards revolution information -bhouston
  4964. var q = new Quaternion();
  4965. return function reorder( newOrder ) {
  4966. q.setFromEuler( this );
  4967. return this.setFromQuaternion( q, newOrder );
  4968. };
  4969. }(),
  4970. equals: function ( euler ) {
  4971. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4972. },
  4973. fromArray: function ( array ) {
  4974. this._x = array[ 0 ];
  4975. this._y = array[ 1 ];
  4976. this._z = array[ 2 ];
  4977. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4978. this.onChangeCallback();
  4979. return this;
  4980. },
  4981. toArray: function ( array, offset ) {
  4982. if ( array === undefined ) array = [];
  4983. if ( offset === undefined ) offset = 0;
  4984. array[ offset ] = this._x;
  4985. array[ offset + 1 ] = this._y;
  4986. array[ offset + 2 ] = this._z;
  4987. array[ offset + 3 ] = this._order;
  4988. return array;
  4989. },
  4990. toVector3: function ( optionalResult ) {
  4991. if ( optionalResult ) {
  4992. return optionalResult.set( this._x, this._y, this._z );
  4993. } else {
  4994. return new Vector3( this._x, this._y, this._z );
  4995. }
  4996. },
  4997. onChange: function ( callback ) {
  4998. this.onChangeCallback = callback;
  4999. return this;
  5000. },
  5001. onChangeCallback: function () {}
  5002. } );
  5003. /**
  5004. * @author mrdoob / http://mrdoob.com/
  5005. */
  5006. function Layers() {
  5007. this.mask = 1 | 0;
  5008. }
  5009. Object.assign( Layers.prototype, {
  5010. set: function ( channel ) {
  5011. this.mask = 1 << channel | 0;
  5012. },
  5013. enable: function ( channel ) {
  5014. this.mask |= 1 << channel | 0;
  5015. },
  5016. toggle: function ( channel ) {
  5017. this.mask ^= 1 << channel | 0;
  5018. },
  5019. disable: function ( channel ) {
  5020. this.mask &= ~ ( 1 << channel | 0 );
  5021. },
  5022. test: function ( layers ) {
  5023. return ( this.mask & layers.mask ) !== 0;
  5024. }
  5025. } );
  5026. /**
  5027. * @author alteredq / http://alteredqualia.com/
  5028. * @author WestLangley / http://github.com/WestLangley
  5029. * @author bhouston / http://clara.io
  5030. * @author tschw
  5031. */
  5032. function Matrix3() {
  5033. this.elements = [
  5034. 1, 0, 0,
  5035. 0, 1, 0,
  5036. 0, 0, 1
  5037. ];
  5038. if ( arguments.length > 0 ) {
  5039. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  5040. }
  5041. }
  5042. Object.assign( Matrix3.prototype, {
  5043. isMatrix3: true,
  5044. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  5045. var te = this.elements;
  5046. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  5047. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  5048. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  5049. return this;
  5050. },
  5051. identity: function () {
  5052. this.set(
  5053. 1, 0, 0,
  5054. 0, 1, 0,
  5055. 0, 0, 1
  5056. );
  5057. return this;
  5058. },
  5059. clone: function () {
  5060. return new this.constructor().fromArray( this.elements );
  5061. },
  5062. copy: function ( m ) {
  5063. var te = this.elements;
  5064. var me = m.elements;
  5065. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  5066. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  5067. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  5068. return this;
  5069. },
  5070. setFromMatrix4: function ( m ) {
  5071. var me = m.elements;
  5072. this.set(
  5073. me[ 0 ], me[ 4 ], me[ 8 ],
  5074. me[ 1 ], me[ 5 ], me[ 9 ],
  5075. me[ 2 ], me[ 6 ], me[ 10 ]
  5076. );
  5077. return this;
  5078. },
  5079. applyToBufferAttribute: function () {
  5080. var v1 = new Vector3();
  5081. return function applyToBufferAttribute( attribute ) {
  5082. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  5083. v1.x = attribute.getX( i );
  5084. v1.y = attribute.getY( i );
  5085. v1.z = attribute.getZ( i );
  5086. v1.applyMatrix3( this );
  5087. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  5088. }
  5089. return attribute;
  5090. };
  5091. }(),
  5092. multiply: function ( m ) {
  5093. return this.multiplyMatrices( this, m );
  5094. },
  5095. premultiply: function ( m ) {
  5096. return this.multiplyMatrices( m, this );
  5097. },
  5098. multiplyMatrices: function ( a, b ) {
  5099. var ae = a.elements;
  5100. var be = b.elements;
  5101. var te = this.elements;
  5102. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  5103. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  5104. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  5105. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  5106. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  5107. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  5108. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  5109. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  5110. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  5111. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  5112. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  5113. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  5114. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  5115. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  5116. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  5117. return this;
  5118. },
  5119. multiplyScalar: function ( s ) {
  5120. var te = this.elements;
  5121. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  5122. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  5123. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  5124. return this;
  5125. },
  5126. determinant: function () {
  5127. var te = this.elements;
  5128. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  5129. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  5130. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  5131. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  5132. },
  5133. getInverse: function ( matrix, throwOnDegenerate ) {
  5134. if ( matrix && matrix.isMatrix4 ) {
  5135. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  5136. }
  5137. var me = matrix.elements,
  5138. te = this.elements,
  5139. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  5140. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  5141. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  5142. t11 = n33 * n22 - n32 * n23,
  5143. t12 = n32 * n13 - n33 * n12,
  5144. t13 = n23 * n12 - n22 * n13,
  5145. det = n11 * t11 + n21 * t12 + n31 * t13;
  5146. if ( det === 0 ) {
  5147. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  5148. if ( throwOnDegenerate === true ) {
  5149. throw new Error( msg );
  5150. } else {
  5151. console.warn( msg );
  5152. }
  5153. return this.identity();
  5154. }
  5155. var detInv = 1 / det;
  5156. te[ 0 ] = t11 * detInv;
  5157. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  5158. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  5159. te[ 3 ] = t12 * detInv;
  5160. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  5161. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  5162. te[ 6 ] = t13 * detInv;
  5163. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  5164. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  5165. return this;
  5166. },
  5167. transpose: function () {
  5168. var tmp, m = this.elements;
  5169. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  5170. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  5171. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  5172. return this;
  5173. },
  5174. getNormalMatrix: function ( matrix4 ) {
  5175. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  5176. },
  5177. transposeIntoArray: function ( r ) {
  5178. var m = this.elements;
  5179. r[ 0 ] = m[ 0 ];
  5180. r[ 1 ] = m[ 3 ];
  5181. r[ 2 ] = m[ 6 ];
  5182. r[ 3 ] = m[ 1 ];
  5183. r[ 4 ] = m[ 4 ];
  5184. r[ 5 ] = m[ 7 ];
  5185. r[ 6 ] = m[ 2 ];
  5186. r[ 7 ] = m[ 5 ];
  5187. r[ 8 ] = m[ 8 ];
  5188. return this;
  5189. },
  5190. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  5191. var c = Math.cos( rotation );
  5192. var s = Math.sin( rotation );
  5193. this.set(
  5194. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  5195. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  5196. 0, 0, 1
  5197. );
  5198. },
  5199. scale: function ( sx, sy ) {
  5200. var te = this.elements;
  5201. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  5202. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  5203. return this;
  5204. },
  5205. rotate: function ( theta ) {
  5206. var c = Math.cos( theta );
  5207. var s = Math.sin( theta );
  5208. var te = this.elements;
  5209. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  5210. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  5211. te[ 0 ] = c * a11 + s * a21;
  5212. te[ 3 ] = c * a12 + s * a22;
  5213. te[ 6 ] = c * a13 + s * a23;
  5214. te[ 1 ] = - s * a11 + c * a21;
  5215. te[ 4 ] = - s * a12 + c * a22;
  5216. te[ 7 ] = - s * a13 + c * a23;
  5217. return this;
  5218. },
  5219. translate: function ( tx, ty ) {
  5220. var te = this.elements;
  5221. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  5222. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  5223. return this;
  5224. },
  5225. equals: function ( matrix ) {
  5226. var te = this.elements;
  5227. var me = matrix.elements;
  5228. for ( var i = 0; i < 9; i ++ ) {
  5229. if ( te[ i ] !== me[ i ] ) return false;
  5230. }
  5231. return true;
  5232. },
  5233. fromArray: function ( array, offset ) {
  5234. if ( offset === undefined ) offset = 0;
  5235. for ( var i = 0; i < 9; i ++ ) {
  5236. this.elements[ i ] = array[ i + offset ];
  5237. }
  5238. return this;
  5239. },
  5240. toArray: function ( array, offset ) {
  5241. if ( array === undefined ) array = [];
  5242. if ( offset === undefined ) offset = 0;
  5243. var te = this.elements;
  5244. array[ offset ] = te[ 0 ];
  5245. array[ offset + 1 ] = te[ 1 ];
  5246. array[ offset + 2 ] = te[ 2 ];
  5247. array[ offset + 3 ] = te[ 3 ];
  5248. array[ offset + 4 ] = te[ 4 ];
  5249. array[ offset + 5 ] = te[ 5 ];
  5250. array[ offset + 6 ] = te[ 6 ];
  5251. array[ offset + 7 ] = te[ 7 ];
  5252. array[ offset + 8 ] = te[ 8 ];
  5253. return array;
  5254. }
  5255. } );
  5256. /**
  5257. * @author mrdoob / http://mrdoob.com/
  5258. * @author mikael emtinger / http://gomo.se/
  5259. * @author alteredq / http://alteredqualia.com/
  5260. * @author WestLangley / http://github.com/WestLangley
  5261. * @author elephantatwork / www.elephantatwork.ch
  5262. */
  5263. var object3DId = 0;
  5264. function Object3D() {
  5265. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  5266. this.uuid = _Math.generateUUID();
  5267. this.name = '';
  5268. this.type = 'Object3D';
  5269. this.parent = null;
  5270. this.children = [];
  5271. this.up = Object3D.DefaultUp.clone();
  5272. var position = new Vector3();
  5273. var rotation = new Euler();
  5274. var quaternion = new Quaternion();
  5275. var scale = new Vector3( 1, 1, 1 );
  5276. function onRotationChange() {
  5277. quaternion.setFromEuler( rotation, false );
  5278. }
  5279. function onQuaternionChange() {
  5280. rotation.setFromQuaternion( quaternion, undefined, false );
  5281. }
  5282. rotation.onChange( onRotationChange );
  5283. quaternion.onChange( onQuaternionChange );
  5284. Object.defineProperties( this, {
  5285. position: {
  5286. enumerable: true,
  5287. value: position
  5288. },
  5289. rotation: {
  5290. enumerable: true,
  5291. value: rotation
  5292. },
  5293. quaternion: {
  5294. enumerable: true,
  5295. value: quaternion
  5296. },
  5297. scale: {
  5298. enumerable: true,
  5299. value: scale
  5300. },
  5301. modelViewMatrix: {
  5302. value: new Matrix4()
  5303. },
  5304. normalMatrix: {
  5305. value: new Matrix3()
  5306. }
  5307. } );
  5308. this.matrix = new Matrix4();
  5309. this.matrixWorld = new Matrix4();
  5310. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5311. this.matrixWorldNeedsUpdate = false;
  5312. this.layers = new Layers();
  5313. this.visible = true;
  5314. this.castShadow = false;
  5315. this.receiveShadow = false;
  5316. this.frustumCulled = true;
  5317. this.renderOrder = 0;
  5318. this.userData = {};
  5319. }
  5320. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  5321. Object3D.DefaultMatrixAutoUpdate = true;
  5322. Object.assign( Object3D.prototype, EventDispatcher.prototype, {
  5323. isObject3D: true,
  5324. onBeforeRender: function () {},
  5325. onAfterRender: function () {},
  5326. applyMatrix: function ( matrix ) {
  5327. this.matrix.multiplyMatrices( matrix, this.matrix );
  5328. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5329. },
  5330. applyQuaternion: function ( q ) {
  5331. this.quaternion.premultiply( q );
  5332. return this;
  5333. },
  5334. setRotationFromAxisAngle: function ( axis, angle ) {
  5335. // assumes axis is normalized
  5336. this.quaternion.setFromAxisAngle( axis, angle );
  5337. },
  5338. setRotationFromEuler: function ( euler ) {
  5339. this.quaternion.setFromEuler( euler, true );
  5340. },
  5341. setRotationFromMatrix: function ( m ) {
  5342. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5343. this.quaternion.setFromRotationMatrix( m );
  5344. },
  5345. setRotationFromQuaternion: function ( q ) {
  5346. // assumes q is normalized
  5347. this.quaternion.copy( q );
  5348. },
  5349. rotateOnAxis: function () {
  5350. // rotate object on axis in object space
  5351. // axis is assumed to be normalized
  5352. var q1 = new Quaternion();
  5353. return function rotateOnAxis( axis, angle ) {
  5354. q1.setFromAxisAngle( axis, angle );
  5355. this.quaternion.multiply( q1 );
  5356. return this;
  5357. };
  5358. }(),
  5359. rotateOnWorldAxis: function () {
  5360. // rotate object on axis in world space
  5361. // axis is assumed to be normalized
  5362. // method assumes no rotated parent
  5363. var q1 = new Quaternion();
  5364. return function rotateOnWorldAxis( axis, angle ) {
  5365. q1.setFromAxisAngle( axis, angle );
  5366. this.quaternion.premultiply( q1 );
  5367. return this;
  5368. };
  5369. }(),
  5370. rotateX: function () {
  5371. var v1 = new Vector3( 1, 0, 0 );
  5372. return function rotateX( angle ) {
  5373. return this.rotateOnAxis( v1, angle );
  5374. };
  5375. }(),
  5376. rotateY: function () {
  5377. var v1 = new Vector3( 0, 1, 0 );
  5378. return function rotateY( angle ) {
  5379. return this.rotateOnAxis( v1, angle );
  5380. };
  5381. }(),
  5382. rotateZ: function () {
  5383. var v1 = new Vector3( 0, 0, 1 );
  5384. return function rotateZ( angle ) {
  5385. return this.rotateOnAxis( v1, angle );
  5386. };
  5387. }(),
  5388. translateOnAxis: function () {
  5389. // translate object by distance along axis in object space
  5390. // axis is assumed to be normalized
  5391. var v1 = new Vector3();
  5392. return function translateOnAxis( axis, distance ) {
  5393. v1.copy( axis ).applyQuaternion( this.quaternion );
  5394. this.position.add( v1.multiplyScalar( distance ) );
  5395. return this;
  5396. };
  5397. }(),
  5398. translateX: function () {
  5399. var v1 = new Vector3( 1, 0, 0 );
  5400. return function translateX( distance ) {
  5401. return this.translateOnAxis( v1, distance );
  5402. };
  5403. }(),
  5404. translateY: function () {
  5405. var v1 = new Vector3( 0, 1, 0 );
  5406. return function translateY( distance ) {
  5407. return this.translateOnAxis( v1, distance );
  5408. };
  5409. }(),
  5410. translateZ: function () {
  5411. var v1 = new Vector3( 0, 0, 1 );
  5412. return function translateZ( distance ) {
  5413. return this.translateOnAxis( v1, distance );
  5414. };
  5415. }(),
  5416. localToWorld: function ( vector ) {
  5417. return vector.applyMatrix4( this.matrixWorld );
  5418. },
  5419. worldToLocal: function () {
  5420. var m1 = new Matrix4();
  5421. return function worldToLocal( vector ) {
  5422. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5423. };
  5424. }(),
  5425. lookAt: function () {
  5426. // This method does not support objects with rotated and/or translated parent(s)
  5427. var m1 = new Matrix4();
  5428. var vector = new Vector3();
  5429. return function lookAt( x, y, z ) {
  5430. if ( x.isVector3 ) {
  5431. vector.copy( x );
  5432. } else {
  5433. vector.set( x, y, z );
  5434. }
  5435. if ( this.isCamera ) {
  5436. m1.lookAt( this.position, vector, this.up );
  5437. } else {
  5438. m1.lookAt( vector, this.position, this.up );
  5439. }
  5440. this.quaternion.setFromRotationMatrix( m1 );
  5441. };
  5442. }(),
  5443. add: function ( object ) {
  5444. if ( arguments.length > 1 ) {
  5445. for ( var i = 0; i < arguments.length; i ++ ) {
  5446. this.add( arguments[ i ] );
  5447. }
  5448. return this;
  5449. }
  5450. if ( object === this ) {
  5451. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5452. return this;
  5453. }
  5454. if ( ( object && object.isObject3D ) ) {
  5455. if ( object.parent !== null ) {
  5456. object.parent.remove( object );
  5457. }
  5458. object.parent = this;
  5459. object.dispatchEvent( { type: 'added' } );
  5460. this.children.push( object );
  5461. } else {
  5462. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5463. }
  5464. return this;
  5465. },
  5466. remove: function ( object ) {
  5467. if ( arguments.length > 1 ) {
  5468. for ( var i = 0; i < arguments.length; i ++ ) {
  5469. this.remove( arguments[ i ] );
  5470. }
  5471. return this;
  5472. }
  5473. var index = this.children.indexOf( object );
  5474. if ( index !== - 1 ) {
  5475. object.parent = null;
  5476. object.dispatchEvent( { type: 'removed' } );
  5477. this.children.splice( index, 1 );
  5478. }
  5479. return this;
  5480. },
  5481. getObjectById: function ( id ) {
  5482. return this.getObjectByProperty( 'id', id );
  5483. },
  5484. getObjectByName: function ( name ) {
  5485. return this.getObjectByProperty( 'name', name );
  5486. },
  5487. getObjectByProperty: function ( name, value ) {
  5488. if ( this[ name ] === value ) return this;
  5489. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5490. var child = this.children[ i ];
  5491. var object = child.getObjectByProperty( name, value );
  5492. if ( object !== undefined ) {
  5493. return object;
  5494. }
  5495. }
  5496. return undefined;
  5497. },
  5498. getWorldPosition: function ( optionalTarget ) {
  5499. var result = optionalTarget || new Vector3();
  5500. this.updateMatrixWorld( true );
  5501. return result.setFromMatrixPosition( this.matrixWorld );
  5502. },
  5503. getWorldQuaternion: function () {
  5504. var position = new Vector3();
  5505. var scale = new Vector3();
  5506. return function getWorldQuaternion( optionalTarget ) {
  5507. var result = optionalTarget || new Quaternion();
  5508. this.updateMatrixWorld( true );
  5509. this.matrixWorld.decompose( position, result, scale );
  5510. return result;
  5511. };
  5512. }(),
  5513. getWorldRotation: function () {
  5514. var quaternion = new Quaternion();
  5515. return function getWorldRotation( optionalTarget ) {
  5516. var result = optionalTarget || new Euler();
  5517. this.getWorldQuaternion( quaternion );
  5518. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5519. };
  5520. }(),
  5521. getWorldScale: function () {
  5522. var position = new Vector3();
  5523. var quaternion = new Quaternion();
  5524. return function getWorldScale( optionalTarget ) {
  5525. var result = optionalTarget || new Vector3();
  5526. this.updateMatrixWorld( true );
  5527. this.matrixWorld.decompose( position, quaternion, result );
  5528. return result;
  5529. };
  5530. }(),
  5531. getWorldDirection: function () {
  5532. var quaternion = new Quaternion();
  5533. return function getWorldDirection( optionalTarget ) {
  5534. var result = optionalTarget || new Vector3();
  5535. this.getWorldQuaternion( quaternion );
  5536. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5537. };
  5538. }(),
  5539. raycast: function () {},
  5540. traverse: function ( callback ) {
  5541. callback( this );
  5542. var children = this.children;
  5543. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5544. children[ i ].traverse( callback );
  5545. }
  5546. },
  5547. traverseVisible: function ( callback ) {
  5548. if ( this.visible === false ) return;
  5549. callback( this );
  5550. var children = this.children;
  5551. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5552. children[ i ].traverseVisible( callback );
  5553. }
  5554. },
  5555. traverseAncestors: function ( callback ) {
  5556. var parent = this.parent;
  5557. if ( parent !== null ) {
  5558. callback( parent );
  5559. parent.traverseAncestors( callback );
  5560. }
  5561. },
  5562. updateMatrix: function () {
  5563. this.matrix.compose( this.position, this.quaternion, this.scale );
  5564. this.matrixWorldNeedsUpdate = true;
  5565. },
  5566. updateMatrixWorld: function ( force ) {
  5567. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5568. if ( this.matrixWorldNeedsUpdate || force ) {
  5569. if ( this.parent === null ) {
  5570. this.matrixWorld.copy( this.matrix );
  5571. } else {
  5572. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5573. }
  5574. this.matrixWorldNeedsUpdate = false;
  5575. force = true;
  5576. }
  5577. // update children
  5578. var children = this.children;
  5579. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5580. children[ i ].updateMatrixWorld( force );
  5581. }
  5582. },
  5583. toJSON: function ( meta ) {
  5584. // meta is a string when called from JSON.stringify
  5585. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  5586. var output = {};
  5587. // meta is a hash used to collect geometries, materials.
  5588. // not providing it implies that this is the root object
  5589. // being serialized.
  5590. if ( isRootObject ) {
  5591. // initialize meta obj
  5592. meta = {
  5593. geometries: {},
  5594. materials: {},
  5595. textures: {},
  5596. images: {}
  5597. };
  5598. output.metadata = {
  5599. version: 4.5,
  5600. type: 'Object',
  5601. generator: 'Object3D.toJSON'
  5602. };
  5603. }
  5604. // standard Object3D serialization
  5605. var object = {};
  5606. object.uuid = this.uuid;
  5607. object.type = this.type;
  5608. if ( this.name !== '' ) object.name = this.name;
  5609. if ( this.castShadow === true ) object.castShadow = true;
  5610. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5611. if ( this.visible === false ) object.visible = false;
  5612. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5613. object.matrix = this.matrix.toArray();
  5614. //
  5615. function serialize( library, element ) {
  5616. if ( library[ element.uuid ] === undefined ) {
  5617. library[ element.uuid ] = element.toJSON( meta );
  5618. }
  5619. return element.uuid;
  5620. }
  5621. if ( this.geometry !== undefined ) {
  5622. object.geometry = serialize( meta.geometries, this.geometry );
  5623. }
  5624. if ( this.material !== undefined ) {
  5625. if ( Array.isArray( this.material ) ) {
  5626. var uuids = [];
  5627. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  5628. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  5629. }
  5630. object.material = uuids;
  5631. } else {
  5632. object.material = serialize( meta.materials, this.material );
  5633. }
  5634. }
  5635. //
  5636. if ( this.children.length > 0 ) {
  5637. object.children = [];
  5638. for ( var i = 0; i < this.children.length; i ++ ) {
  5639. object.children.push( this.children[ i ].toJSON( meta ).object );
  5640. }
  5641. }
  5642. if ( isRootObject ) {
  5643. var geometries = extractFromCache( meta.geometries );
  5644. var materials = extractFromCache( meta.materials );
  5645. var textures = extractFromCache( meta.textures );
  5646. var images = extractFromCache( meta.images );
  5647. if ( geometries.length > 0 ) output.geometries = geometries;
  5648. if ( materials.length > 0 ) output.materials = materials;
  5649. if ( textures.length > 0 ) output.textures = textures;
  5650. if ( images.length > 0 ) output.images = images;
  5651. }
  5652. output.object = object;
  5653. return output;
  5654. // extract data from the cache hash
  5655. // remove metadata on each item
  5656. // and return as array
  5657. function extractFromCache( cache ) {
  5658. var values = [];
  5659. for ( var key in cache ) {
  5660. var data = cache[ key ];
  5661. delete data.metadata;
  5662. values.push( data );
  5663. }
  5664. return values;
  5665. }
  5666. },
  5667. clone: function ( recursive ) {
  5668. return new this.constructor().copy( this, recursive );
  5669. },
  5670. copy: function ( source, recursive ) {
  5671. if ( recursive === undefined ) recursive = true;
  5672. this.name = source.name;
  5673. this.up.copy( source.up );
  5674. this.position.copy( source.position );
  5675. this.quaternion.copy( source.quaternion );
  5676. this.scale.copy( source.scale );
  5677. this.matrix.copy( source.matrix );
  5678. this.matrixWorld.copy( source.matrixWorld );
  5679. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5680. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5681. this.layers.mask = source.layers.mask;
  5682. this.visible = source.visible;
  5683. this.castShadow = source.castShadow;
  5684. this.receiveShadow = source.receiveShadow;
  5685. this.frustumCulled = source.frustumCulled;
  5686. this.renderOrder = source.renderOrder;
  5687. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5688. if ( recursive === true ) {
  5689. for ( var i = 0; i < source.children.length; i ++ ) {
  5690. var child = source.children[ i ];
  5691. this.add( child.clone() );
  5692. }
  5693. }
  5694. return this;
  5695. }
  5696. } );
  5697. /**
  5698. * @author tschw
  5699. * @author TristanVALCKE / https://github.com/Itee
  5700. */
  5701. /* global QUnit */
  5702. QUnit.module( "Animation", () => {
  5703. QUnit.module.todo( "AnimationObjectGroup", () => {
  5704. var ObjectA = new Object3D(),
  5705. ObjectB = new Object3D(),
  5706. ObjectC = new Object3D(),
  5707. PathA = 'object.position',
  5708. PathB = 'object.rotation',
  5709. PathC = 'object.scale',
  5710. ParsedPathA = PropertyBinding.parseTrackName( PathA ),
  5711. ParsedPathB = PropertyBinding.parseTrackName( PathB ),
  5712. ParsedPathC = PropertyBinding.parseTrackName( PathC );
  5713. // INSTANCING
  5714. QUnit.test( "Instancing", ( assert ) => {
  5715. assert.ok( false, "everything's gonna be alright" );
  5716. } );
  5717. // PRIVATE STUFF
  5718. QUnit.test( "subscribe_", ( assert ) => {
  5719. assert.ok( false, "everything's gonna be alright" );
  5720. } ); // Todo: Naming guys -_-'
  5721. QUnit.test( "unsubscribe_", ( assert ) => {
  5722. assert.ok( false, "everything's gonna be alright" );
  5723. } ); // Todo: Naming guys -_-'
  5724. // PUBLIC STUFF
  5725. QUnit.test( "isAnimationObjectGroup", ( assert ) => {
  5726. assert.ok( false, "everything's gonna be alright" );
  5727. } );
  5728. QUnit.test( "add", ( assert ) => {
  5729. assert.ok( false, "everything's gonna be alright" );
  5730. } );
  5731. QUnit.test( "remove", ( assert ) => {
  5732. assert.ok( false, "everything's gonna be alright" );
  5733. } );
  5734. QUnit.test( "uncache", ( assert ) => {
  5735. assert.ok( false, "everything's gonna be alright" );
  5736. } );
  5737. // OTHERS
  5738. QUnit.test( "smoke test", ( assert ) => {
  5739. var expect = function expect( testIndex, group, bindings, path, cached, roots ) {
  5740. var rootNodes = [], pathsOk = true, nodesOk = true;
  5741. for ( var i = group.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  5742. if ( bindings[ i ].path !== path ) pathsOk = false;
  5743. rootNodes.push( bindings[ i ].rootNode );
  5744. }
  5745. for ( var i = 0, n = roots.length; i !== n; ++ i ) {
  5746. if ( rootNodes.indexOf( roots[ i ] ) === - 1 ) nodesOk = false;
  5747. }
  5748. assert.ok( pathsOk, QUnit.testIndex + " paths" );
  5749. assert.ok( nodesOk, QUnit.testIndex + " nodes" );
  5750. assert.ok( group.nCachedObjects_ === cached, QUnit.testIndex + " cache size" );
  5751. assert.ok( bindings.length - group.nCachedObjects_ === roots.length, QUnit.testIndex + " object count" );
  5752. };
  5753. // initial state
  5754. var groupA = new AnimationObjectGroup();
  5755. assert.ok( groupA instanceof AnimationObjectGroup, "constructor (w/o args)" );
  5756. var bindingsAA = groupA.subscribe_( PathA, ParsedPathA );
  5757. expect( 0, groupA, bindingsAA, PathA, 0, [] );
  5758. var groupB = new AnimationObjectGroup( ObjectA, ObjectB );
  5759. assert.ok( groupB instanceof AnimationObjectGroup, "constructor (with args)" );
  5760. var bindingsBB = groupB.subscribe_( PathB, ParsedPathB );
  5761. expect( 1, groupB, bindingsBB, PathB, 0, [ ObjectA, ObjectB ] );
  5762. // add
  5763. groupA.add( ObjectA, ObjectB );
  5764. expect( 2, groupA, bindingsAA, PathA, 0, [ ObjectA, ObjectB ] );
  5765. groupB.add( ObjectC );
  5766. expect( 3, groupB, bindingsBB, PathB, 0, [ ObjectA, ObjectB, ObjectC ] );
  5767. // remove
  5768. groupA.remove( ObjectA, ObjectC );
  5769. expect( 4, groupA, bindingsAA, PathA, 1, [ ObjectB ] );
  5770. groupB.remove( ObjectA, ObjectB, ObjectC );
  5771. expect( 5, groupB, bindingsBB, PathB, 3, [] );
  5772. // subscribe after re-add
  5773. groupA.add( ObjectC );
  5774. expect( 6, groupA, bindingsAA, PathA, 1, [ ObjectB, ObjectC ] );
  5775. var bindingsAC = groupA.subscribe_( PathC, ParsedPathC );
  5776. expect( 7, groupA, bindingsAC, PathC, 1, [ ObjectB, ObjectC ] );
  5777. // re-add after subscribe
  5778. var bindingsBC = groupB.subscribe_( PathC, ParsedPathC );
  5779. groupB.add( ObjectA, ObjectB );
  5780. expect( 8, groupB, bindingsBB, PathB, 1, [ ObjectA, ObjectB ] );
  5781. // unsubscribe
  5782. var copyOfBindingsBC = bindingsBC.slice();
  5783. groupB.unsubscribe_( PathC );
  5784. groupB.add( ObjectC );
  5785. assert.deepEqual( bindingsBC, copyOfBindingsBC, "no more update after unsubscribe" );
  5786. // uncache active
  5787. groupB.uncache( ObjectA );
  5788. expect( 9, groupB, bindingsBB, PathB, 0, [ ObjectB, ObjectC ] );
  5789. // uncache cached
  5790. groupA.uncache( ObjectA );
  5791. expect( 10, groupA, bindingsAC, PathC, 0, [ ObjectB, ObjectC ] );
  5792. } );
  5793. } );
  5794. } );
  5795. /**
  5796. * @author TristanVALCKE / https://github.com/Itee
  5797. */
  5798. /* global QUnit */
  5799. QUnit.module( 'Animation', () => {
  5800. QUnit.module.todo( 'AnimationUtils', () => {
  5801. // PUBLIC STUFF
  5802. QUnit.test( "arraySlice", ( assert ) => {
  5803. assert.ok( false, "everything's gonna be alright" );
  5804. } );
  5805. QUnit.test( "convertArray", ( assert ) => {
  5806. assert.ok( false, "everything's gonna be alright" );
  5807. } );
  5808. QUnit.test( "isTypedArray", ( assert ) => {
  5809. assert.ok( false, "everything's gonna be alright" );
  5810. } );
  5811. QUnit.test( "getKeyframeOrder", ( assert ) => {
  5812. assert.ok( false, "everything's gonna be alright" );
  5813. } );
  5814. QUnit.test( "sortedArray", ( assert ) => {
  5815. assert.ok( false, "everything's gonna be alright" );
  5816. } );
  5817. QUnit.test( "flattenJSON", ( assert ) => {
  5818. assert.ok( false, "everything's gonna be alright" );
  5819. } );
  5820. } );
  5821. } );
  5822. /**
  5823. * @author TristanVALCKE / https://github.com/Itee
  5824. */
  5825. /* global QUnit */
  5826. QUnit.module( 'Animation', () => {
  5827. QUnit.module.todo( 'KeyframeTrack', () => {
  5828. // INSTANCING
  5829. QUnit.test( "Instancing", ( assert ) => {
  5830. assert.ok( false, "everything's gonna be alright" );
  5831. } );
  5832. // STATIC STUFF
  5833. QUnit.test( "parse", ( assert ) => {
  5834. assert.ok( false, "everything's gonna be alright" );
  5835. } );
  5836. QUnit.test( "toJSON", ( assert ) => {
  5837. assert.ok( false, "everything's gonna be alright" );
  5838. } );
  5839. QUnit.test( "_getTrackTypeForValueTypeName", ( assert ) => {
  5840. assert.ok( false, "everything's gonna be alright" );
  5841. } );
  5842. // PUBLIC STUFF
  5843. QUnit.test( "TimeBufferType", ( assert ) => {
  5844. assert.ok( false, "everything's gonna be alright" );
  5845. } );
  5846. QUnit.test( "ValueBufferType", ( assert ) => {
  5847. assert.ok( false, "everything's gonna be alright" );
  5848. } );
  5849. QUnit.test( "DefaultInterpolation", ( assert ) => {
  5850. assert.ok( false, "everything's gonna be alright" );
  5851. } );
  5852. QUnit.test( "InterpolantFactoryMethodDiscrete", ( assert ) => {
  5853. assert.ok( false, "everything's gonna be alright" );
  5854. } );
  5855. QUnit.test( "InterpolantFactoryMethodLinear", ( assert ) => {
  5856. assert.ok( false, "everything's gonna be alright" );
  5857. } );
  5858. QUnit.test( "InterpolantFactoryMethodSmooth", ( assert ) => {
  5859. assert.ok( false, "everything's gonna be alright" );
  5860. } );
  5861. QUnit.test( "setInterpolation", ( assert ) => {
  5862. assert.ok( false, "everything's gonna be alright" );
  5863. } );
  5864. QUnit.test( "getInterpolation", ( assert ) => {
  5865. assert.ok( false, "everything's gonna be alright" );
  5866. } );
  5867. QUnit.test( "getValueSize", ( assert ) => {
  5868. assert.ok( false, "everything's gonna be alright" );
  5869. } );
  5870. QUnit.test( "shift", ( assert ) => {
  5871. assert.ok( false, "everything's gonna be alright" );
  5872. } );
  5873. QUnit.test( "scale", ( assert ) => {
  5874. assert.ok( false, "everything's gonna be alright" );
  5875. } );
  5876. QUnit.test( "trim", ( assert ) => {
  5877. assert.ok( false, "everything's gonna be alright" );
  5878. } );
  5879. QUnit.test( "validate", ( assert ) => {
  5880. assert.ok( false, "everything's gonna be alright" );
  5881. } );
  5882. QUnit.test( "optimize", ( assert ) => {
  5883. assert.ok( false, "everything's gonna be alright" );
  5884. } );
  5885. } );
  5886. } );
  5887. /**
  5888. * @author mrdoob / http://mrdoob.com/
  5889. */
  5890. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  5891. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  5892. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  5893. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  5894. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  5895. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  5896. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  5897. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  5898. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  5899. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  5900. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  5901. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  5902. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  5903. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  5904. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  5905. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  5906. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  5907. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  5908. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  5909. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  5910. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  5911. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  5912. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  5913. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  5914. function Color( r, g, b ) {
  5915. if ( g === undefined && b === undefined ) {
  5916. // r is THREE.Color, hex or string
  5917. return this.set( r );
  5918. }
  5919. return this.setRGB( r, g, b );
  5920. }
  5921. Object.assign( Color.prototype, {
  5922. isColor: true,
  5923. r: 1, g: 1, b: 1,
  5924. set: function ( value ) {
  5925. if ( value && value.isColor ) {
  5926. this.copy( value );
  5927. } else if ( typeof value === 'number' ) {
  5928. this.setHex( value );
  5929. } else if ( typeof value === 'string' ) {
  5930. this.setStyle( value );
  5931. }
  5932. return this;
  5933. },
  5934. setScalar: function ( scalar ) {
  5935. this.r = scalar;
  5936. this.g = scalar;
  5937. this.b = scalar;
  5938. return this;
  5939. },
  5940. setHex: function ( hex ) {
  5941. hex = Math.floor( hex );
  5942. this.r = ( hex >> 16 & 255 ) / 255;
  5943. this.g = ( hex >> 8 & 255 ) / 255;
  5944. this.b = ( hex & 255 ) / 255;
  5945. return this;
  5946. },
  5947. setRGB: function ( r, g, b ) {
  5948. this.r = r;
  5949. this.g = g;
  5950. this.b = b;
  5951. return this;
  5952. },
  5953. setHSL: function () {
  5954. function hue2rgb( p, q, t ) {
  5955. if ( t < 0 ) t += 1;
  5956. if ( t > 1 ) t -= 1;
  5957. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  5958. if ( t < 1 / 2 ) return q;
  5959. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  5960. return p;
  5961. }
  5962. return function setHSL( h, s, l ) {
  5963. // h,s,l ranges are in 0.0 - 1.0
  5964. h = _Math.euclideanModulo( h, 1 );
  5965. s = _Math.clamp( s, 0, 1 );
  5966. l = _Math.clamp( l, 0, 1 );
  5967. if ( s === 0 ) {
  5968. this.r = this.g = this.b = l;
  5969. } else {
  5970. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  5971. var q = ( 2 * l ) - p;
  5972. this.r = hue2rgb( q, p, h + 1 / 3 );
  5973. this.g = hue2rgb( q, p, h );
  5974. this.b = hue2rgb( q, p, h - 1 / 3 );
  5975. }
  5976. return this;
  5977. };
  5978. }(),
  5979. setStyle: function ( style ) {
  5980. function handleAlpha( string ) {
  5981. if ( string === undefined ) return;
  5982. if ( parseFloat( string ) < 1 ) {
  5983. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  5984. }
  5985. }
  5986. var m;
  5987. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  5988. // rgb / hsl
  5989. var color;
  5990. var name = m[ 1 ];
  5991. var components = m[ 2 ];
  5992. switch ( name ) {
  5993. case 'rgb':
  5994. case 'rgba':
  5995. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  5996. // rgb(255,0,0) rgba(255,0,0,0.5)
  5997. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  5998. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  5999. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  6000. handleAlpha( color[ 5 ] );
  6001. return this;
  6002. }
  6003. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  6004. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  6005. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  6006. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  6007. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  6008. handleAlpha( color[ 5 ] );
  6009. return this;
  6010. }
  6011. break;
  6012. case 'hsl':
  6013. case 'hsla':
  6014. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  6015. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  6016. var h = parseFloat( color[ 1 ] ) / 360;
  6017. var s = parseInt( color[ 2 ], 10 ) / 100;
  6018. var l = parseInt( color[ 3 ], 10 ) / 100;
  6019. handleAlpha( color[ 5 ] );
  6020. return this.setHSL( h, s, l );
  6021. }
  6022. break;
  6023. }
  6024. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  6025. // hex color
  6026. var hex = m[ 1 ];
  6027. var size = hex.length;
  6028. if ( size === 3 ) {
  6029. // #ff0
  6030. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  6031. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  6032. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  6033. return this;
  6034. } else if ( size === 6 ) {
  6035. // #ff0000
  6036. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  6037. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  6038. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  6039. return this;
  6040. }
  6041. }
  6042. if ( style && style.length > 0 ) {
  6043. // color keywords
  6044. var hex = ColorKeywords[ style ];
  6045. if ( hex !== undefined ) {
  6046. // red
  6047. this.setHex( hex );
  6048. } else {
  6049. // unknown color
  6050. console.warn( 'THREE.Color: Unknown color ' + style );
  6051. }
  6052. }
  6053. return this;
  6054. },
  6055. clone: function () {
  6056. return new this.constructor( this.r, this.g, this.b );
  6057. },
  6058. copy: function ( color ) {
  6059. this.r = color.r;
  6060. this.g = color.g;
  6061. this.b = color.b;
  6062. return this;
  6063. },
  6064. copyGammaToLinear: function ( color, gammaFactor ) {
  6065. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  6066. this.r = Math.pow( color.r, gammaFactor );
  6067. this.g = Math.pow( color.g, gammaFactor );
  6068. this.b = Math.pow( color.b, gammaFactor );
  6069. return this;
  6070. },
  6071. copyLinearToGamma: function ( color, gammaFactor ) {
  6072. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  6073. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  6074. this.r = Math.pow( color.r, safeInverse );
  6075. this.g = Math.pow( color.g, safeInverse );
  6076. this.b = Math.pow( color.b, safeInverse );
  6077. return this;
  6078. },
  6079. convertGammaToLinear: function () {
  6080. var r = this.r, g = this.g, b = this.b;
  6081. this.r = r * r;
  6082. this.g = g * g;
  6083. this.b = b * b;
  6084. return this;
  6085. },
  6086. convertLinearToGamma: function () {
  6087. this.r = Math.sqrt( this.r );
  6088. this.g = Math.sqrt( this.g );
  6089. this.b = Math.sqrt( this.b );
  6090. return this;
  6091. },
  6092. getHex: function () {
  6093. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  6094. },
  6095. getHexString: function () {
  6096. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  6097. },
  6098. getHSL: function ( optionalTarget ) {
  6099. // h,s,l ranges are in 0.0 - 1.0
  6100. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  6101. var r = this.r, g = this.g, b = this.b;
  6102. var max = Math.max( r, g, b );
  6103. var min = Math.min( r, g, b );
  6104. var hue, saturation;
  6105. var lightness = ( min + max ) / 2.0;
  6106. if ( min === max ) {
  6107. hue = 0;
  6108. saturation = 0;
  6109. } else {
  6110. var delta = max - min;
  6111. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  6112. switch ( max ) {
  6113. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  6114. case g: hue = ( b - r ) / delta + 2; break;
  6115. case b: hue = ( r - g ) / delta + 4; break;
  6116. }
  6117. hue /= 6;
  6118. }
  6119. hsl.h = hue;
  6120. hsl.s = saturation;
  6121. hsl.l = lightness;
  6122. return hsl;
  6123. },
  6124. getStyle: function () {
  6125. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  6126. },
  6127. offsetHSL: function ( h, s, l ) {
  6128. var hsl = this.getHSL();
  6129. hsl.h += h; hsl.s += s; hsl.l += l;
  6130. this.setHSL( hsl.h, hsl.s, hsl.l );
  6131. return this;
  6132. },
  6133. add: function ( color ) {
  6134. this.r += color.r;
  6135. this.g += color.g;
  6136. this.b += color.b;
  6137. return this;
  6138. },
  6139. addColors: function ( color1, color2 ) {
  6140. this.r = color1.r + color2.r;
  6141. this.g = color1.g + color2.g;
  6142. this.b = color1.b + color2.b;
  6143. return this;
  6144. },
  6145. addScalar: function ( s ) {
  6146. this.r += s;
  6147. this.g += s;
  6148. this.b += s;
  6149. return this;
  6150. },
  6151. sub: function ( color ) {
  6152. this.r = Math.max( 0, this.r - color.r );
  6153. this.g = Math.max( 0, this.g - color.g );
  6154. this.b = Math.max( 0, this.b - color.b );
  6155. return this;
  6156. },
  6157. multiply: function ( color ) {
  6158. this.r *= color.r;
  6159. this.g *= color.g;
  6160. this.b *= color.b;
  6161. return this;
  6162. },
  6163. multiplyScalar: function ( s ) {
  6164. this.r *= s;
  6165. this.g *= s;
  6166. this.b *= s;
  6167. return this;
  6168. },
  6169. lerp: function ( color, alpha ) {
  6170. this.r += ( color.r - this.r ) * alpha;
  6171. this.g += ( color.g - this.g ) * alpha;
  6172. this.b += ( color.b - this.b ) * alpha;
  6173. return this;
  6174. },
  6175. equals: function ( c ) {
  6176. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  6177. },
  6178. fromArray: function ( array, offset ) {
  6179. if ( offset === undefined ) offset = 0;
  6180. this.r = array[ offset ];
  6181. this.g = array[ offset + 1 ];
  6182. this.b = array[ offset + 2 ];
  6183. return this;
  6184. },
  6185. toArray: function ( array, offset ) {
  6186. if ( array === undefined ) array = [];
  6187. if ( offset === undefined ) offset = 0;
  6188. array[ offset ] = this.r;
  6189. array[ offset + 1 ] = this.g;
  6190. array[ offset + 2 ] = this.b;
  6191. return array;
  6192. },
  6193. toJSON: function () {
  6194. return this.getHex();
  6195. }
  6196. } );
  6197. /**
  6198. * @author mrdoob / http://mrdoob.com/
  6199. * @author alteredq / http://alteredqualia.com/
  6200. */
  6201. function Face3( a, b, c, normal, color, materialIndex ) {
  6202. this.a = a;
  6203. this.b = b;
  6204. this.c = c;
  6205. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  6206. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  6207. this.color = ( color && color.isColor ) ? color : new Color();
  6208. this.vertexColors = Array.isArray( color ) ? color : [];
  6209. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  6210. }
  6211. Object.assign( Face3.prototype, {
  6212. clone: function () {
  6213. return new this.constructor().copy( this );
  6214. },
  6215. copy: function ( source ) {
  6216. this.a = source.a;
  6217. this.b = source.b;
  6218. this.c = source.c;
  6219. this.normal.copy( source.normal );
  6220. this.color.copy( source.color );
  6221. this.materialIndex = source.materialIndex;
  6222. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  6223. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  6224. }
  6225. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  6226. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  6227. }
  6228. return this;
  6229. }
  6230. } );
  6231. /**
  6232. * @author bhouston / http://clara.io
  6233. * @author WestLangley / http://github.com/WestLangley
  6234. */
  6235. function Box3( min, max ) {
  6236. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  6237. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  6238. }
  6239. Object.assign( Box3.prototype, {
  6240. isBox3: true,
  6241. set: function ( min, max ) {
  6242. this.min.copy( min );
  6243. this.max.copy( max );
  6244. return this;
  6245. },
  6246. setFromArray: function ( array ) {
  6247. var minX = + Infinity;
  6248. var minY = + Infinity;
  6249. var minZ = + Infinity;
  6250. var maxX = - Infinity;
  6251. var maxY = - Infinity;
  6252. var maxZ = - Infinity;
  6253. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  6254. var x = array[ i ];
  6255. var y = array[ i + 1 ];
  6256. var z = array[ i + 2 ];
  6257. if ( x < minX ) minX = x;
  6258. if ( y < minY ) minY = y;
  6259. if ( z < minZ ) minZ = z;
  6260. if ( x > maxX ) maxX = x;
  6261. if ( y > maxY ) maxY = y;
  6262. if ( z > maxZ ) maxZ = z;
  6263. }
  6264. this.min.set( minX, minY, minZ );
  6265. this.max.set( maxX, maxY, maxZ );
  6266. return this;
  6267. },
  6268. setFromBufferAttribute: function ( attribute ) {
  6269. var minX = + Infinity;
  6270. var minY = + Infinity;
  6271. var minZ = + Infinity;
  6272. var maxX = - Infinity;
  6273. var maxY = - Infinity;
  6274. var maxZ = - Infinity;
  6275. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  6276. var x = attribute.getX( i );
  6277. var y = attribute.getY( i );
  6278. var z = attribute.getZ( i );
  6279. if ( x < minX ) minX = x;
  6280. if ( y < minY ) minY = y;
  6281. if ( z < minZ ) minZ = z;
  6282. if ( x > maxX ) maxX = x;
  6283. if ( y > maxY ) maxY = y;
  6284. if ( z > maxZ ) maxZ = z;
  6285. }
  6286. this.min.set( minX, minY, minZ );
  6287. this.max.set( maxX, maxY, maxZ );
  6288. return this;
  6289. },
  6290. setFromPoints: function ( points ) {
  6291. this.makeEmpty();
  6292. for ( var i = 0, il = points.length; i < il; i ++ ) {
  6293. this.expandByPoint( points[ i ] );
  6294. }
  6295. return this;
  6296. },
  6297. setFromCenterAndSize: function () {
  6298. var v1 = new Vector3();
  6299. return function setFromCenterAndSize( center, size ) {
  6300. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  6301. this.min.copy( center ).sub( halfSize );
  6302. this.max.copy( center ).add( halfSize );
  6303. return this;
  6304. };
  6305. }(),
  6306. setFromObject: function ( object ) {
  6307. this.makeEmpty();
  6308. return this.expandByObject( object );
  6309. },
  6310. clone: function () {
  6311. return new this.constructor().copy( this );
  6312. },
  6313. copy: function ( box ) {
  6314. this.min.copy( box.min );
  6315. this.max.copy( box.max );
  6316. return this;
  6317. },
  6318. makeEmpty: function () {
  6319. this.min.x = this.min.y = this.min.z = + Infinity;
  6320. this.max.x = this.max.y = this.max.z = - Infinity;
  6321. return this;
  6322. },
  6323. isEmpty: function () {
  6324. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  6325. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  6326. },
  6327. getCenter: function ( optionalTarget ) {
  6328. var result = optionalTarget || new Vector3();
  6329. return this.isEmpty() ? result.set( 0, 0, 0 ) : result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  6330. },
  6331. getSize: function ( optionalTarget ) {
  6332. var result = optionalTarget || new Vector3();
  6333. return this.isEmpty() ? result.set( 0, 0, 0 ) : result.subVectors( this.max, this.min );
  6334. },
  6335. expandByPoint: function ( point ) {
  6336. this.min.min( point );
  6337. this.max.max( point );
  6338. return this;
  6339. },
  6340. expandByVector: function ( vector ) {
  6341. this.min.sub( vector );
  6342. this.max.add( vector );
  6343. return this;
  6344. },
  6345. expandByScalar: function ( scalar ) {
  6346. this.min.addScalar( - scalar );
  6347. this.max.addScalar( scalar );
  6348. return this;
  6349. },
  6350. expandByObject: function () {
  6351. // Computes the world-axis-aligned bounding box of an object (including its children),
  6352. // accounting for both the object's, and children's, world transforms
  6353. var scope, i, l;
  6354. var v1 = new Vector3();
  6355. function traverse( node ) {
  6356. var geometry = node.geometry;
  6357. if ( geometry !== undefined ) {
  6358. if ( geometry.isGeometry ) {
  6359. var vertices = geometry.vertices;
  6360. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  6361. v1.copy( vertices[ i ] );
  6362. v1.applyMatrix4( node.matrixWorld );
  6363. scope.expandByPoint( v1 );
  6364. }
  6365. } else if ( geometry.isBufferGeometry ) {
  6366. var attribute = geometry.attributes.position;
  6367. if ( attribute !== undefined ) {
  6368. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  6369. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  6370. scope.expandByPoint( v1 );
  6371. }
  6372. }
  6373. }
  6374. }
  6375. }
  6376. return function expandByObject( object ) {
  6377. scope = this;
  6378. object.updateMatrixWorld( true );
  6379. object.traverse( traverse );
  6380. return this;
  6381. };
  6382. }(),
  6383. containsPoint: function ( point ) {
  6384. return point.x < this.min.x || point.x > this.max.x ||
  6385. point.y < this.min.y || point.y > this.max.y ||
  6386. point.z < this.min.z || point.z > this.max.z ? false : true;
  6387. },
  6388. containsBox: function ( box ) {
  6389. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  6390. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  6391. this.min.z <= box.min.z && box.max.z <= this.max.z;
  6392. },
  6393. getParameter: function ( point, optionalTarget ) {
  6394. // This can potentially have a divide by zero if the box
  6395. // has a size dimension of 0.
  6396. var result = optionalTarget || new Vector3();
  6397. return result.set(
  6398. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  6399. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  6400. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  6401. );
  6402. },
  6403. intersectsBox: function ( box ) {
  6404. // using 6 splitting planes to rule out intersections.
  6405. return box.max.x < this.min.x || box.min.x > this.max.x ||
  6406. box.max.y < this.min.y || box.min.y > this.max.y ||
  6407. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  6408. },
  6409. intersectsSphere: ( function () {
  6410. var closestPoint = new Vector3();
  6411. return function intersectsSphere( sphere ) {
  6412. // Find the point on the AABB closest to the sphere center.
  6413. this.clampPoint( sphere.center, closestPoint );
  6414. // If that point is inside the sphere, the AABB and sphere intersect.
  6415. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  6416. };
  6417. } )(),
  6418. intersectsPlane: function ( plane ) {
  6419. // We compute the minimum and maximum dot product values. If those values
  6420. // are on the same side (back or front) of the plane, then there is no intersection.
  6421. var min, max;
  6422. if ( plane.normal.x > 0 ) {
  6423. min = plane.normal.x * this.min.x;
  6424. max = plane.normal.x * this.max.x;
  6425. } else {
  6426. min = plane.normal.x * this.max.x;
  6427. max = plane.normal.x * this.min.x;
  6428. }
  6429. if ( plane.normal.y > 0 ) {
  6430. min += plane.normal.y * this.min.y;
  6431. max += plane.normal.y * this.max.y;
  6432. } else {
  6433. min += plane.normal.y * this.max.y;
  6434. max += plane.normal.y * this.min.y;
  6435. }
  6436. if ( plane.normal.z > 0 ) {
  6437. min += plane.normal.z * this.min.z;
  6438. max += plane.normal.z * this.max.z;
  6439. } else {
  6440. min += plane.normal.z * this.max.z;
  6441. max += plane.normal.z * this.min.z;
  6442. }
  6443. return ( min <= plane.constant && max >= plane.constant );
  6444. },
  6445. clampPoint: function ( point, optionalTarget ) {
  6446. var result = optionalTarget || new Vector3();
  6447. return result.copy( point ).clamp( this.min, this.max );
  6448. },
  6449. distanceToPoint: function () {
  6450. var v1 = new Vector3();
  6451. return function distanceToPoint( point ) {
  6452. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  6453. return clampedPoint.sub( point ).length();
  6454. };
  6455. }(),
  6456. getBoundingSphere: function () {
  6457. var v1 = new Vector3();
  6458. return function getBoundingSphere( optionalTarget ) {
  6459. var result = optionalTarget || new Sphere();
  6460. this.getCenter( result.center );
  6461. result.radius = this.getSize( v1 ).length() * 0.5;
  6462. return result;
  6463. };
  6464. }(),
  6465. intersect: function ( box ) {
  6466. this.min.max( box.min );
  6467. this.max.min( box.max );
  6468. // 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.
  6469. if ( this.isEmpty() ) this.makeEmpty();
  6470. return this;
  6471. },
  6472. union: function ( box ) {
  6473. this.min.min( box.min );
  6474. this.max.max( box.max );
  6475. return this;
  6476. },
  6477. applyMatrix4: function () {
  6478. var points = [
  6479. new Vector3(),
  6480. new Vector3(),
  6481. new Vector3(),
  6482. new Vector3(),
  6483. new Vector3(),
  6484. new Vector3(),
  6485. new Vector3(),
  6486. new Vector3()
  6487. ];
  6488. return function applyMatrix4( matrix ) {
  6489. // transform of empty box is an empty box.
  6490. if ( this.isEmpty() ) return this;
  6491. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  6492. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  6493. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  6494. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  6495. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  6496. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  6497. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  6498. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  6499. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  6500. this.setFromPoints( points );
  6501. return this;
  6502. };
  6503. }(),
  6504. translate: function ( offset ) {
  6505. this.min.add( offset );
  6506. this.max.add( offset );
  6507. return this;
  6508. },
  6509. equals: function ( box ) {
  6510. return box.min.equals( this.min ) && box.max.equals( this.max );
  6511. }
  6512. } );
  6513. /**
  6514. * @author bhouston / http://clara.io
  6515. * @author mrdoob / http://mrdoob.com/
  6516. */
  6517. function Sphere( center, radius ) {
  6518. this.center = ( center !== undefined ) ? center : new Vector3();
  6519. this.radius = ( radius !== undefined ) ? radius : 0;
  6520. }
  6521. Object.assign( Sphere.prototype, {
  6522. set: function ( center, radius ) {
  6523. this.center.copy( center );
  6524. this.radius = radius;
  6525. return this;
  6526. },
  6527. setFromPoints: function () {
  6528. var box = new Box3();
  6529. return function setFromPoints( points, optionalCenter ) {
  6530. var center = this.center;
  6531. if ( optionalCenter !== undefined ) {
  6532. center.copy( optionalCenter );
  6533. } else {
  6534. box.setFromPoints( points ).getCenter( center );
  6535. }
  6536. var maxRadiusSq = 0;
  6537. for ( var i = 0, il = points.length; i < il; i ++ ) {
  6538. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  6539. }
  6540. this.radius = Math.sqrt( maxRadiusSq );
  6541. return this;
  6542. };
  6543. }(),
  6544. clone: function () {
  6545. return new this.constructor().copy( this );
  6546. },
  6547. copy: function ( sphere ) {
  6548. this.center.copy( sphere.center );
  6549. this.radius = sphere.radius;
  6550. return this;
  6551. },
  6552. empty: function () {
  6553. return ( this.radius <= 0 );
  6554. },
  6555. containsPoint: function ( point ) {
  6556. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  6557. },
  6558. distanceToPoint: function ( point ) {
  6559. return ( point.distanceTo( this.center ) - this.radius );
  6560. },
  6561. intersectsSphere: function ( sphere ) {
  6562. var radiusSum = this.radius + sphere.radius;
  6563. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  6564. },
  6565. intersectsBox: function ( box ) {
  6566. return box.intersectsSphere( this );
  6567. },
  6568. intersectsPlane: function ( plane ) {
  6569. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  6570. },
  6571. clampPoint: function ( point, optionalTarget ) {
  6572. var deltaLengthSq = this.center.distanceToSquared( point );
  6573. var result = optionalTarget || new Vector3();
  6574. result.copy( point );
  6575. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  6576. result.sub( this.center ).normalize();
  6577. result.multiplyScalar( this.radius ).add( this.center );
  6578. }
  6579. return result;
  6580. },
  6581. getBoundingBox: function ( optionalTarget ) {
  6582. var box = optionalTarget || new Box3();
  6583. box.set( this.center, this.center );
  6584. box.expandByScalar( this.radius );
  6585. return box;
  6586. },
  6587. applyMatrix4: function ( matrix ) {
  6588. this.center.applyMatrix4( matrix );
  6589. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  6590. return this;
  6591. },
  6592. translate: function ( offset ) {
  6593. this.center.add( offset );
  6594. return this;
  6595. },
  6596. equals: function ( sphere ) {
  6597. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  6598. }
  6599. } );
  6600. /**
  6601. * @author mrdoob / http://mrdoob.com/
  6602. * @author philogb / http://blog.thejit.org/
  6603. * @author egraether / http://egraether.com/
  6604. * @author zz85 / http://www.lab4games.net/zz85/blog
  6605. */
  6606. function Vector2( x, y ) {
  6607. this.x = x || 0;
  6608. this.y = y || 0;
  6609. }
  6610. Object.defineProperties( Vector2.prototype, {
  6611. "width": {
  6612. get: function () {
  6613. return this.x;
  6614. },
  6615. set: function ( value ) {
  6616. this.x = value;
  6617. }
  6618. },
  6619. "height": {
  6620. get: function () {
  6621. return this.y;
  6622. },
  6623. set: function ( value ) {
  6624. this.y = value;
  6625. }
  6626. }
  6627. } );
  6628. Object.assign( Vector2.prototype, {
  6629. isVector2: true,
  6630. set: function ( x, y ) {
  6631. this.x = x;
  6632. this.y = y;
  6633. return this;
  6634. },
  6635. setScalar: function ( scalar ) {
  6636. this.x = scalar;
  6637. this.y = scalar;
  6638. return this;
  6639. },
  6640. setX: function ( x ) {
  6641. this.x = x;
  6642. return this;
  6643. },
  6644. setY: function ( y ) {
  6645. this.y = y;
  6646. return this;
  6647. },
  6648. setComponent: function ( index, value ) {
  6649. switch ( index ) {
  6650. case 0: this.x = value; break;
  6651. case 1: this.y = value; break;
  6652. default: throw new Error( 'index is out of range: ' + index );
  6653. }
  6654. return this;
  6655. },
  6656. getComponent: function ( index ) {
  6657. switch ( index ) {
  6658. case 0: return this.x;
  6659. case 1: return this.y;
  6660. default: throw new Error( 'index is out of range: ' + index );
  6661. }
  6662. },
  6663. clone: function () {
  6664. return new this.constructor( this.x, this.y );
  6665. },
  6666. copy: function ( v ) {
  6667. this.x = v.x;
  6668. this.y = v.y;
  6669. return this;
  6670. },
  6671. add: function ( v, w ) {
  6672. if ( w !== undefined ) {
  6673. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  6674. return this.addVectors( v, w );
  6675. }
  6676. this.x += v.x;
  6677. this.y += v.y;
  6678. return this;
  6679. },
  6680. addScalar: function ( s ) {
  6681. this.x += s;
  6682. this.y += s;
  6683. return this;
  6684. },
  6685. addVectors: function ( a, b ) {
  6686. this.x = a.x + b.x;
  6687. this.y = a.y + b.y;
  6688. return this;
  6689. },
  6690. addScaledVector: function ( v, s ) {
  6691. this.x += v.x * s;
  6692. this.y += v.y * s;
  6693. return this;
  6694. },
  6695. sub: function ( v, w ) {
  6696. if ( w !== undefined ) {
  6697. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  6698. return this.subVectors( v, w );
  6699. }
  6700. this.x -= v.x;
  6701. this.y -= v.y;
  6702. return this;
  6703. },
  6704. subScalar: function ( s ) {
  6705. this.x -= s;
  6706. this.y -= s;
  6707. return this;
  6708. },
  6709. subVectors: function ( a, b ) {
  6710. this.x = a.x - b.x;
  6711. this.y = a.y - b.y;
  6712. return this;
  6713. },
  6714. multiply: function ( v ) {
  6715. this.x *= v.x;
  6716. this.y *= v.y;
  6717. return this;
  6718. },
  6719. multiplyScalar: function ( scalar ) {
  6720. this.x *= scalar;
  6721. this.y *= scalar;
  6722. return this;
  6723. },
  6724. divide: function ( v ) {
  6725. this.x /= v.x;
  6726. this.y /= v.y;
  6727. return this;
  6728. },
  6729. divideScalar: function ( scalar ) {
  6730. return this.multiplyScalar( 1 / scalar );
  6731. },
  6732. applyMatrix3: function ( m ) {
  6733. var x = this.x, y = this.y;
  6734. var e = m.elements;
  6735. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  6736. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  6737. return this;
  6738. },
  6739. min: function ( v ) {
  6740. this.x = Math.min( this.x, v.x );
  6741. this.y = Math.min( this.y, v.y );
  6742. return this;
  6743. },
  6744. max: function ( v ) {
  6745. this.x = Math.max( this.x, v.x );
  6746. this.y = Math.max( this.y, v.y );
  6747. return this;
  6748. },
  6749. clamp: function ( min, max ) {
  6750. // assumes min < max, componentwise
  6751. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  6752. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  6753. return this;
  6754. },
  6755. clampScalar: function () {
  6756. var min = new Vector2();
  6757. var max = new Vector2();
  6758. return function clampScalar( minVal, maxVal ) {
  6759. min.set( minVal, minVal );
  6760. max.set( maxVal, maxVal );
  6761. return this.clamp( min, max );
  6762. };
  6763. }(),
  6764. clampLength: function ( min, max ) {
  6765. var length = this.length();
  6766. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  6767. },
  6768. floor: function () {
  6769. this.x = Math.floor( this.x );
  6770. this.y = Math.floor( this.y );
  6771. return this;
  6772. },
  6773. ceil: function () {
  6774. this.x = Math.ceil( this.x );
  6775. this.y = Math.ceil( this.y );
  6776. return this;
  6777. },
  6778. round: function () {
  6779. this.x = Math.round( this.x );
  6780. this.y = Math.round( this.y );
  6781. return this;
  6782. },
  6783. roundToZero: function () {
  6784. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  6785. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  6786. return this;
  6787. },
  6788. negate: function () {
  6789. this.x = - this.x;
  6790. this.y = - this.y;
  6791. return this;
  6792. },
  6793. dot: function ( v ) {
  6794. return this.x * v.x + this.y * v.y;
  6795. },
  6796. lengthSq: function () {
  6797. return this.x * this.x + this.y * this.y;
  6798. },
  6799. length: function () {
  6800. return Math.sqrt( this.x * this.x + this.y * this.y );
  6801. },
  6802. manhattanLength: function () {
  6803. return Math.abs( this.x ) + Math.abs( this.y );
  6804. },
  6805. normalize: function () {
  6806. return this.divideScalar( this.length() || 1 );
  6807. },
  6808. angle: function () {
  6809. // computes the angle in radians with respect to the positive x-axis
  6810. var angle = Math.atan2( this.y, this.x );
  6811. if ( angle < 0 ) angle += 2 * Math.PI;
  6812. return angle;
  6813. },
  6814. distanceTo: function ( v ) {
  6815. return Math.sqrt( this.distanceToSquared( v ) );
  6816. },
  6817. distanceToSquared: function ( v ) {
  6818. var dx = this.x - v.x, dy = this.y - v.y;
  6819. return dx * dx + dy * dy;
  6820. },
  6821. manhattanDistanceTo: function ( v ) {
  6822. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  6823. },
  6824. setLength: function ( length ) {
  6825. return this.normalize().multiplyScalar( length );
  6826. },
  6827. lerp: function ( v, alpha ) {
  6828. this.x += ( v.x - this.x ) * alpha;
  6829. this.y += ( v.y - this.y ) * alpha;
  6830. return this;
  6831. },
  6832. lerpVectors: function ( v1, v2, alpha ) {
  6833. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  6834. },
  6835. equals: function ( v ) {
  6836. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  6837. },
  6838. fromArray: function ( array, offset ) {
  6839. if ( offset === undefined ) offset = 0;
  6840. this.x = array[ offset ];
  6841. this.y = array[ offset + 1 ];
  6842. return this;
  6843. },
  6844. toArray: function ( array, offset ) {
  6845. if ( array === undefined ) array = [];
  6846. if ( offset === undefined ) offset = 0;
  6847. array[ offset ] = this.x;
  6848. array[ offset + 1 ] = this.y;
  6849. return array;
  6850. },
  6851. fromBufferAttribute: function ( attribute, index, offset ) {
  6852. if ( offset !== undefined ) {
  6853. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  6854. }
  6855. this.x = attribute.getX( index );
  6856. this.y = attribute.getY( index );
  6857. return this;
  6858. },
  6859. rotateAround: function ( center, angle ) {
  6860. var c = Math.cos( angle ), s = Math.sin( angle );
  6861. var x = this.x - center.x;
  6862. var y = this.y - center.y;
  6863. this.x = x * c - y * s + center.x;
  6864. this.y = x * s + y * c + center.y;
  6865. return this;
  6866. }
  6867. } );
  6868. /**
  6869. * @author mrdoob / http://mrdoob.com/
  6870. * @author kile / http://kile.stravaganza.org/
  6871. * @author alteredq / http://alteredqualia.com/
  6872. * @author mikael emtinger / http://gomo.se/
  6873. * @author zz85 / http://www.lab4games.net/zz85/blog
  6874. * @author bhouston / http://clara.io
  6875. */
  6876. var geometryId = 0; // Geometry uses even numbers as Id
  6877. function Geometry() {
  6878. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  6879. this.uuid = _Math.generateUUID();
  6880. this.name = '';
  6881. this.type = 'Geometry';
  6882. this.vertices = [];
  6883. this.colors = [];
  6884. this.faces = [];
  6885. this.faceVertexUvs = [[]];
  6886. this.morphTargets = [];
  6887. this.morphNormals = [];
  6888. this.skinWeights = [];
  6889. this.skinIndices = [];
  6890. this.lineDistances = [];
  6891. this.boundingBox = null;
  6892. this.boundingSphere = null;
  6893. // update flags
  6894. this.elementsNeedUpdate = false;
  6895. this.verticesNeedUpdate = false;
  6896. this.uvsNeedUpdate = false;
  6897. this.normalsNeedUpdate = false;
  6898. this.colorsNeedUpdate = false;
  6899. this.lineDistancesNeedUpdate = false;
  6900. this.groupsNeedUpdate = false;
  6901. }
  6902. Object.assign( Geometry.prototype, EventDispatcher.prototype, {
  6903. isGeometry: true,
  6904. applyMatrix: function ( matrix ) {
  6905. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6906. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  6907. var vertex = this.vertices[ i ];
  6908. vertex.applyMatrix4( matrix );
  6909. }
  6910. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  6911. var face = this.faces[ i ];
  6912. face.normal.applyMatrix3( normalMatrix ).normalize();
  6913. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  6914. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  6915. }
  6916. }
  6917. if ( this.boundingBox !== null ) {
  6918. this.computeBoundingBox();
  6919. }
  6920. if ( this.boundingSphere !== null ) {
  6921. this.computeBoundingSphere();
  6922. }
  6923. this.verticesNeedUpdate = true;
  6924. this.normalsNeedUpdate = true;
  6925. return this;
  6926. },
  6927. rotateX: function () {
  6928. // rotate geometry around world x-axis
  6929. var m1 = new Matrix4();
  6930. return function rotateX( angle ) {
  6931. m1.makeRotationX( angle );
  6932. this.applyMatrix( m1 );
  6933. return this;
  6934. };
  6935. }(),
  6936. rotateY: function () {
  6937. // rotate geometry around world y-axis
  6938. var m1 = new Matrix4();
  6939. return function rotateY( angle ) {
  6940. m1.makeRotationY( angle );
  6941. this.applyMatrix( m1 );
  6942. return this;
  6943. };
  6944. }(),
  6945. rotateZ: function () {
  6946. // rotate geometry around world z-axis
  6947. var m1 = new Matrix4();
  6948. return function rotateZ( angle ) {
  6949. m1.makeRotationZ( angle );
  6950. this.applyMatrix( m1 );
  6951. return this;
  6952. };
  6953. }(),
  6954. translate: function () {
  6955. // translate geometry
  6956. var m1 = new Matrix4();
  6957. return function translate( x, y, z ) {
  6958. m1.makeTranslation( x, y, z );
  6959. this.applyMatrix( m1 );
  6960. return this;
  6961. };
  6962. }(),
  6963. scale: function () {
  6964. // scale geometry
  6965. var m1 = new Matrix4();
  6966. return function scale( x, y, z ) {
  6967. m1.makeScale( x, y, z );
  6968. this.applyMatrix( m1 );
  6969. return this;
  6970. };
  6971. }(),
  6972. lookAt: function () {
  6973. var obj = new Object3D();
  6974. return function lookAt( vector ) {
  6975. obj.lookAt( vector );
  6976. obj.updateMatrix();
  6977. this.applyMatrix( obj.matrix );
  6978. };
  6979. }(),
  6980. fromBufferGeometry: function ( geometry ) {
  6981. var scope = this;
  6982. var indices = geometry.index !== null ? geometry.index.array : undefined;
  6983. var attributes = geometry.attributes;
  6984. var positions = attributes.position.array;
  6985. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  6986. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  6987. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  6988. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  6989. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  6990. var tempNormals = [];
  6991. var tempUVs = [];
  6992. var tempUVs2 = [];
  6993. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  6994. scope.vertices.push( new Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  6995. if ( normals !== undefined ) {
  6996. tempNormals.push( new Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  6997. }
  6998. if ( colors !== undefined ) {
  6999. scope.colors.push( new Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  7000. }
  7001. if ( uvs !== undefined ) {
  7002. tempUVs.push( new Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  7003. }
  7004. if ( uvs2 !== undefined ) {
  7005. tempUVs2.push( new Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  7006. }
  7007. }
  7008. function addFace( a, b, c, materialIndex ) {
  7009. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  7010. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  7011. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  7012. scope.faces.push( face );
  7013. if ( uvs !== undefined ) {
  7014. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  7015. }
  7016. if ( uvs2 !== undefined ) {
  7017. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  7018. }
  7019. }
  7020. var groups = geometry.groups;
  7021. if ( groups.length > 0 ) {
  7022. for ( var i = 0; i < groups.length; i ++ ) {
  7023. var group = groups[ i ];
  7024. var start = group.start;
  7025. var count = group.count;
  7026. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  7027. if ( indices !== undefined ) {
  7028. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  7029. } else {
  7030. addFace( j, j + 1, j + 2, group.materialIndex );
  7031. }
  7032. }
  7033. }
  7034. } else {
  7035. if ( indices !== undefined ) {
  7036. for ( var i = 0; i < indices.length; i += 3 ) {
  7037. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  7038. }
  7039. } else {
  7040. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  7041. addFace( i, i + 1, i + 2 );
  7042. }
  7043. }
  7044. }
  7045. this.computeFaceNormals();
  7046. if ( geometry.boundingBox !== null ) {
  7047. this.boundingBox = geometry.boundingBox.clone();
  7048. }
  7049. if ( geometry.boundingSphere !== null ) {
  7050. this.boundingSphere = geometry.boundingSphere.clone();
  7051. }
  7052. return this;
  7053. },
  7054. center: function () {
  7055. this.computeBoundingBox();
  7056. var offset = this.boundingBox.getCenter().negate();
  7057. this.translate( offset.x, offset.y, offset.z );
  7058. return offset;
  7059. },
  7060. normalize: function () {
  7061. this.computeBoundingSphere();
  7062. var center = this.boundingSphere.center;
  7063. var radius = this.boundingSphere.radius;
  7064. var s = radius === 0 ? 1 : 1.0 / radius;
  7065. var matrix = new Matrix4();
  7066. matrix.set(
  7067. s, 0, 0, - s * center.x,
  7068. 0, s, 0, - s * center.y,
  7069. 0, 0, s, - s * center.z,
  7070. 0, 0, 0, 1
  7071. );
  7072. this.applyMatrix( matrix );
  7073. return this;
  7074. },
  7075. computeFaceNormals: function () {
  7076. var cb = new Vector3(), ab = new Vector3();
  7077. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7078. var face = this.faces[ f ];
  7079. var vA = this.vertices[ face.a ];
  7080. var vB = this.vertices[ face.b ];
  7081. var vC = this.vertices[ face.c ];
  7082. cb.subVectors( vC, vB );
  7083. ab.subVectors( vA, vB );
  7084. cb.cross( ab );
  7085. cb.normalize();
  7086. face.normal.copy( cb );
  7087. }
  7088. },
  7089. computeVertexNormals: function ( areaWeighted ) {
  7090. if ( areaWeighted === undefined ) areaWeighted = true;
  7091. var v, vl, f, fl, face, vertices;
  7092. vertices = new Array( this.vertices.length );
  7093. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7094. vertices[ v ] = new Vector3();
  7095. }
  7096. if ( areaWeighted ) {
  7097. // vertex normals weighted by triangle areas
  7098. // http://www.iquilezles.org/www/articles/normals/normals.htm
  7099. var vA, vB, vC;
  7100. var cb = new Vector3(), ab = new Vector3();
  7101. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7102. face = this.faces[ f ];
  7103. vA = this.vertices[ face.a ];
  7104. vB = this.vertices[ face.b ];
  7105. vC = this.vertices[ face.c ];
  7106. cb.subVectors( vC, vB );
  7107. ab.subVectors( vA, vB );
  7108. cb.cross( ab );
  7109. vertices[ face.a ].add( cb );
  7110. vertices[ face.b ].add( cb );
  7111. vertices[ face.c ].add( cb );
  7112. }
  7113. } else {
  7114. this.computeFaceNormals();
  7115. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7116. face = this.faces[ f ];
  7117. vertices[ face.a ].add( face.normal );
  7118. vertices[ face.b ].add( face.normal );
  7119. vertices[ face.c ].add( face.normal );
  7120. }
  7121. }
  7122. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7123. vertices[ v ].normalize();
  7124. }
  7125. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7126. face = this.faces[ f ];
  7127. var vertexNormals = face.vertexNormals;
  7128. if ( vertexNormals.length === 3 ) {
  7129. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  7130. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  7131. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  7132. } else {
  7133. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  7134. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  7135. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  7136. }
  7137. }
  7138. if ( this.faces.length > 0 ) {
  7139. this.normalsNeedUpdate = true;
  7140. }
  7141. },
  7142. computeFlatVertexNormals: function () {
  7143. var f, fl, face;
  7144. this.computeFaceNormals();
  7145. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7146. face = this.faces[ f ];
  7147. var vertexNormals = face.vertexNormals;
  7148. if ( vertexNormals.length === 3 ) {
  7149. vertexNormals[ 0 ].copy( face.normal );
  7150. vertexNormals[ 1 ].copy( face.normal );
  7151. vertexNormals[ 2 ].copy( face.normal );
  7152. } else {
  7153. vertexNormals[ 0 ] = face.normal.clone();
  7154. vertexNormals[ 1 ] = face.normal.clone();
  7155. vertexNormals[ 2 ] = face.normal.clone();
  7156. }
  7157. }
  7158. if ( this.faces.length > 0 ) {
  7159. this.normalsNeedUpdate = true;
  7160. }
  7161. },
  7162. computeMorphNormals: function () {
  7163. var i, il, f, fl, face;
  7164. // save original normals
  7165. // - create temp variables on first access
  7166. // otherwise just copy (for faster repeated calls)
  7167. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7168. face = this.faces[ f ];
  7169. if ( ! face.__originalFaceNormal ) {
  7170. face.__originalFaceNormal = face.normal.clone();
  7171. } else {
  7172. face.__originalFaceNormal.copy( face.normal );
  7173. }
  7174. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  7175. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  7176. if ( ! face.__originalVertexNormals[ i ] ) {
  7177. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  7178. } else {
  7179. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  7180. }
  7181. }
  7182. }
  7183. // use temp geometry to compute face and vertex normals for each morph
  7184. var tmpGeo = new Geometry();
  7185. tmpGeo.faces = this.faces;
  7186. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  7187. // create on first access
  7188. if ( ! this.morphNormals[ i ] ) {
  7189. this.morphNormals[ i ] = {};
  7190. this.morphNormals[ i ].faceNormals = [];
  7191. this.morphNormals[ i ].vertexNormals = [];
  7192. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  7193. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  7194. var faceNormal, vertexNormals;
  7195. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7196. faceNormal = new Vector3();
  7197. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  7198. dstNormalsFace.push( faceNormal );
  7199. dstNormalsVertex.push( vertexNormals );
  7200. }
  7201. }
  7202. var morphNormals = this.morphNormals[ i ];
  7203. // set vertices to morph target
  7204. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  7205. // compute morph normals
  7206. tmpGeo.computeFaceNormals();
  7207. tmpGeo.computeVertexNormals();
  7208. // store morph normals
  7209. var faceNormal, vertexNormals;
  7210. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7211. face = this.faces[ f ];
  7212. faceNormal = morphNormals.faceNormals[ f ];
  7213. vertexNormals = morphNormals.vertexNormals[ f ];
  7214. faceNormal.copy( face.normal );
  7215. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  7216. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  7217. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  7218. }
  7219. }
  7220. // restore original normals
  7221. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7222. face = this.faces[ f ];
  7223. face.normal = face.__originalFaceNormal;
  7224. face.vertexNormals = face.__originalVertexNormals;
  7225. }
  7226. },
  7227. computeLineDistances: function () {
  7228. var d = 0;
  7229. var vertices = this.vertices;
  7230. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  7231. if ( i > 0 ) {
  7232. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  7233. }
  7234. this.lineDistances[ i ] = d;
  7235. }
  7236. },
  7237. computeBoundingBox: function () {
  7238. if ( this.boundingBox === null ) {
  7239. this.boundingBox = new Box3();
  7240. }
  7241. this.boundingBox.setFromPoints( this.vertices );
  7242. },
  7243. computeBoundingSphere: function () {
  7244. if ( this.boundingSphere === null ) {
  7245. this.boundingSphere = new Sphere();
  7246. }
  7247. this.boundingSphere.setFromPoints( this.vertices );
  7248. },
  7249. merge: function ( geometry, matrix, materialIndexOffset ) {
  7250. if ( ! ( geometry && geometry.isGeometry ) ) {
  7251. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7252. return;
  7253. }
  7254. var normalMatrix,
  7255. vertexOffset = this.vertices.length,
  7256. vertices1 = this.vertices,
  7257. vertices2 = geometry.vertices,
  7258. faces1 = this.faces,
  7259. faces2 = geometry.faces,
  7260. uvs1 = this.faceVertexUvs[ 0 ],
  7261. uvs2 = geometry.faceVertexUvs[ 0 ],
  7262. colors1 = this.colors,
  7263. colors2 = geometry.colors;
  7264. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  7265. if ( matrix !== undefined ) {
  7266. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7267. }
  7268. // vertices
  7269. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  7270. var vertex = vertices2[ i ];
  7271. var vertexCopy = vertex.clone();
  7272. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  7273. vertices1.push( vertexCopy );
  7274. }
  7275. // colors
  7276. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  7277. colors1.push( colors2[ i ].clone() );
  7278. }
  7279. // faces
  7280. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  7281. var face = faces2[ i ], faceCopy, normal, color,
  7282. faceVertexNormals = face.vertexNormals,
  7283. faceVertexColors = face.vertexColors;
  7284. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7285. faceCopy.normal.copy( face.normal );
  7286. if ( normalMatrix !== undefined ) {
  7287. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7288. }
  7289. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7290. normal = faceVertexNormals[ j ].clone();
  7291. if ( normalMatrix !== undefined ) {
  7292. normal.applyMatrix3( normalMatrix ).normalize();
  7293. }
  7294. faceCopy.vertexNormals.push( normal );
  7295. }
  7296. faceCopy.color.copy( face.color );
  7297. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  7298. color = faceVertexColors[ j ];
  7299. faceCopy.vertexColors.push( color.clone() );
  7300. }
  7301. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7302. faces1.push( faceCopy );
  7303. }
  7304. // uvs
  7305. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  7306. var uv = uvs2[ i ], uvCopy = [];
  7307. if ( uv === undefined ) {
  7308. continue;
  7309. }
  7310. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  7311. uvCopy.push( uv[ j ].clone() );
  7312. }
  7313. uvs1.push( uvCopy );
  7314. }
  7315. },
  7316. mergeMesh: function ( mesh ) {
  7317. if ( ! ( mesh && mesh.isMesh ) ) {
  7318. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7319. return;
  7320. }
  7321. mesh.matrixAutoUpdate && mesh.updateMatrix();
  7322. this.merge( mesh.geometry, mesh.matrix );
  7323. },
  7324. /*
  7325. * Checks for duplicate vertices with hashmap.
  7326. * Duplicated vertices are removed
  7327. * and faces' vertices are updated.
  7328. */
  7329. mergeVertices: function () {
  7330. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7331. var unique = [], changes = [];
  7332. var v, key;
  7333. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7334. var precision = Math.pow( 10, precisionPoints );
  7335. var i, il, face;
  7336. var indices, j, jl;
  7337. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  7338. v = this.vertices[ i ];
  7339. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7340. if ( verticesMap[ key ] === undefined ) {
  7341. verticesMap[ key ] = i;
  7342. unique.push( this.vertices[ i ] );
  7343. changes[ i ] = unique.length - 1;
  7344. } else {
  7345. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7346. changes[ i ] = changes[ verticesMap[ key ] ];
  7347. }
  7348. }
  7349. // if faces are completely degenerate after merging vertices, we
  7350. // have to remove them from the geometry.
  7351. var faceIndicesToRemove = [];
  7352. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  7353. face = this.faces[ i ];
  7354. face.a = changes[ face.a ];
  7355. face.b = changes[ face.b ];
  7356. face.c = changes[ face.c ];
  7357. indices = [ face.a, face.b, face.c ];
  7358. // if any duplicate vertices are found in a Face3
  7359. // we have to remove the face as nothing can be saved
  7360. for ( var n = 0; n < 3; n ++ ) {
  7361. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7362. faceIndicesToRemove.push( i );
  7363. break;
  7364. }
  7365. }
  7366. }
  7367. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7368. var idx = faceIndicesToRemove[ i ];
  7369. this.faces.splice( idx, 1 );
  7370. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7371. this.faceVertexUvs[ j ].splice( idx, 1 );
  7372. }
  7373. }
  7374. // Use unique set of vertices
  7375. var diff = this.vertices.length - unique.length;
  7376. this.vertices = unique;
  7377. return diff;
  7378. },
  7379. setFromPoints: function ( points ) {
  7380. this.vertices = [];
  7381. for ( var i = 0, l = points.length; i < l; i ++ ) {
  7382. var point = points[ i ];
  7383. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  7384. }
  7385. return this;
  7386. },
  7387. sortFacesByMaterialIndex: function () {
  7388. var faces = this.faces;
  7389. var length = faces.length;
  7390. // tag faces
  7391. for ( var i = 0; i < length; i ++ ) {
  7392. faces[ i ]._id = i;
  7393. }
  7394. // sort faces
  7395. function materialIndexSort( a, b ) {
  7396. return a.materialIndex - b.materialIndex;
  7397. }
  7398. faces.sort( materialIndexSort );
  7399. // sort uvs
  7400. var uvs1 = this.faceVertexUvs[ 0 ];
  7401. var uvs2 = this.faceVertexUvs[ 1 ];
  7402. var newUvs1, newUvs2;
  7403. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7404. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7405. for ( var i = 0; i < length; i ++ ) {
  7406. var id = faces[ i ]._id;
  7407. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  7408. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  7409. }
  7410. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  7411. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  7412. },
  7413. toJSON: function () {
  7414. var data = {
  7415. metadata: {
  7416. version: 4.5,
  7417. type: 'Geometry',
  7418. generator: 'Geometry.toJSON'
  7419. }
  7420. };
  7421. // standard Geometry serialization
  7422. data.uuid = this.uuid;
  7423. data.type = this.type;
  7424. if ( this.name !== '' ) data.name = this.name;
  7425. if ( this.parameters !== undefined ) {
  7426. var parameters = this.parameters;
  7427. for ( var key in parameters ) {
  7428. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7429. }
  7430. return data;
  7431. }
  7432. var vertices = [];
  7433. for ( var i = 0; i < this.vertices.length; i ++ ) {
  7434. var vertex = this.vertices[ i ];
  7435. vertices.push( vertex.x, vertex.y, vertex.z );
  7436. }
  7437. var faces = [];
  7438. var normals = [];
  7439. var normalsHash = {};
  7440. var colors = [];
  7441. var colorsHash = {};
  7442. var uvs = [];
  7443. var uvsHash = {};
  7444. for ( var i = 0; i < this.faces.length; i ++ ) {
  7445. var face = this.faces[ i ];
  7446. var hasMaterial = true;
  7447. var hasFaceUv = false; // deprecated
  7448. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  7449. var hasFaceNormal = face.normal.length() > 0;
  7450. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  7451. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  7452. var hasFaceVertexColor = face.vertexColors.length > 0;
  7453. var faceType = 0;
  7454. faceType = setBit( faceType, 0, 0 ); // isQuad
  7455. faceType = setBit( faceType, 1, hasMaterial );
  7456. faceType = setBit( faceType, 2, hasFaceUv );
  7457. faceType = setBit( faceType, 3, hasFaceVertexUv );
  7458. faceType = setBit( faceType, 4, hasFaceNormal );
  7459. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  7460. faceType = setBit( faceType, 6, hasFaceColor );
  7461. faceType = setBit( faceType, 7, hasFaceVertexColor );
  7462. faces.push( faceType );
  7463. faces.push( face.a, face.b, face.c );
  7464. faces.push( face.materialIndex );
  7465. if ( hasFaceVertexUv ) {
  7466. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  7467. faces.push(
  7468. getUvIndex( faceVertexUvs[ 0 ] ),
  7469. getUvIndex( faceVertexUvs[ 1 ] ),
  7470. getUvIndex( faceVertexUvs[ 2 ] )
  7471. );
  7472. }
  7473. if ( hasFaceNormal ) {
  7474. faces.push( getNormalIndex( face.normal ) );
  7475. }
  7476. if ( hasFaceVertexNormal ) {
  7477. var vertexNormals = face.vertexNormals;
  7478. faces.push(
  7479. getNormalIndex( vertexNormals[ 0 ] ),
  7480. getNormalIndex( vertexNormals[ 1 ] ),
  7481. getNormalIndex( vertexNormals[ 2 ] )
  7482. );
  7483. }
  7484. if ( hasFaceColor ) {
  7485. faces.push( getColorIndex( face.color ) );
  7486. }
  7487. if ( hasFaceVertexColor ) {
  7488. var vertexColors = face.vertexColors;
  7489. faces.push(
  7490. getColorIndex( vertexColors[ 0 ] ),
  7491. getColorIndex( vertexColors[ 1 ] ),
  7492. getColorIndex( vertexColors[ 2 ] )
  7493. );
  7494. }
  7495. }
  7496. function setBit( value, position, enabled ) {
  7497. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  7498. }
  7499. function getNormalIndex( normal ) {
  7500. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  7501. if ( normalsHash[ hash ] !== undefined ) {
  7502. return normalsHash[ hash ];
  7503. }
  7504. normalsHash[ hash ] = normals.length / 3;
  7505. normals.push( normal.x, normal.y, normal.z );
  7506. return normalsHash[ hash ];
  7507. }
  7508. function getColorIndex( color ) {
  7509. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  7510. if ( colorsHash[ hash ] !== undefined ) {
  7511. return colorsHash[ hash ];
  7512. }
  7513. colorsHash[ hash ] = colors.length;
  7514. colors.push( color.getHex() );
  7515. return colorsHash[ hash ];
  7516. }
  7517. function getUvIndex( uv ) {
  7518. var hash = uv.x.toString() + uv.y.toString();
  7519. if ( uvsHash[ hash ] !== undefined ) {
  7520. return uvsHash[ hash ];
  7521. }
  7522. uvsHash[ hash ] = uvs.length / 2;
  7523. uvs.push( uv.x, uv.y );
  7524. return uvsHash[ hash ];
  7525. }
  7526. data.data = {};
  7527. data.data.vertices = vertices;
  7528. data.data.normals = normals;
  7529. if ( colors.length > 0 ) data.data.colors = colors;
  7530. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  7531. data.data.faces = faces;
  7532. return data;
  7533. },
  7534. clone: function () {
  7535. /*
  7536. // Handle primitives
  7537. var parameters = this.parameters;
  7538. if ( parameters !== undefined ) {
  7539. var values = [];
  7540. for ( var key in parameters ) {
  7541. values.push( parameters[ key ] );
  7542. }
  7543. var geometry = Object.create( this.constructor.prototype );
  7544. this.constructor.apply( geometry, values );
  7545. return geometry;
  7546. }
  7547. return new this.constructor().copy( this );
  7548. */
  7549. return new Geometry().copy( this );
  7550. },
  7551. copy: function ( source ) {
  7552. var i, il, j, jl, k, kl;
  7553. // reset
  7554. this.vertices = [];
  7555. this.colors = [];
  7556. this.faces = [];
  7557. this.faceVertexUvs = [[]];
  7558. this.morphTargets = [];
  7559. this.morphNormals = [];
  7560. this.skinWeights = [];
  7561. this.skinIndices = [];
  7562. this.lineDistances = [];
  7563. this.boundingBox = null;
  7564. this.boundingSphere = null;
  7565. // name
  7566. this.name = source.name;
  7567. // vertices
  7568. var vertices = source.vertices;
  7569. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  7570. this.vertices.push( vertices[ i ].clone() );
  7571. }
  7572. // colors
  7573. var colors = source.colors;
  7574. for ( i = 0, il = colors.length; i < il; i ++ ) {
  7575. this.colors.push( colors[ i ].clone() );
  7576. }
  7577. // faces
  7578. var faces = source.faces;
  7579. for ( i = 0, il = faces.length; i < il; i ++ ) {
  7580. this.faces.push( faces[ i ].clone() );
  7581. }
  7582. // face vertex uvs
  7583. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  7584. var faceVertexUvs = source.faceVertexUvs[ i ];
  7585. if ( this.faceVertexUvs[ i ] === undefined ) {
  7586. this.faceVertexUvs[ i ] = [];
  7587. }
  7588. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  7589. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  7590. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  7591. var uv = uvs[ k ];
  7592. uvsCopy.push( uv.clone() );
  7593. }
  7594. this.faceVertexUvs[ i ].push( uvsCopy );
  7595. }
  7596. }
  7597. // morph targets
  7598. var morphTargets = source.morphTargets;
  7599. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  7600. var morphTarget = {};
  7601. morphTarget.name = morphTargets[ i ].name;
  7602. // vertices
  7603. if ( morphTargets[ i ].vertices !== undefined ) {
  7604. morphTarget.vertices = [];
  7605. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  7606. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  7607. }
  7608. }
  7609. // normals
  7610. if ( morphTargets[ i ].normals !== undefined ) {
  7611. morphTarget.normals = [];
  7612. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  7613. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  7614. }
  7615. }
  7616. this.morphTargets.push( morphTarget );
  7617. }
  7618. // morph normals
  7619. var morphNormals = source.morphNormals;
  7620. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  7621. var morphNormal = {};
  7622. // vertex normals
  7623. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  7624. morphNormal.vertexNormals = [];
  7625. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  7626. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  7627. var destVertexNormal = {};
  7628. destVertexNormal.a = srcVertexNormal.a.clone();
  7629. destVertexNormal.b = srcVertexNormal.b.clone();
  7630. destVertexNormal.c = srcVertexNormal.c.clone();
  7631. morphNormal.vertexNormals.push( destVertexNormal );
  7632. }
  7633. }
  7634. // face normals
  7635. if ( morphNormals[ i ].faceNormals !== undefined ) {
  7636. morphNormal.faceNormals = [];
  7637. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  7638. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  7639. }
  7640. }
  7641. this.morphNormals.push( morphNormal );
  7642. }
  7643. // skin weights
  7644. var skinWeights = source.skinWeights;
  7645. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  7646. this.skinWeights.push( skinWeights[ i ].clone() );
  7647. }
  7648. // skin indices
  7649. var skinIndices = source.skinIndices;
  7650. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  7651. this.skinIndices.push( skinIndices[ i ].clone() );
  7652. }
  7653. // line distances
  7654. var lineDistances = source.lineDistances;
  7655. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  7656. this.lineDistances.push( lineDistances[ i ] );
  7657. }
  7658. // bounding box
  7659. var boundingBox = source.boundingBox;
  7660. if ( boundingBox !== null ) {
  7661. this.boundingBox = boundingBox.clone();
  7662. }
  7663. // bounding sphere
  7664. var boundingSphere = source.boundingSphere;
  7665. if ( boundingSphere !== null ) {
  7666. this.boundingSphere = boundingSphere.clone();
  7667. }
  7668. // update flags
  7669. this.elementsNeedUpdate = source.elementsNeedUpdate;
  7670. this.verticesNeedUpdate = source.verticesNeedUpdate;
  7671. this.uvsNeedUpdate = source.uvsNeedUpdate;
  7672. this.normalsNeedUpdate = source.normalsNeedUpdate;
  7673. this.colorsNeedUpdate = source.colorsNeedUpdate;
  7674. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  7675. this.groupsNeedUpdate = source.groupsNeedUpdate;
  7676. return this;
  7677. },
  7678. dispose: function () {
  7679. this.dispatchEvent( { type: 'dispose' } );
  7680. }
  7681. } );
  7682. /**
  7683. * @author supereggbert / http://www.paulbrunt.co.uk/
  7684. * @author philogb / http://blog.thejit.org/
  7685. * @author mikael emtinger / http://gomo.se/
  7686. * @author egraether / http://egraether.com/
  7687. * @author WestLangley / http://github.com/WestLangley
  7688. */
  7689. function Vector4( x, y, z, w ) {
  7690. this.x = x || 0;
  7691. this.y = y || 0;
  7692. this.z = z || 0;
  7693. this.w = ( w !== undefined ) ? w : 1;
  7694. }
  7695. Object.assign( Vector4.prototype, {
  7696. isVector4: true,
  7697. set: function ( x, y, z, w ) {
  7698. this.x = x;
  7699. this.y = y;
  7700. this.z = z;
  7701. this.w = w;
  7702. return this;
  7703. },
  7704. setScalar: function ( scalar ) {
  7705. this.x = scalar;
  7706. this.y = scalar;
  7707. this.z = scalar;
  7708. this.w = scalar;
  7709. return this;
  7710. },
  7711. setX: function ( x ) {
  7712. this.x = x;
  7713. return this;
  7714. },
  7715. setY: function ( y ) {
  7716. this.y = y;
  7717. return this;
  7718. },
  7719. setZ: function ( z ) {
  7720. this.z = z;
  7721. return this;
  7722. },
  7723. setW: function ( w ) {
  7724. this.w = w;
  7725. return this;
  7726. },
  7727. setComponent: function ( index, value ) {
  7728. switch ( index ) {
  7729. case 0: this.x = value; break;
  7730. case 1: this.y = value; break;
  7731. case 2: this.z = value; break;
  7732. case 3: this.w = value; break;
  7733. default: throw new Error( 'index is out of range: ' + index );
  7734. }
  7735. return this;
  7736. },
  7737. getComponent: function ( index ) {
  7738. switch ( index ) {
  7739. case 0: return this.x;
  7740. case 1: return this.y;
  7741. case 2: return this.z;
  7742. case 3: return this.w;
  7743. default: throw new Error( 'index is out of range: ' + index );
  7744. }
  7745. },
  7746. clone: function () {
  7747. return new this.constructor( this.x, this.y, this.z, this.w );
  7748. },
  7749. copy: function ( v ) {
  7750. this.x = v.x;
  7751. this.y = v.y;
  7752. this.z = v.z;
  7753. this.w = ( v.w !== undefined ) ? v.w : 1;
  7754. return this;
  7755. },
  7756. add: function ( v, w ) {
  7757. if ( w !== undefined ) {
  7758. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  7759. return this.addVectors( v, w );
  7760. }
  7761. this.x += v.x;
  7762. this.y += v.y;
  7763. this.z += v.z;
  7764. this.w += v.w;
  7765. return this;
  7766. },
  7767. addScalar: function ( s ) {
  7768. this.x += s;
  7769. this.y += s;
  7770. this.z += s;
  7771. this.w += s;
  7772. return this;
  7773. },
  7774. addVectors: function ( a, b ) {
  7775. this.x = a.x + b.x;
  7776. this.y = a.y + b.y;
  7777. this.z = a.z + b.z;
  7778. this.w = a.w + b.w;
  7779. return this;
  7780. },
  7781. addScaledVector: function ( v, s ) {
  7782. this.x += v.x * s;
  7783. this.y += v.y * s;
  7784. this.z += v.z * s;
  7785. this.w += v.w * s;
  7786. return this;
  7787. },
  7788. sub: function ( v, w ) {
  7789. if ( w !== undefined ) {
  7790. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  7791. return this.subVectors( v, w );
  7792. }
  7793. this.x -= v.x;
  7794. this.y -= v.y;
  7795. this.z -= v.z;
  7796. this.w -= v.w;
  7797. return this;
  7798. },
  7799. subScalar: function ( s ) {
  7800. this.x -= s;
  7801. this.y -= s;
  7802. this.z -= s;
  7803. this.w -= s;
  7804. return this;
  7805. },
  7806. subVectors: function ( a, b ) {
  7807. this.x = a.x - b.x;
  7808. this.y = a.y - b.y;
  7809. this.z = a.z - b.z;
  7810. this.w = a.w - b.w;
  7811. return this;
  7812. },
  7813. multiplyScalar: function ( scalar ) {
  7814. this.x *= scalar;
  7815. this.y *= scalar;
  7816. this.z *= scalar;
  7817. this.w *= scalar;
  7818. return this;
  7819. },
  7820. applyMatrix4: function ( m ) {
  7821. var x = this.x, y = this.y, z = this.z, w = this.w;
  7822. var e = m.elements;
  7823. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  7824. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  7825. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  7826. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  7827. return this;
  7828. },
  7829. divideScalar: function ( scalar ) {
  7830. return this.multiplyScalar( 1 / scalar );
  7831. },
  7832. setAxisAngleFromQuaternion: function ( q ) {
  7833. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  7834. // q is assumed to be normalized
  7835. this.w = 2 * Math.acos( q.w );
  7836. var s = Math.sqrt( 1 - q.w * q.w );
  7837. if ( s < 0.0001 ) {
  7838. this.x = 1;
  7839. this.y = 0;
  7840. this.z = 0;
  7841. } else {
  7842. this.x = q.x / s;
  7843. this.y = q.y / s;
  7844. this.z = q.z / s;
  7845. }
  7846. return this;
  7847. },
  7848. setAxisAngleFromRotationMatrix: function ( m ) {
  7849. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  7850. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  7851. var angle, x, y, z, // variables for result
  7852. epsilon = 0.01, // margin to allow for rounding errors
  7853. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  7854. te = m.elements,
  7855. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  7856. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  7857. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  7858. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  7859. ( Math.abs( m13 - m31 ) < epsilon ) &&
  7860. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  7861. // singularity found
  7862. // first check for identity matrix which must have +1 for all terms
  7863. // in leading diagonal and zero in other terms
  7864. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  7865. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  7866. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  7867. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  7868. // this singularity is identity matrix so angle = 0
  7869. this.set( 1, 0, 0, 0 );
  7870. return this; // zero angle, arbitrary axis
  7871. }
  7872. // otherwise this singularity is angle = 180
  7873. angle = Math.PI;
  7874. var xx = ( m11 + 1 ) / 2;
  7875. var yy = ( m22 + 1 ) / 2;
  7876. var zz = ( m33 + 1 ) / 2;
  7877. var xy = ( m12 + m21 ) / 4;
  7878. var xz = ( m13 + m31 ) / 4;
  7879. var yz = ( m23 + m32 ) / 4;
  7880. if ( ( xx > yy ) && ( xx > zz ) ) {
  7881. // m11 is the largest diagonal term
  7882. if ( xx < epsilon ) {
  7883. x = 0;
  7884. y = 0.707106781;
  7885. z = 0.707106781;
  7886. } else {
  7887. x = Math.sqrt( xx );
  7888. y = xy / x;
  7889. z = xz / x;
  7890. }
  7891. } else if ( yy > zz ) {
  7892. // m22 is the largest diagonal term
  7893. if ( yy < epsilon ) {
  7894. x = 0.707106781;
  7895. y = 0;
  7896. z = 0.707106781;
  7897. } else {
  7898. y = Math.sqrt( yy );
  7899. x = xy / y;
  7900. z = yz / y;
  7901. }
  7902. } else {
  7903. // m33 is the largest diagonal term so base result on this
  7904. if ( zz < epsilon ) {
  7905. x = 0.707106781;
  7906. y = 0.707106781;
  7907. z = 0;
  7908. } else {
  7909. z = Math.sqrt( zz );
  7910. x = xz / z;
  7911. y = yz / z;
  7912. }
  7913. }
  7914. this.set( x, y, z, angle );
  7915. return this; // return 180 deg rotation
  7916. }
  7917. // as we have reached here there are no singularities so we can handle normally
  7918. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  7919. ( m13 - m31 ) * ( m13 - m31 ) +
  7920. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  7921. if ( Math.abs( s ) < 0.001 ) s = 1;
  7922. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  7923. // caught by singularity test above, but I've left it in just in case
  7924. this.x = ( m32 - m23 ) / s;
  7925. this.y = ( m13 - m31 ) / s;
  7926. this.z = ( m21 - m12 ) / s;
  7927. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  7928. return this;
  7929. },
  7930. min: function ( v ) {
  7931. this.x = Math.min( this.x, v.x );
  7932. this.y = Math.min( this.y, v.y );
  7933. this.z = Math.min( this.z, v.z );
  7934. this.w = Math.min( this.w, v.w );
  7935. return this;
  7936. },
  7937. max: function ( v ) {
  7938. this.x = Math.max( this.x, v.x );
  7939. this.y = Math.max( this.y, v.y );
  7940. this.z = Math.max( this.z, v.z );
  7941. this.w = Math.max( this.w, v.w );
  7942. return this;
  7943. },
  7944. clamp: function ( min, max ) {
  7945. // assumes min < max, componentwise
  7946. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  7947. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  7948. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  7949. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  7950. return this;
  7951. },
  7952. clampScalar: function () {
  7953. var min, max;
  7954. return function clampScalar( minVal, maxVal ) {
  7955. if ( min === undefined ) {
  7956. min = new Vector4();
  7957. max = new Vector4();
  7958. }
  7959. min.set( minVal, minVal, minVal, minVal );
  7960. max.set( maxVal, maxVal, maxVal, maxVal );
  7961. return this.clamp( min, max );
  7962. };
  7963. }(),
  7964. clampLength: function ( min, max ) {
  7965. var length = this.length();
  7966. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  7967. },
  7968. floor: function () {
  7969. this.x = Math.floor( this.x );
  7970. this.y = Math.floor( this.y );
  7971. this.z = Math.floor( this.z );
  7972. this.w = Math.floor( this.w );
  7973. return this;
  7974. },
  7975. ceil: function () {
  7976. this.x = Math.ceil( this.x );
  7977. this.y = Math.ceil( this.y );
  7978. this.z = Math.ceil( this.z );
  7979. this.w = Math.ceil( this.w );
  7980. return this;
  7981. },
  7982. round: function () {
  7983. this.x = Math.round( this.x );
  7984. this.y = Math.round( this.y );
  7985. this.z = Math.round( this.z );
  7986. this.w = Math.round( this.w );
  7987. return this;
  7988. },
  7989. roundToZero: function () {
  7990. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  7991. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  7992. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  7993. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  7994. return this;
  7995. },
  7996. negate: function () {
  7997. this.x = - this.x;
  7998. this.y = - this.y;
  7999. this.z = - this.z;
  8000. this.w = - this.w;
  8001. return this;
  8002. },
  8003. dot: function ( v ) {
  8004. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  8005. },
  8006. lengthSq: function () {
  8007. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  8008. },
  8009. length: function () {
  8010. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  8011. },
  8012. manhattanLength: function () {
  8013. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  8014. },
  8015. normalize: function () {
  8016. return this.divideScalar( this.length() || 1 );
  8017. },
  8018. setLength: function ( length ) {
  8019. return this.normalize().multiplyScalar( length );
  8020. },
  8021. lerp: function ( v, alpha ) {
  8022. this.x += ( v.x - this.x ) * alpha;
  8023. this.y += ( v.y - this.y ) * alpha;
  8024. this.z += ( v.z - this.z ) * alpha;
  8025. this.w += ( v.w - this.w ) * alpha;
  8026. return this;
  8027. },
  8028. lerpVectors: function ( v1, v2, alpha ) {
  8029. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  8030. },
  8031. equals: function ( v ) {
  8032. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  8033. },
  8034. fromArray: function ( array, offset ) {
  8035. if ( offset === undefined ) offset = 0;
  8036. this.x = array[ offset ];
  8037. this.y = array[ offset + 1 ];
  8038. this.z = array[ offset + 2 ];
  8039. this.w = array[ offset + 3 ];
  8040. return this;
  8041. },
  8042. toArray: function ( array, offset ) {
  8043. if ( array === undefined ) array = [];
  8044. if ( offset === undefined ) offset = 0;
  8045. array[ offset ] = this.x;
  8046. array[ offset + 1 ] = this.y;
  8047. array[ offset + 2 ] = this.z;
  8048. array[ offset + 3 ] = this.w;
  8049. return array;
  8050. },
  8051. fromBufferAttribute: function ( attribute, index, offset ) {
  8052. if ( offset !== undefined ) {
  8053. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  8054. }
  8055. this.x = attribute.getX( index );
  8056. this.y = attribute.getY( index );
  8057. this.z = attribute.getZ( index );
  8058. this.w = attribute.getW( index );
  8059. return this;
  8060. }
  8061. } );
  8062. /**
  8063. * @author mrdoob / http://mrdoob.com/
  8064. */
  8065. function BufferAttribute( array, itemSize, normalized ) {
  8066. if ( Array.isArray( array ) ) {
  8067. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  8068. }
  8069. this.uuid = _Math.generateUUID();
  8070. this.name = '';
  8071. this.array = array;
  8072. this.itemSize = itemSize;
  8073. this.count = array !== undefined ? array.length / itemSize : 0;
  8074. this.normalized = normalized === true;
  8075. this.dynamic = false;
  8076. this.updateRange = { offset: 0, count: - 1 };
  8077. this.onUploadCallback = function () {};
  8078. this.version = 0;
  8079. }
  8080. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  8081. set: function ( value ) {
  8082. if ( value === true ) this.version ++;
  8083. }
  8084. } );
  8085. Object.assign( BufferAttribute.prototype, {
  8086. isBufferAttribute: true,
  8087. setArray: function ( array ) {
  8088. if ( Array.isArray( array ) ) {
  8089. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  8090. }
  8091. this.count = array !== undefined ? array.length / this.itemSize : 0;
  8092. this.array = array;
  8093. },
  8094. setDynamic: function ( value ) {
  8095. this.dynamic = value;
  8096. return this;
  8097. },
  8098. copy: function ( source ) {
  8099. this.array = new source.array.constructor( source.array );
  8100. this.itemSize = source.itemSize;
  8101. this.count = source.count;
  8102. this.normalized = source.normalized;
  8103. this.dynamic = source.dynamic;
  8104. return this;
  8105. },
  8106. copyAt: function ( index1, attribute, index2 ) {
  8107. index1 *= this.itemSize;
  8108. index2 *= attribute.itemSize;
  8109. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  8110. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  8111. }
  8112. return this;
  8113. },
  8114. copyArray: function ( array ) {
  8115. this.array.set( array );
  8116. return this;
  8117. },
  8118. copyColorsArray: function ( colors ) {
  8119. var array = this.array, offset = 0;
  8120. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  8121. var color = colors[ i ];
  8122. if ( color === undefined ) {
  8123. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  8124. color = new Color();
  8125. }
  8126. array[ offset ++ ] = color.r;
  8127. array[ offset ++ ] = color.g;
  8128. array[ offset ++ ] = color.b;
  8129. }
  8130. return this;
  8131. },
  8132. copyIndicesArray: function ( indices ) {
  8133. var array = this.array, offset = 0;
  8134. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  8135. var index = indices[ i ];
  8136. array[ offset ++ ] = index.a;
  8137. array[ offset ++ ] = index.b;
  8138. array[ offset ++ ] = index.c;
  8139. }
  8140. return this;
  8141. },
  8142. copyVector2sArray: function ( vectors ) {
  8143. var array = this.array, offset = 0;
  8144. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  8145. var vector = vectors[ i ];
  8146. if ( vector === undefined ) {
  8147. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  8148. vector = new Vector2();
  8149. }
  8150. array[ offset ++ ] = vector.x;
  8151. array[ offset ++ ] = vector.y;
  8152. }
  8153. return this;
  8154. },
  8155. copyVector3sArray: function ( vectors ) {
  8156. var array = this.array, offset = 0;
  8157. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  8158. var vector = vectors[ i ];
  8159. if ( vector === undefined ) {
  8160. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  8161. vector = new Vector3();
  8162. }
  8163. array[ offset ++ ] = vector.x;
  8164. array[ offset ++ ] = vector.y;
  8165. array[ offset ++ ] = vector.z;
  8166. }
  8167. return this;
  8168. },
  8169. copyVector4sArray: function ( vectors ) {
  8170. var array = this.array, offset = 0;
  8171. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  8172. var vector = vectors[ i ];
  8173. if ( vector === undefined ) {
  8174. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  8175. vector = new Vector4();
  8176. }
  8177. array[ offset ++ ] = vector.x;
  8178. array[ offset ++ ] = vector.y;
  8179. array[ offset ++ ] = vector.z;
  8180. array[ offset ++ ] = vector.w;
  8181. }
  8182. return this;
  8183. },
  8184. set: function ( value, offset ) {
  8185. if ( offset === undefined ) offset = 0;
  8186. this.array.set( value, offset );
  8187. return this;
  8188. },
  8189. getX: function ( index ) {
  8190. return this.array[ index * this.itemSize ];
  8191. },
  8192. setX: function ( index, x ) {
  8193. this.array[ index * this.itemSize ] = x;
  8194. return this;
  8195. },
  8196. getY: function ( index ) {
  8197. return this.array[ index * this.itemSize + 1 ];
  8198. },
  8199. setY: function ( index, y ) {
  8200. this.array[ index * this.itemSize + 1 ] = y;
  8201. return this;
  8202. },
  8203. getZ: function ( index ) {
  8204. return this.array[ index * this.itemSize + 2 ];
  8205. },
  8206. setZ: function ( index, z ) {
  8207. this.array[ index * this.itemSize + 2 ] = z;
  8208. return this;
  8209. },
  8210. getW: function ( index ) {
  8211. return this.array[ index * this.itemSize + 3 ];
  8212. },
  8213. setW: function ( index, w ) {
  8214. this.array[ index * this.itemSize + 3 ] = w;
  8215. return this;
  8216. },
  8217. setXY: function ( index, x, y ) {
  8218. index *= this.itemSize;
  8219. this.array[ index + 0 ] = x;
  8220. this.array[ index + 1 ] = y;
  8221. return this;
  8222. },
  8223. setXYZ: function ( index, x, y, z ) {
  8224. index *= this.itemSize;
  8225. this.array[ index + 0 ] = x;
  8226. this.array[ index + 1 ] = y;
  8227. this.array[ index + 2 ] = z;
  8228. return this;
  8229. },
  8230. setXYZW: function ( index, x, y, z, w ) {
  8231. index *= this.itemSize;
  8232. this.array[ index + 0 ] = x;
  8233. this.array[ index + 1 ] = y;
  8234. this.array[ index + 2 ] = z;
  8235. this.array[ index + 3 ] = w;
  8236. return this;
  8237. },
  8238. onUpload: function ( callback ) {
  8239. this.onUploadCallback = callback;
  8240. return this;
  8241. },
  8242. clone: function () {
  8243. return new this.constructor( this.array, this.itemSize ).copy( this );
  8244. }
  8245. } );
  8246. function Uint16BufferAttribute( array, itemSize, normalized ) {
  8247. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  8248. }
  8249. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  8250. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  8251. function Uint32BufferAttribute( array, itemSize, normalized ) {
  8252. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  8253. }
  8254. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  8255. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  8256. function Float32BufferAttribute( array, itemSize, normalized ) {
  8257. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  8258. }
  8259. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  8260. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  8261. /**
  8262. * @author mrdoob / http://mrdoob.com/
  8263. */
  8264. function DirectGeometry() {
  8265. this.indices = [];
  8266. this.vertices = [];
  8267. this.normals = [];
  8268. this.colors = [];
  8269. this.uvs = [];
  8270. this.uvs2 = [];
  8271. this.groups = [];
  8272. this.morphTargets = {};
  8273. this.skinWeights = [];
  8274. this.skinIndices = [];
  8275. // this.lineDistances = [];
  8276. this.boundingBox = null;
  8277. this.boundingSphere = null;
  8278. // update flags
  8279. this.verticesNeedUpdate = false;
  8280. this.normalsNeedUpdate = false;
  8281. this.colorsNeedUpdate = false;
  8282. this.uvsNeedUpdate = false;
  8283. this.groupsNeedUpdate = false;
  8284. }
  8285. Object.assign( DirectGeometry.prototype, {
  8286. computeGroups: function ( geometry ) {
  8287. var group;
  8288. var groups = [];
  8289. var materialIndex = undefined;
  8290. var faces = geometry.faces;
  8291. for ( var i = 0; i < faces.length; i ++ ) {
  8292. var face = faces[ i ];
  8293. // materials
  8294. if ( face.materialIndex !== materialIndex ) {
  8295. materialIndex = face.materialIndex;
  8296. if ( group !== undefined ) {
  8297. group.count = ( i * 3 ) - group.start;
  8298. groups.push( group );
  8299. }
  8300. group = {
  8301. start: i * 3,
  8302. materialIndex: materialIndex
  8303. };
  8304. }
  8305. }
  8306. if ( group !== undefined ) {
  8307. group.count = ( i * 3 ) - group.start;
  8308. groups.push( group );
  8309. }
  8310. this.groups = groups;
  8311. },
  8312. fromGeometry: function ( geometry ) {
  8313. var faces = geometry.faces;
  8314. var vertices = geometry.vertices;
  8315. var faceVertexUvs = geometry.faceVertexUvs;
  8316. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  8317. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  8318. // morphs
  8319. var morphTargets = geometry.morphTargets;
  8320. var morphTargetsLength = morphTargets.length;
  8321. var morphTargetsPosition;
  8322. if ( morphTargetsLength > 0 ) {
  8323. morphTargetsPosition = [];
  8324. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  8325. morphTargetsPosition[ i ] = [];
  8326. }
  8327. this.morphTargets.position = morphTargetsPosition;
  8328. }
  8329. var morphNormals = geometry.morphNormals;
  8330. var morphNormalsLength = morphNormals.length;
  8331. var morphTargetsNormal;
  8332. if ( morphNormalsLength > 0 ) {
  8333. morphTargetsNormal = [];
  8334. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  8335. morphTargetsNormal[ i ] = [];
  8336. }
  8337. this.morphTargets.normal = morphTargetsNormal;
  8338. }
  8339. // skins
  8340. var skinIndices = geometry.skinIndices;
  8341. var skinWeights = geometry.skinWeights;
  8342. var hasSkinIndices = skinIndices.length === vertices.length;
  8343. var hasSkinWeights = skinWeights.length === vertices.length;
  8344. //
  8345. for ( var i = 0; i < faces.length; i ++ ) {
  8346. var face = faces[ i ];
  8347. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  8348. var vertexNormals = face.vertexNormals;
  8349. if ( vertexNormals.length === 3 ) {
  8350. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  8351. } else {
  8352. var normal = face.normal;
  8353. this.normals.push( normal, normal, normal );
  8354. }
  8355. var vertexColors = face.vertexColors;
  8356. if ( vertexColors.length === 3 ) {
  8357. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  8358. } else {
  8359. var color = face.color;
  8360. this.colors.push( color, color, color );
  8361. }
  8362. if ( hasFaceVertexUv === true ) {
  8363. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  8364. if ( vertexUvs !== undefined ) {
  8365. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  8366. } else {
  8367. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  8368. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  8369. }
  8370. }
  8371. if ( hasFaceVertexUv2 === true ) {
  8372. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  8373. if ( vertexUvs !== undefined ) {
  8374. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  8375. } else {
  8376. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  8377. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  8378. }
  8379. }
  8380. // morphs
  8381. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  8382. var morphTarget = morphTargets[ j ].vertices;
  8383. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  8384. }
  8385. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  8386. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  8387. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  8388. }
  8389. // skins
  8390. if ( hasSkinIndices ) {
  8391. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  8392. }
  8393. if ( hasSkinWeights ) {
  8394. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  8395. }
  8396. }
  8397. this.computeGroups( geometry );
  8398. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  8399. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  8400. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  8401. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  8402. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  8403. return this;
  8404. }
  8405. } );
  8406. /**
  8407. * @author alteredq / http://alteredqualia.com/
  8408. * @author mrdoob / http://mrdoob.com/
  8409. */
  8410. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  8411. function BufferGeometry() {
  8412. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  8413. this.uuid = _Math.generateUUID();
  8414. this.name = '';
  8415. this.type = 'BufferGeometry';
  8416. this.index = null;
  8417. this.attributes = {};
  8418. this.morphAttributes = {};
  8419. this.groups = [];
  8420. this.boundingBox = null;
  8421. this.boundingSphere = null;
  8422. this.drawRange = { start: 0, count: Infinity };
  8423. }
  8424. Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, {
  8425. isBufferGeometry: true,
  8426. getIndex: function () {
  8427. return this.index;
  8428. },
  8429. setIndex: function ( index ) {
  8430. if ( Array.isArray( index ) ) {
  8431. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  8432. } else {
  8433. this.index = index;
  8434. }
  8435. },
  8436. addAttribute: function ( name, attribute ) {
  8437. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  8438. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  8439. this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  8440. return;
  8441. }
  8442. if ( name === 'index' ) {
  8443. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  8444. this.setIndex( attribute );
  8445. return;
  8446. }
  8447. this.attributes[ name ] = attribute;
  8448. return this;
  8449. },
  8450. getAttribute: function ( name ) {
  8451. return this.attributes[ name ];
  8452. },
  8453. removeAttribute: function ( name ) {
  8454. delete this.attributes[ name ];
  8455. return this;
  8456. },
  8457. addGroup: function ( start, count, materialIndex ) {
  8458. this.groups.push( {
  8459. start: start,
  8460. count: count,
  8461. materialIndex: materialIndex !== undefined ? materialIndex : 0
  8462. } );
  8463. },
  8464. clearGroups: function () {
  8465. this.groups = [];
  8466. },
  8467. setDrawRange: function ( start, count ) {
  8468. this.drawRange.start = start;
  8469. this.drawRange.count = count;
  8470. },
  8471. applyMatrix: function ( matrix ) {
  8472. var position = this.attributes.position;
  8473. if ( position !== undefined ) {
  8474. matrix.applyToBufferAttribute( position );
  8475. position.needsUpdate = true;
  8476. }
  8477. var normal = this.attributes.normal;
  8478. if ( normal !== undefined ) {
  8479. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  8480. normalMatrix.applyToBufferAttribute( normal );
  8481. normal.needsUpdate = true;
  8482. }
  8483. if ( this.boundingBox !== null ) {
  8484. this.computeBoundingBox();
  8485. }
  8486. if ( this.boundingSphere !== null ) {
  8487. this.computeBoundingSphere();
  8488. }
  8489. return this;
  8490. },
  8491. rotateX: function () {
  8492. // rotate geometry around world x-axis
  8493. var m1 = new Matrix4();
  8494. return function rotateX( angle ) {
  8495. m1.makeRotationX( angle );
  8496. this.applyMatrix( m1 );
  8497. return this;
  8498. };
  8499. }(),
  8500. rotateY: function () {
  8501. // rotate geometry around world y-axis
  8502. var m1 = new Matrix4();
  8503. return function rotateY( angle ) {
  8504. m1.makeRotationY( angle );
  8505. this.applyMatrix( m1 );
  8506. return this;
  8507. };
  8508. }(),
  8509. rotateZ: function () {
  8510. // rotate geometry around world z-axis
  8511. var m1 = new Matrix4();
  8512. return function rotateZ( angle ) {
  8513. m1.makeRotationZ( angle );
  8514. this.applyMatrix( m1 );
  8515. return this;
  8516. };
  8517. }(),
  8518. translate: function () {
  8519. // translate geometry
  8520. var m1 = new Matrix4();
  8521. return function translate( x, y, z ) {
  8522. m1.makeTranslation( x, y, z );
  8523. this.applyMatrix( m1 );
  8524. return this;
  8525. };
  8526. }(),
  8527. scale: function () {
  8528. // scale geometry
  8529. var m1 = new Matrix4();
  8530. return function scale( x, y, z ) {
  8531. m1.makeScale( x, y, z );
  8532. this.applyMatrix( m1 );
  8533. return this;
  8534. };
  8535. }(),
  8536. lookAt: function () {
  8537. var obj = new Object3D();
  8538. return function lookAt( vector ) {
  8539. obj.lookAt( vector );
  8540. obj.updateMatrix();
  8541. this.applyMatrix( obj.matrix );
  8542. };
  8543. }(),
  8544. center: function () {
  8545. this.computeBoundingBox();
  8546. var offset = this.boundingBox.getCenter().negate();
  8547. this.translate( offset.x, offset.y, offset.z );
  8548. return offset;
  8549. },
  8550. setFromObject: function ( object ) {
  8551. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  8552. var geometry = object.geometry;
  8553. if ( object.isPoints || object.isLine ) {
  8554. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  8555. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  8556. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  8557. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  8558. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  8559. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  8560. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  8561. }
  8562. if ( geometry.boundingSphere !== null ) {
  8563. this.boundingSphere = geometry.boundingSphere.clone();
  8564. }
  8565. if ( geometry.boundingBox !== null ) {
  8566. this.boundingBox = geometry.boundingBox.clone();
  8567. }
  8568. } else if ( object.isMesh ) {
  8569. if ( geometry && geometry.isGeometry ) {
  8570. this.fromGeometry( geometry );
  8571. }
  8572. }
  8573. return this;
  8574. },
  8575. setFromPoints: function ( points ) {
  8576. var position = [];
  8577. for ( var i = 0, l = points.length; i < l; i ++ ) {
  8578. var point = points[ i ];
  8579. position.push( point.x, point.y, point.z || 0 );
  8580. }
  8581. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  8582. return this;
  8583. },
  8584. updateFromObject: function ( object ) {
  8585. var geometry = object.geometry;
  8586. if ( object.isMesh ) {
  8587. var direct = geometry.__directGeometry;
  8588. if ( geometry.elementsNeedUpdate === true ) {
  8589. direct = undefined;
  8590. geometry.elementsNeedUpdate = false;
  8591. }
  8592. if ( direct === undefined ) {
  8593. return this.fromGeometry( geometry );
  8594. }
  8595. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  8596. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  8597. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  8598. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  8599. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  8600. geometry.verticesNeedUpdate = false;
  8601. geometry.normalsNeedUpdate = false;
  8602. geometry.colorsNeedUpdate = false;
  8603. geometry.uvsNeedUpdate = false;
  8604. geometry.groupsNeedUpdate = false;
  8605. geometry = direct;
  8606. }
  8607. var attribute;
  8608. if ( geometry.verticesNeedUpdate === true ) {
  8609. attribute = this.attributes.position;
  8610. if ( attribute !== undefined ) {
  8611. attribute.copyVector3sArray( geometry.vertices );
  8612. attribute.needsUpdate = true;
  8613. }
  8614. geometry.verticesNeedUpdate = false;
  8615. }
  8616. if ( geometry.normalsNeedUpdate === true ) {
  8617. attribute = this.attributes.normal;
  8618. if ( attribute !== undefined ) {
  8619. attribute.copyVector3sArray( geometry.normals );
  8620. attribute.needsUpdate = true;
  8621. }
  8622. geometry.normalsNeedUpdate = false;
  8623. }
  8624. if ( geometry.colorsNeedUpdate === true ) {
  8625. attribute = this.attributes.color;
  8626. if ( attribute !== undefined ) {
  8627. attribute.copyColorsArray( geometry.colors );
  8628. attribute.needsUpdate = true;
  8629. }
  8630. geometry.colorsNeedUpdate = false;
  8631. }
  8632. if ( geometry.uvsNeedUpdate ) {
  8633. attribute = this.attributes.uv;
  8634. if ( attribute !== undefined ) {
  8635. attribute.copyVector2sArray( geometry.uvs );
  8636. attribute.needsUpdate = true;
  8637. }
  8638. geometry.uvsNeedUpdate = false;
  8639. }
  8640. if ( geometry.lineDistancesNeedUpdate ) {
  8641. attribute = this.attributes.lineDistance;
  8642. if ( attribute !== undefined ) {
  8643. attribute.copyArray( geometry.lineDistances );
  8644. attribute.needsUpdate = true;
  8645. }
  8646. geometry.lineDistancesNeedUpdate = false;
  8647. }
  8648. if ( geometry.groupsNeedUpdate ) {
  8649. geometry.computeGroups( object.geometry );
  8650. this.groups = geometry.groups;
  8651. geometry.groupsNeedUpdate = false;
  8652. }
  8653. return this;
  8654. },
  8655. fromGeometry: function ( geometry ) {
  8656. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  8657. return this.fromDirectGeometry( geometry.__directGeometry );
  8658. },
  8659. fromDirectGeometry: function ( geometry ) {
  8660. var positions = new Float32Array( geometry.vertices.length * 3 );
  8661. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  8662. if ( geometry.normals.length > 0 ) {
  8663. var normals = new Float32Array( geometry.normals.length * 3 );
  8664. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  8665. }
  8666. if ( geometry.colors.length > 0 ) {
  8667. var colors = new Float32Array( geometry.colors.length * 3 );
  8668. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  8669. }
  8670. if ( geometry.uvs.length > 0 ) {
  8671. var uvs = new Float32Array( geometry.uvs.length * 2 );
  8672. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  8673. }
  8674. if ( geometry.uvs2.length > 0 ) {
  8675. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  8676. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  8677. }
  8678. if ( geometry.indices.length > 0 ) {
  8679. var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
  8680. var indices = new TypeArray( geometry.indices.length * 3 );
  8681. this.setIndex( new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  8682. }
  8683. // groups
  8684. this.groups = geometry.groups;
  8685. // morphs
  8686. for ( var name in geometry.morphTargets ) {
  8687. var array = [];
  8688. var morphTargets = geometry.morphTargets[ name ];
  8689. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  8690. var morphTarget = morphTargets[ i ];
  8691. var attribute = new Float32BufferAttribute( morphTarget.length * 3, 3 );
  8692. array.push( attribute.copyVector3sArray( morphTarget ) );
  8693. }
  8694. this.morphAttributes[ name ] = array;
  8695. }
  8696. // skinning
  8697. if ( geometry.skinIndices.length > 0 ) {
  8698. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  8699. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  8700. }
  8701. if ( geometry.skinWeights.length > 0 ) {
  8702. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  8703. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  8704. }
  8705. //
  8706. if ( geometry.boundingSphere !== null ) {
  8707. this.boundingSphere = geometry.boundingSphere.clone();
  8708. }
  8709. if ( geometry.boundingBox !== null ) {
  8710. this.boundingBox = geometry.boundingBox.clone();
  8711. }
  8712. return this;
  8713. },
  8714. computeBoundingBox: function () {
  8715. if ( this.boundingBox === null ) {
  8716. this.boundingBox = new Box3();
  8717. }
  8718. var position = this.attributes.position;
  8719. if ( position !== undefined ) {
  8720. this.boundingBox.setFromBufferAttribute( position );
  8721. } else {
  8722. this.boundingBox.makeEmpty();
  8723. }
  8724. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  8725. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  8726. }
  8727. },
  8728. computeBoundingSphere: function () {
  8729. var box = new Box3();
  8730. var vector = new Vector3();
  8731. return function computeBoundingSphere() {
  8732. if ( this.boundingSphere === null ) {
  8733. this.boundingSphere = new Sphere();
  8734. }
  8735. var position = this.attributes.position;
  8736. if ( position ) {
  8737. var center = this.boundingSphere.center;
  8738. box.setFromBufferAttribute( position );
  8739. box.getCenter( center );
  8740. // hoping to find a boundingSphere with a radius smaller than the
  8741. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  8742. var maxRadiusSq = 0;
  8743. for ( var i = 0, il = position.count; i < il; i ++ ) {
  8744. vector.x = position.getX( i );
  8745. vector.y = position.getY( i );
  8746. vector.z = position.getZ( i );
  8747. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  8748. }
  8749. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  8750. if ( isNaN( this.boundingSphere.radius ) ) {
  8751. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  8752. }
  8753. }
  8754. };
  8755. }(),
  8756. computeFaceNormals: function () {
  8757. // backwards compatibility
  8758. },
  8759. computeVertexNormals: function () {
  8760. var index = this.index;
  8761. var attributes = this.attributes;
  8762. var groups = this.groups;
  8763. if ( attributes.position ) {
  8764. var positions = attributes.position.array;
  8765. if ( attributes.normal === undefined ) {
  8766. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  8767. } else {
  8768. // reset existing normals to zero
  8769. var array = attributes.normal.array;
  8770. for ( var i = 0, il = array.length; i < il; i ++ ) {
  8771. array[ i ] = 0;
  8772. }
  8773. }
  8774. var normals = attributes.normal.array;
  8775. var vA, vB, vC;
  8776. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  8777. var cb = new Vector3(), ab = new Vector3();
  8778. // indexed elements
  8779. if ( index ) {
  8780. var indices = index.array;
  8781. if ( groups.length === 0 ) {
  8782. this.addGroup( 0, indices.length );
  8783. }
  8784. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  8785. var group = groups[ j ];
  8786. var start = group.start;
  8787. var count = group.count;
  8788. for ( var i = start, il = start + count; i < il; i += 3 ) {
  8789. vA = indices[ i + 0 ] * 3;
  8790. vB = indices[ i + 1 ] * 3;
  8791. vC = indices[ i + 2 ] * 3;
  8792. pA.fromArray( positions, vA );
  8793. pB.fromArray( positions, vB );
  8794. pC.fromArray( positions, vC );
  8795. cb.subVectors( pC, pB );
  8796. ab.subVectors( pA, pB );
  8797. cb.cross( ab );
  8798. normals[ vA ] += cb.x;
  8799. normals[ vA + 1 ] += cb.y;
  8800. normals[ vA + 2 ] += cb.z;
  8801. normals[ vB ] += cb.x;
  8802. normals[ vB + 1 ] += cb.y;
  8803. normals[ vB + 2 ] += cb.z;
  8804. normals[ vC ] += cb.x;
  8805. normals[ vC + 1 ] += cb.y;
  8806. normals[ vC + 2 ] += cb.z;
  8807. }
  8808. }
  8809. } else {
  8810. // non-indexed elements (unconnected triangle soup)
  8811. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  8812. pA.fromArray( positions, i );
  8813. pB.fromArray( positions, i + 3 );
  8814. pC.fromArray( positions, i + 6 );
  8815. cb.subVectors( pC, pB );
  8816. ab.subVectors( pA, pB );
  8817. cb.cross( ab );
  8818. normals[ i ] = cb.x;
  8819. normals[ i + 1 ] = cb.y;
  8820. normals[ i + 2 ] = cb.z;
  8821. normals[ i + 3 ] = cb.x;
  8822. normals[ i + 4 ] = cb.y;
  8823. normals[ i + 5 ] = cb.z;
  8824. normals[ i + 6 ] = cb.x;
  8825. normals[ i + 7 ] = cb.y;
  8826. normals[ i + 8 ] = cb.z;
  8827. }
  8828. }
  8829. this.normalizeNormals();
  8830. attributes.normal.needsUpdate = true;
  8831. }
  8832. },
  8833. merge: function ( geometry, offset ) {
  8834. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  8835. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  8836. return;
  8837. }
  8838. if ( offset === undefined ) offset = 0;
  8839. var attributes = this.attributes;
  8840. for ( var key in attributes ) {
  8841. if ( geometry.attributes[ key ] === undefined ) continue;
  8842. var attribute1 = attributes[ key ];
  8843. var attributeArray1 = attribute1.array;
  8844. var attribute2 = geometry.attributes[ key ];
  8845. var attributeArray2 = attribute2.array;
  8846. var attributeSize = attribute2.itemSize;
  8847. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  8848. attributeArray1[ j ] = attributeArray2[ i ];
  8849. }
  8850. }
  8851. return this;
  8852. },
  8853. normalizeNormals: function () {
  8854. var vector = new Vector3();
  8855. return function normalizeNormals() {
  8856. var normals = this.attributes.normal;
  8857. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  8858. vector.x = normals.getX( i );
  8859. vector.y = normals.getY( i );
  8860. vector.z = normals.getZ( i );
  8861. vector.normalize();
  8862. normals.setXYZ( i, vector.x, vector.y, vector.z );
  8863. }
  8864. };
  8865. }(),
  8866. toNonIndexed: function () {
  8867. if ( this.index === null ) {
  8868. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  8869. return this;
  8870. }
  8871. var geometry2 = new BufferGeometry();
  8872. var indices = this.index.array;
  8873. var attributes = this.attributes;
  8874. for ( var name in attributes ) {
  8875. var attribute = attributes[ name ];
  8876. var array = attribute.array;
  8877. var itemSize = attribute.itemSize;
  8878. var array2 = new array.constructor( indices.length * itemSize );
  8879. var index = 0, index2 = 0;
  8880. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  8881. index = indices[ i ] * itemSize;
  8882. for ( var j = 0; j < itemSize; j ++ ) {
  8883. array2[ index2 ++ ] = array[ index ++ ];
  8884. }
  8885. }
  8886. geometry2.addAttribute( name, new BufferAttribute( array2, itemSize ) );
  8887. }
  8888. return geometry2;
  8889. },
  8890. toJSON: function () {
  8891. var data = {
  8892. metadata: {
  8893. version: 4.5,
  8894. type: 'BufferGeometry',
  8895. generator: 'BufferGeometry.toJSON'
  8896. }
  8897. };
  8898. // standard BufferGeometry serialization
  8899. data.uuid = this.uuid;
  8900. data.type = this.type;
  8901. if ( this.name !== '' ) data.name = this.name;
  8902. if ( this.parameters !== undefined ) {
  8903. var parameters = this.parameters;
  8904. for ( var key in parameters ) {
  8905. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  8906. }
  8907. return data;
  8908. }
  8909. data.data = { attributes: {} };
  8910. var index = this.index;
  8911. if ( index !== null ) {
  8912. var array = Array.prototype.slice.call( index.array );
  8913. data.data.index = {
  8914. type: index.array.constructor.name,
  8915. array: array
  8916. };
  8917. }
  8918. var attributes = this.attributes;
  8919. for ( var key in attributes ) {
  8920. var attribute = attributes[ key ];
  8921. var array = Array.prototype.slice.call( attribute.array );
  8922. data.data.attributes[ key ] = {
  8923. itemSize: attribute.itemSize,
  8924. type: attribute.array.constructor.name,
  8925. array: array,
  8926. normalized: attribute.normalized
  8927. };
  8928. }
  8929. var groups = this.groups;
  8930. if ( groups.length > 0 ) {
  8931. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  8932. }
  8933. var boundingSphere = this.boundingSphere;
  8934. if ( boundingSphere !== null ) {
  8935. data.data.boundingSphere = {
  8936. center: boundingSphere.center.toArray(),
  8937. radius: boundingSphere.radius
  8938. };
  8939. }
  8940. return data;
  8941. },
  8942. clone: function () {
  8943. /*
  8944. // Handle primitives
  8945. var parameters = this.parameters;
  8946. if ( parameters !== undefined ) {
  8947. var values = [];
  8948. for ( var key in parameters ) {
  8949. values.push( parameters[ key ] );
  8950. }
  8951. var geometry = Object.create( this.constructor.prototype );
  8952. this.constructor.apply( geometry, values );
  8953. return geometry;
  8954. }
  8955. return new this.constructor().copy( this );
  8956. */
  8957. return new BufferGeometry().copy( this );
  8958. },
  8959. copy: function ( source ) {
  8960. var name, i, l;
  8961. // reset
  8962. this.index = null;
  8963. this.attributes = {};
  8964. this.morphAttributes = {};
  8965. this.groups = [];
  8966. this.boundingBox = null;
  8967. this.boundingSphere = null;
  8968. // name
  8969. this.name = source.name;
  8970. // index
  8971. var index = source.index;
  8972. if ( index !== null ) {
  8973. this.setIndex( index.clone() );
  8974. }
  8975. // attributes
  8976. var attributes = source.attributes;
  8977. for ( name in attributes ) {
  8978. var attribute = attributes[ name ];
  8979. this.addAttribute( name, attribute.clone() );
  8980. }
  8981. // morph attributes
  8982. var morphAttributes = source.morphAttributes;
  8983. for ( name in morphAttributes ) {
  8984. var array = [];
  8985. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  8986. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  8987. array.push( morphAttribute[ i ].clone() );
  8988. }
  8989. this.morphAttributes[ name ] = array;
  8990. }
  8991. // groups
  8992. var groups = source.groups;
  8993. for ( i = 0, l = groups.length; i < l; i ++ ) {
  8994. var group = groups[ i ];
  8995. this.addGroup( group.start, group.count, group.materialIndex );
  8996. }
  8997. // bounding box
  8998. var boundingBox = source.boundingBox;
  8999. if ( boundingBox !== null ) {
  9000. this.boundingBox = boundingBox.clone();
  9001. }
  9002. // bounding sphere
  9003. var boundingSphere = source.boundingSphere;
  9004. if ( boundingSphere !== null ) {
  9005. this.boundingSphere = boundingSphere.clone();
  9006. }
  9007. // draw range
  9008. this.drawRange.start = source.drawRange.start;
  9009. this.drawRange.count = source.drawRange.count;
  9010. return this;
  9011. },
  9012. dispose: function () {
  9013. this.dispatchEvent( { type: 'dispose' } );
  9014. }
  9015. } );
  9016. /**
  9017. * @author mrdoob / http://mrdoob.com/
  9018. * @author Mugen87 / https://github.com/Mugen87
  9019. */
  9020. // BoxGeometry
  9021. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  9022. Geometry.call( this );
  9023. this.type = 'BoxGeometry';
  9024. this.parameters = {
  9025. width: width,
  9026. height: height,
  9027. depth: depth,
  9028. widthSegments: widthSegments,
  9029. heightSegments: heightSegments,
  9030. depthSegments: depthSegments
  9031. };
  9032. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  9033. this.mergeVertices();
  9034. }
  9035. BoxGeometry.prototype = Object.create( Geometry.prototype );
  9036. BoxGeometry.prototype.constructor = BoxGeometry;
  9037. // BoxBufferGeometry
  9038. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  9039. BufferGeometry.call( this );
  9040. this.type = 'BoxBufferGeometry';
  9041. this.parameters = {
  9042. width: width,
  9043. height: height,
  9044. depth: depth,
  9045. widthSegments: widthSegments,
  9046. heightSegments: heightSegments,
  9047. depthSegments: depthSegments
  9048. };
  9049. var scope = this;
  9050. width = width || 1;
  9051. height = height || 1;
  9052. depth = depth || 1;
  9053. // segments
  9054. widthSegments = Math.floor( widthSegments ) || 1;
  9055. heightSegments = Math.floor( heightSegments ) || 1;
  9056. depthSegments = Math.floor( depthSegments ) || 1;
  9057. // buffers
  9058. var indices = [];
  9059. var vertices = [];
  9060. var normals = [];
  9061. var uvs = [];
  9062. // helper variables
  9063. var numberOfVertices = 0;
  9064. var groupStart = 0;
  9065. // build each side of the box geometry
  9066. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  9067. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  9068. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  9069. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  9070. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  9071. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  9072. // build geometry
  9073. this.setIndex( indices );
  9074. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  9075. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  9076. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  9077. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  9078. var segmentWidth = width / gridX;
  9079. var segmentHeight = height / gridY;
  9080. var widthHalf = width / 2;
  9081. var heightHalf = height / 2;
  9082. var depthHalf = depth / 2;
  9083. var gridX1 = gridX + 1;
  9084. var gridY1 = gridY + 1;
  9085. var vertexCounter = 0;
  9086. var groupCount = 0;
  9087. var ix, iy;
  9088. var vector = new Vector3();
  9089. // generate vertices, normals and uvs
  9090. for ( iy = 0; iy < gridY1; iy ++ ) {
  9091. var y = iy * segmentHeight - heightHalf;
  9092. for ( ix = 0; ix < gridX1; ix ++ ) {
  9093. var x = ix * segmentWidth - widthHalf;
  9094. // set values to correct vector component
  9095. vector[ u ] = x * udir;
  9096. vector[ v ] = y * vdir;
  9097. vector[ w ] = depthHalf;
  9098. // now apply vector to vertex buffer
  9099. vertices.push( vector.x, vector.y, vector.z );
  9100. // set values to correct vector component
  9101. vector[ u ] = 0;
  9102. vector[ v ] = 0;
  9103. vector[ w ] = depth > 0 ? 1 : - 1;
  9104. // now apply vector to normal buffer
  9105. normals.push( vector.x, vector.y, vector.z );
  9106. // uvs
  9107. uvs.push( ix / gridX );
  9108. uvs.push( 1 - ( iy / gridY ) );
  9109. // counters
  9110. vertexCounter += 1;
  9111. }
  9112. }
  9113. // indices
  9114. // 1. you need three indices to draw a single face
  9115. // 2. a single segment consists of two faces
  9116. // 3. so we need to generate six (2*3) indices per segment
  9117. for ( iy = 0; iy < gridY; iy ++ ) {
  9118. for ( ix = 0; ix < gridX; ix ++ ) {
  9119. var a = numberOfVertices + ix + gridX1 * iy;
  9120. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  9121. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  9122. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  9123. // faces
  9124. indices.push( a, b, d );
  9125. indices.push( b, c, d );
  9126. // increase counter
  9127. groupCount += 6;
  9128. }
  9129. }
  9130. // add a group to the geometry. this will ensure multi material support
  9131. scope.addGroup( groupStart, groupCount, materialIndex );
  9132. // calculate new start value for groups
  9133. groupStart += groupCount;
  9134. // update total number of vertices
  9135. numberOfVertices += vertexCounter;
  9136. }
  9137. }
  9138. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  9139. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  9140. /**
  9141. * @author bhouston / http://clara.io
  9142. */
  9143. function Ray( origin, direction ) {
  9144. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  9145. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  9146. }
  9147. Object.assign( Ray.prototype, {
  9148. set: function ( origin, direction ) {
  9149. this.origin.copy( origin );
  9150. this.direction.copy( direction );
  9151. return this;
  9152. },
  9153. clone: function () {
  9154. return new this.constructor().copy( this );
  9155. },
  9156. copy: function ( ray ) {
  9157. this.origin.copy( ray.origin );
  9158. this.direction.copy( ray.direction );
  9159. return this;
  9160. },
  9161. at: function ( t, optionalTarget ) {
  9162. var result = optionalTarget || new Vector3();
  9163. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  9164. },
  9165. lookAt: function ( v ) {
  9166. this.direction.copy( v ).sub( this.origin ).normalize();
  9167. return this;
  9168. },
  9169. recast: function () {
  9170. var v1 = new Vector3();
  9171. return function recast( t ) {
  9172. this.origin.copy( this.at( t, v1 ) );
  9173. return this;
  9174. };
  9175. }(),
  9176. closestPointToPoint: function ( point, optionalTarget ) {
  9177. var result = optionalTarget || new Vector3();
  9178. result.subVectors( point, this.origin );
  9179. var directionDistance = result.dot( this.direction );
  9180. if ( directionDistance < 0 ) {
  9181. return result.copy( this.origin );
  9182. }
  9183. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  9184. },
  9185. distanceToPoint: function ( point ) {
  9186. return Math.sqrt( this.distanceSqToPoint( point ) );
  9187. },
  9188. distanceSqToPoint: function () {
  9189. var v1 = new Vector3();
  9190. return function distanceSqToPoint( point ) {
  9191. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  9192. // point behind the ray
  9193. if ( directionDistance < 0 ) {
  9194. return this.origin.distanceToSquared( point );
  9195. }
  9196. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  9197. return v1.distanceToSquared( point );
  9198. };
  9199. }(),
  9200. distanceSqToSegment: function () {
  9201. var segCenter = new Vector3();
  9202. var segDir = new Vector3();
  9203. var diff = new Vector3();
  9204. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  9205. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  9206. // It returns the min distance between the ray and the segment
  9207. // defined by v0 and v1
  9208. // It can also set two optional targets :
  9209. // - The closest point on the ray
  9210. // - The closest point on the segment
  9211. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  9212. segDir.copy( v1 ).sub( v0 ).normalize();
  9213. diff.copy( this.origin ).sub( segCenter );
  9214. var segExtent = v0.distanceTo( v1 ) * 0.5;
  9215. var a01 = - this.direction.dot( segDir );
  9216. var b0 = diff.dot( this.direction );
  9217. var b1 = - diff.dot( segDir );
  9218. var c = diff.lengthSq();
  9219. var det = Math.abs( 1 - a01 * a01 );
  9220. var s0, s1, sqrDist, extDet;
  9221. if ( det > 0 ) {
  9222. // The ray and segment are not parallel.
  9223. s0 = a01 * b1 - b0;
  9224. s1 = a01 * b0 - b1;
  9225. extDet = segExtent * det;
  9226. if ( s0 >= 0 ) {
  9227. if ( s1 >= - extDet ) {
  9228. if ( s1 <= extDet ) {
  9229. // region 0
  9230. // Minimum at interior points of ray and segment.
  9231. var invDet = 1 / det;
  9232. s0 *= invDet;
  9233. s1 *= invDet;
  9234. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  9235. } else {
  9236. // region 1
  9237. s1 = segExtent;
  9238. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  9239. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9240. }
  9241. } else {
  9242. // region 5
  9243. s1 = - segExtent;
  9244. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  9245. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9246. }
  9247. } else {
  9248. if ( s1 <= - extDet ) {
  9249. // region 4
  9250. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  9251. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  9252. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9253. } else if ( s1 <= extDet ) {
  9254. // region 3
  9255. s0 = 0;
  9256. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  9257. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  9258. } else {
  9259. // region 2
  9260. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  9261. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  9262. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9263. }
  9264. }
  9265. } else {
  9266. // Ray and segment are parallel.
  9267. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  9268. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  9269. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9270. }
  9271. if ( optionalPointOnRay ) {
  9272. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  9273. }
  9274. if ( optionalPointOnSegment ) {
  9275. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  9276. }
  9277. return sqrDist;
  9278. };
  9279. }(),
  9280. intersectSphere: function () {
  9281. var v1 = new Vector3();
  9282. return function intersectSphere( sphere, optionalTarget ) {
  9283. v1.subVectors( sphere.center, this.origin );
  9284. var tca = v1.dot( this.direction );
  9285. var d2 = v1.dot( v1 ) - tca * tca;
  9286. var radius2 = sphere.radius * sphere.radius;
  9287. if ( d2 > radius2 ) return null;
  9288. var thc = Math.sqrt( radius2 - d2 );
  9289. // t0 = first intersect point - entrance on front of sphere
  9290. var t0 = tca - thc;
  9291. // t1 = second intersect point - exit point on back of sphere
  9292. var t1 = tca + thc;
  9293. // test to see if both t0 and t1 are behind the ray - if so, return null
  9294. if ( t0 < 0 && t1 < 0 ) return null;
  9295. // test to see if t0 is behind the ray:
  9296. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  9297. // in order to always return an intersect point that is in front of the ray.
  9298. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  9299. // else t0 is in front of the ray, so return the first collision point scaled by t0
  9300. return this.at( t0, optionalTarget );
  9301. };
  9302. }(),
  9303. intersectsSphere: function ( sphere ) {
  9304. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  9305. },
  9306. distanceToPlane: function ( plane ) {
  9307. var denominator = plane.normal.dot( this.direction );
  9308. if ( denominator === 0 ) {
  9309. // line is coplanar, return origin
  9310. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  9311. return 0;
  9312. }
  9313. // Null is preferable to undefined since undefined means.... it is undefined
  9314. return null;
  9315. }
  9316. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  9317. // Return if the ray never intersects the plane
  9318. return t >= 0 ? t : null;
  9319. },
  9320. intersectPlane: function ( plane, optionalTarget ) {
  9321. var t = this.distanceToPlane( plane );
  9322. if ( t === null ) {
  9323. return null;
  9324. }
  9325. return this.at( t, optionalTarget );
  9326. },
  9327. intersectsPlane: function ( plane ) {
  9328. // check if the ray lies on the plane first
  9329. var distToPoint = plane.distanceToPoint( this.origin );
  9330. if ( distToPoint === 0 ) {
  9331. return true;
  9332. }
  9333. var denominator = plane.normal.dot( this.direction );
  9334. if ( denominator * distToPoint < 0 ) {
  9335. return true;
  9336. }
  9337. // ray origin is behind the plane (and is pointing behind it)
  9338. return false;
  9339. },
  9340. intersectBox: function ( box, optionalTarget ) {
  9341. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  9342. var invdirx = 1 / this.direction.x,
  9343. invdiry = 1 / this.direction.y,
  9344. invdirz = 1 / this.direction.z;
  9345. var origin = this.origin;
  9346. if ( invdirx >= 0 ) {
  9347. tmin = ( box.min.x - origin.x ) * invdirx;
  9348. tmax = ( box.max.x - origin.x ) * invdirx;
  9349. } else {
  9350. tmin = ( box.max.x - origin.x ) * invdirx;
  9351. tmax = ( box.min.x - origin.x ) * invdirx;
  9352. }
  9353. if ( invdiry >= 0 ) {
  9354. tymin = ( box.min.y - origin.y ) * invdiry;
  9355. tymax = ( box.max.y - origin.y ) * invdiry;
  9356. } else {
  9357. tymin = ( box.max.y - origin.y ) * invdiry;
  9358. tymax = ( box.min.y - origin.y ) * invdiry;
  9359. }
  9360. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  9361. // These lines also handle the case where tmin or tmax is NaN
  9362. // (result of 0 * Infinity). x !== x returns true if x is NaN
  9363. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  9364. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  9365. if ( invdirz >= 0 ) {
  9366. tzmin = ( box.min.z - origin.z ) * invdirz;
  9367. tzmax = ( box.max.z - origin.z ) * invdirz;
  9368. } else {
  9369. tzmin = ( box.max.z - origin.z ) * invdirz;
  9370. tzmax = ( box.min.z - origin.z ) * invdirz;
  9371. }
  9372. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  9373. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  9374. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  9375. //return point closest to the ray (positive side)
  9376. if ( tmax < 0 ) return null;
  9377. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  9378. },
  9379. intersectsBox: ( function () {
  9380. var v = new Vector3();
  9381. return function intersectsBox( box ) {
  9382. return this.intersectBox( box, v ) !== null;
  9383. };
  9384. } )(),
  9385. intersectTriangle: function () {
  9386. // Compute the offset origin, edges, and normal.
  9387. var diff = new Vector3();
  9388. var edge1 = new Vector3();
  9389. var edge2 = new Vector3();
  9390. var normal = new Vector3();
  9391. return function intersectTriangle( a, b, c, backfaceCulling, optionalTarget ) {
  9392. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  9393. edge1.subVectors( b, a );
  9394. edge2.subVectors( c, a );
  9395. normal.crossVectors( edge1, edge2 );
  9396. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  9397. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  9398. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  9399. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  9400. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  9401. var DdN = this.direction.dot( normal );
  9402. var sign;
  9403. if ( DdN > 0 ) {
  9404. if ( backfaceCulling ) return null;
  9405. sign = 1;
  9406. } else if ( DdN < 0 ) {
  9407. sign = - 1;
  9408. DdN = - DdN;
  9409. } else {
  9410. return null;
  9411. }
  9412. diff.subVectors( this.origin, a );
  9413. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  9414. // b1 < 0, no intersection
  9415. if ( DdQxE2 < 0 ) {
  9416. return null;
  9417. }
  9418. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  9419. // b2 < 0, no intersection
  9420. if ( DdE1xQ < 0 ) {
  9421. return null;
  9422. }
  9423. // b1+b2 > 1, no intersection
  9424. if ( DdQxE2 + DdE1xQ > DdN ) {
  9425. return null;
  9426. }
  9427. // Line intersects triangle, check if ray does.
  9428. var QdN = - sign * diff.dot( normal );
  9429. // t < 0, no intersection
  9430. if ( QdN < 0 ) {
  9431. return null;
  9432. }
  9433. // Ray intersects triangle.
  9434. return this.at( QdN / DdN, optionalTarget );
  9435. };
  9436. }(),
  9437. applyMatrix4: function ( matrix4 ) {
  9438. this.origin.applyMatrix4( matrix4 );
  9439. this.direction.transformDirection( matrix4 );
  9440. return this;
  9441. },
  9442. equals: function ( ray ) {
  9443. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  9444. }
  9445. } );
  9446. /**
  9447. * @author bhouston / http://clara.io
  9448. */
  9449. function Line3( start, end ) {
  9450. this.start = ( start !== undefined ) ? start : new Vector3();
  9451. this.end = ( end !== undefined ) ? end : new Vector3();
  9452. }
  9453. Object.assign( Line3.prototype, {
  9454. set: function ( start, end ) {
  9455. this.start.copy( start );
  9456. this.end.copy( end );
  9457. return this;
  9458. },
  9459. clone: function () {
  9460. return new this.constructor().copy( this );
  9461. },
  9462. copy: function ( line ) {
  9463. this.start.copy( line.start );
  9464. this.end.copy( line.end );
  9465. return this;
  9466. },
  9467. getCenter: function ( optionalTarget ) {
  9468. var result = optionalTarget || new Vector3();
  9469. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  9470. },
  9471. delta: function ( optionalTarget ) {
  9472. var result = optionalTarget || new Vector3();
  9473. return result.subVectors( this.end, this.start );
  9474. },
  9475. distanceSq: function () {
  9476. return this.start.distanceToSquared( this.end );
  9477. },
  9478. distance: function () {
  9479. return this.start.distanceTo( this.end );
  9480. },
  9481. at: function ( t, optionalTarget ) {
  9482. var result = optionalTarget || new Vector3();
  9483. return this.delta( result ).multiplyScalar( t ).add( this.start );
  9484. },
  9485. closestPointToPointParameter: function () {
  9486. var startP = new Vector3();
  9487. var startEnd = new Vector3();
  9488. return function closestPointToPointParameter( point, clampToLine ) {
  9489. startP.subVectors( point, this.start );
  9490. startEnd.subVectors( this.end, this.start );
  9491. var startEnd2 = startEnd.dot( startEnd );
  9492. var startEnd_startP = startEnd.dot( startP );
  9493. var t = startEnd_startP / startEnd2;
  9494. if ( clampToLine ) {
  9495. t = _Math.clamp( t, 0, 1 );
  9496. }
  9497. return t;
  9498. };
  9499. }(),
  9500. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  9501. var t = this.closestPointToPointParameter( point, clampToLine );
  9502. var result = optionalTarget || new Vector3();
  9503. return this.delta( result ).multiplyScalar( t ).add( this.start );
  9504. },
  9505. applyMatrix4: function ( matrix ) {
  9506. this.start.applyMatrix4( matrix );
  9507. this.end.applyMatrix4( matrix );
  9508. return this;
  9509. },
  9510. equals: function ( line ) {
  9511. return line.start.equals( this.start ) && line.end.equals( this.end );
  9512. }
  9513. } );
  9514. /**
  9515. * @author bhouston / http://clara.io
  9516. */
  9517. function Plane( normal, constant ) {
  9518. // normal is assumed to be normalized
  9519. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  9520. this.constant = ( constant !== undefined ) ? constant : 0;
  9521. }
  9522. Object.assign( Plane.prototype, {
  9523. set: function ( normal, constant ) {
  9524. this.normal.copy( normal );
  9525. this.constant = constant;
  9526. return this;
  9527. },
  9528. setComponents: function ( x, y, z, w ) {
  9529. this.normal.set( x, y, z );
  9530. this.constant = w;
  9531. return this;
  9532. },
  9533. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  9534. this.normal.copy( normal );
  9535. this.constant = - point.dot( this.normal );
  9536. return this;
  9537. },
  9538. setFromCoplanarPoints: function () {
  9539. var v1 = new Vector3();
  9540. var v2 = new Vector3();
  9541. return function setFromCoplanarPoints( a, b, c ) {
  9542. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  9543. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  9544. this.setFromNormalAndCoplanarPoint( normal, a );
  9545. return this;
  9546. };
  9547. }(),
  9548. clone: function () {
  9549. return new this.constructor().copy( this );
  9550. },
  9551. copy: function ( plane ) {
  9552. this.normal.copy( plane.normal );
  9553. this.constant = plane.constant;
  9554. return this;
  9555. },
  9556. normalize: function () {
  9557. // Note: will lead to a divide by zero if the plane is invalid.
  9558. var inverseNormalLength = 1.0 / this.normal.length();
  9559. this.normal.multiplyScalar( inverseNormalLength );
  9560. this.constant *= inverseNormalLength;
  9561. return this;
  9562. },
  9563. negate: function () {
  9564. this.constant *= - 1;
  9565. this.normal.negate();
  9566. return this;
  9567. },
  9568. distanceToPoint: function ( point ) {
  9569. return this.normal.dot( point ) + this.constant;
  9570. },
  9571. distanceToSphere: function ( sphere ) {
  9572. return this.distanceToPoint( sphere.center ) - sphere.radius;
  9573. },
  9574. projectPoint: function ( point, optionalTarget ) {
  9575. var result = optionalTarget || new Vector3();
  9576. return result.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  9577. },
  9578. intersectLine: function () {
  9579. var v1 = new Vector3();
  9580. return function intersectLine( line, optionalTarget ) {
  9581. var result = optionalTarget || new Vector3();
  9582. var direction = line.delta( v1 );
  9583. var denominator = this.normal.dot( direction );
  9584. if ( denominator === 0 ) {
  9585. // line is coplanar, return origin
  9586. if ( this.distanceToPoint( line.start ) === 0 ) {
  9587. return result.copy( line.start );
  9588. }
  9589. // Unsure if this is the correct method to handle this case.
  9590. return undefined;
  9591. }
  9592. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  9593. if ( t < 0 || t > 1 ) {
  9594. return undefined;
  9595. }
  9596. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  9597. };
  9598. }(),
  9599. intersectsLine: function ( line ) {
  9600. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  9601. var startSign = this.distanceToPoint( line.start );
  9602. var endSign = this.distanceToPoint( line.end );
  9603. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  9604. },
  9605. intersectsBox: function ( box ) {
  9606. return box.intersectsPlane( this );
  9607. },
  9608. intersectsSphere: function ( sphere ) {
  9609. return sphere.intersectsPlane( this );
  9610. },
  9611. coplanarPoint: function ( optionalTarget ) {
  9612. var result = optionalTarget || new Vector3();
  9613. return result.copy( this.normal ).multiplyScalar( - this.constant );
  9614. },
  9615. applyMatrix4: function () {
  9616. var v1 = new Vector3();
  9617. var m1 = new Matrix3();
  9618. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  9619. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  9620. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  9621. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  9622. this.constant = - referencePoint.dot( normal );
  9623. return this;
  9624. };
  9625. }(),
  9626. translate: function ( offset ) {
  9627. this.constant -= offset.dot( this.normal );
  9628. return this;
  9629. },
  9630. equals: function ( plane ) {
  9631. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  9632. }
  9633. } );
  9634. /**
  9635. * @author bhouston / http://clara.io
  9636. * @author mrdoob / http://mrdoob.com/
  9637. */
  9638. function Triangle( a, b, c ) {
  9639. this.a = ( a !== undefined ) ? a : new Vector3();
  9640. this.b = ( b !== undefined ) ? b : new Vector3();
  9641. this.c = ( c !== undefined ) ? c : new Vector3();
  9642. }
  9643. Object.assign( Triangle, {
  9644. normal: function () {
  9645. var v0 = new Vector3();
  9646. return function normal( a, b, c, optionalTarget ) {
  9647. var result = optionalTarget || new Vector3();
  9648. result.subVectors( c, b );
  9649. v0.subVectors( a, b );
  9650. result.cross( v0 );
  9651. var resultLengthSq = result.lengthSq();
  9652. if ( resultLengthSq > 0 ) {
  9653. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  9654. }
  9655. return result.set( 0, 0, 0 );
  9656. };
  9657. }(),
  9658. // static/instance method to calculate barycentric coordinates
  9659. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  9660. barycoordFromPoint: function () {
  9661. var v0 = new Vector3();
  9662. var v1 = new Vector3();
  9663. var v2 = new Vector3();
  9664. return function barycoordFromPoint( point, a, b, c, optionalTarget ) {
  9665. v0.subVectors( c, a );
  9666. v1.subVectors( b, a );
  9667. v2.subVectors( point, a );
  9668. var dot00 = v0.dot( v0 );
  9669. var dot01 = v0.dot( v1 );
  9670. var dot02 = v0.dot( v2 );
  9671. var dot11 = v1.dot( v1 );
  9672. var dot12 = v1.dot( v2 );
  9673. var denom = ( dot00 * dot11 - dot01 * dot01 );
  9674. var result = optionalTarget || new Vector3();
  9675. // collinear or singular triangle
  9676. if ( denom === 0 ) {
  9677. // arbitrary location outside of triangle?
  9678. // not sure if this is the best idea, maybe should be returning undefined
  9679. return result.set( - 2, - 1, - 1 );
  9680. }
  9681. var invDenom = 1 / denom;
  9682. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  9683. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  9684. // barycentric coordinates must always sum to 1
  9685. return result.set( 1 - u - v, v, u );
  9686. };
  9687. }(),
  9688. containsPoint: function () {
  9689. var v1 = new Vector3();
  9690. return function containsPoint( point, a, b, c ) {
  9691. var result = Triangle.barycoordFromPoint( point, a, b, c, v1 );
  9692. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  9693. };
  9694. }()
  9695. } );
  9696. Object.assign( Triangle.prototype, {
  9697. set: function ( a, b, c ) {
  9698. this.a.copy( a );
  9699. this.b.copy( b );
  9700. this.c.copy( c );
  9701. return this;
  9702. },
  9703. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  9704. this.a.copy( points[ i0 ] );
  9705. this.b.copy( points[ i1 ] );
  9706. this.c.copy( points[ i2 ] );
  9707. return this;
  9708. },
  9709. clone: function () {
  9710. return new this.constructor().copy( this );
  9711. },
  9712. copy: function ( triangle ) {
  9713. this.a.copy( triangle.a );
  9714. this.b.copy( triangle.b );
  9715. this.c.copy( triangle.c );
  9716. return this;
  9717. },
  9718. area: function () {
  9719. var v0 = new Vector3();
  9720. var v1 = new Vector3();
  9721. return function area() {
  9722. v0.subVectors( this.c, this.b );
  9723. v1.subVectors( this.a, this.b );
  9724. return v0.cross( v1 ).length() * 0.5;
  9725. };
  9726. }(),
  9727. midpoint: function ( optionalTarget ) {
  9728. var result = optionalTarget || new Vector3();
  9729. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  9730. },
  9731. normal: function ( optionalTarget ) {
  9732. return Triangle.normal( this.a, this.b, this.c, optionalTarget );
  9733. },
  9734. plane: function ( optionalTarget ) {
  9735. var result = optionalTarget || new Plane();
  9736. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  9737. },
  9738. barycoordFromPoint: function ( point, optionalTarget ) {
  9739. return Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  9740. },
  9741. containsPoint: function ( point ) {
  9742. return Triangle.containsPoint( point, this.a, this.b, this.c );
  9743. },
  9744. closestPointToPoint: function () {
  9745. var plane = new Plane();
  9746. var edgeList = [ new Line3(), new Line3(), new Line3() ];
  9747. var projectedPoint = new Vector3();
  9748. var closestPoint = new Vector3();
  9749. return function closestPointToPoint( point, optionalTarget ) {
  9750. var result = optionalTarget || new Vector3();
  9751. var minDistance = Infinity;
  9752. // project the point onto the plane of the triangle
  9753. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  9754. plane.projectPoint( point, projectedPoint );
  9755. // check if the projection lies within the triangle
  9756. if ( this.containsPoint( projectedPoint ) === true ) {
  9757. // if so, this is the closest point
  9758. result.copy( projectedPoint );
  9759. } else {
  9760. // if not, the point falls outside the triangle. the result is the closest point to the triangle's edges or vertices
  9761. edgeList[ 0 ].set( this.a, this.b );
  9762. edgeList[ 1 ].set( this.b, this.c );
  9763. edgeList[ 2 ].set( this.c, this.a );
  9764. for ( var i = 0; i < edgeList.length; i ++ ) {
  9765. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  9766. var distance = projectedPoint.distanceToSquared( closestPoint );
  9767. if ( distance < minDistance ) {
  9768. minDistance = distance;
  9769. result.copy( closestPoint );
  9770. }
  9771. }
  9772. }
  9773. return result;
  9774. };
  9775. }(),
  9776. equals: function ( triangle ) {
  9777. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  9778. }
  9779. } );
  9780. /**
  9781. * @author mrdoob / http://mrdoob.com/
  9782. * @author alteredq / http://alteredqualia.com/
  9783. */
  9784. var materialId = 0;
  9785. function Material() {
  9786. Object.defineProperty( this, 'id', { value: materialId ++ } );
  9787. this.uuid = _Math.generateUUID();
  9788. this.name = '';
  9789. this.type = 'Material';
  9790. this.fog = true;
  9791. this.lights = true;
  9792. this.blending = NormalBlending;
  9793. this.side = FrontSide;
  9794. this.flatShading = false;
  9795. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  9796. this.opacity = 1;
  9797. this.transparent = false;
  9798. this.blendSrc = SrcAlphaFactor;
  9799. this.blendDst = OneMinusSrcAlphaFactor;
  9800. this.blendEquation = AddEquation;
  9801. this.blendSrcAlpha = null;
  9802. this.blendDstAlpha = null;
  9803. this.blendEquationAlpha = null;
  9804. this.depthFunc = LessEqualDepth;
  9805. this.depthTest = true;
  9806. this.depthWrite = true;
  9807. this.clippingPlanes = null;
  9808. this.clipIntersection = false;
  9809. this.clipShadows = false;
  9810. this.colorWrite = true;
  9811. this.precision = null; // override the renderer's default precision for this material
  9812. this.polygonOffset = false;
  9813. this.polygonOffsetFactor = 0;
  9814. this.polygonOffsetUnits = 0;
  9815. this.dithering = false;
  9816. this.alphaTest = 0;
  9817. this.premultipliedAlpha = false;
  9818. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  9819. this.visible = true;
  9820. this.userData = {};
  9821. this.needsUpdate = true;
  9822. }
  9823. Object.assign( Material.prototype, EventDispatcher.prototype, {
  9824. isMaterial: true,
  9825. onBeforeCompile: function () {},
  9826. setValues: function ( values ) {
  9827. if ( values === undefined ) return;
  9828. for ( var key in values ) {
  9829. var newValue = values[ key ];
  9830. if ( newValue === undefined ) {
  9831. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  9832. continue;
  9833. }
  9834. // for backward compatability if shading is set in the constructor
  9835. if ( key === 'shading' ) {
  9836. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  9837. this.flatShading = ( newValue === FlatShading ) ? true : false;
  9838. continue;
  9839. }
  9840. var currentValue = this[ key ];
  9841. if ( currentValue === undefined ) {
  9842. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  9843. continue;
  9844. }
  9845. if ( currentValue && currentValue.isColor ) {
  9846. currentValue.set( newValue );
  9847. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  9848. currentValue.copy( newValue );
  9849. } else if ( key === 'overdraw' ) {
  9850. // ensure overdraw is backwards-compatible with legacy boolean type
  9851. this[ key ] = Number( newValue );
  9852. } else {
  9853. this[ key ] = newValue;
  9854. }
  9855. }
  9856. },
  9857. toJSON: function ( meta ) {
  9858. var isRoot = ( meta === undefined || typeof meta === 'string' );
  9859. if ( isRoot ) {
  9860. meta = {
  9861. textures: {},
  9862. images: {}
  9863. };
  9864. }
  9865. var data = {
  9866. metadata: {
  9867. version: 4.5,
  9868. type: 'Material',
  9869. generator: 'Material.toJSON'
  9870. }
  9871. };
  9872. // standard Material serialization
  9873. data.uuid = this.uuid;
  9874. data.type = this.type;
  9875. if ( this.name !== '' ) data.name = this.name;
  9876. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  9877. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  9878. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  9879. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  9880. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  9881. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  9882. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  9883. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  9884. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  9885. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  9886. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  9887. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  9888. if ( this.bumpMap && this.bumpMap.isTexture ) {
  9889. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  9890. data.bumpScale = this.bumpScale;
  9891. }
  9892. if ( this.normalMap && this.normalMap.isTexture ) {
  9893. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  9894. data.normalScale = this.normalScale.toArray();
  9895. }
  9896. if ( this.displacementMap && this.displacementMap.isTexture ) {
  9897. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  9898. data.displacementScale = this.displacementScale;
  9899. data.displacementBias = this.displacementBias;
  9900. }
  9901. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  9902. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  9903. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  9904. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  9905. if ( this.envMap && this.envMap.isTexture ) {
  9906. data.envMap = this.envMap.toJSON( meta ).uuid;
  9907. data.reflectivity = this.reflectivity; // Scale behind envMap
  9908. }
  9909. if ( this.gradientMap && this.gradientMap.isTexture ) {
  9910. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  9911. }
  9912. if ( this.size !== undefined ) data.size = this.size;
  9913. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  9914. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  9915. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  9916. if ( this.side !== FrontSide ) data.side = this.side;
  9917. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  9918. if ( this.opacity < 1 ) data.opacity = this.opacity;
  9919. if ( this.transparent === true ) data.transparent = this.transparent;
  9920. data.depthFunc = this.depthFunc;
  9921. data.depthTest = this.depthTest;
  9922. data.depthWrite = this.depthWrite;
  9923. // rotation (SpriteMaterial)
  9924. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  9925. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  9926. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  9927. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  9928. if ( this.scale !== undefined ) data.scale = this.scale;
  9929. if ( this.dithering === true ) data.dithering = true;
  9930. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  9931. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  9932. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  9933. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  9934. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  9935. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  9936. if ( this.morphTargets === true ) data.morphTargets = true;
  9937. if ( this.skinning === true ) data.skinning = true;
  9938. if ( this.visible === false ) data.visible = false;
  9939. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  9940. // TODO: Copied from Object3D.toJSON
  9941. function extractFromCache( cache ) {
  9942. var values = [];
  9943. for ( var key in cache ) {
  9944. var data = cache[ key ];
  9945. delete data.metadata;
  9946. values.push( data );
  9947. }
  9948. return values;
  9949. }
  9950. if ( isRoot ) {
  9951. var textures = extractFromCache( meta.textures );
  9952. var images = extractFromCache( meta.images );
  9953. if ( textures.length > 0 ) data.textures = textures;
  9954. if ( images.length > 0 ) data.images = images;
  9955. }
  9956. return data;
  9957. },
  9958. clone: function () {
  9959. return new this.constructor().copy( this );
  9960. },
  9961. copy: function ( source ) {
  9962. this.name = source.name;
  9963. this.fog = source.fog;
  9964. this.lights = source.lights;
  9965. this.blending = source.blending;
  9966. this.side = source.side;
  9967. this.flatShading = source.flatShading;
  9968. this.vertexColors = source.vertexColors;
  9969. this.opacity = source.opacity;
  9970. this.transparent = source.transparent;
  9971. this.blendSrc = source.blendSrc;
  9972. this.blendDst = source.blendDst;
  9973. this.blendEquation = source.blendEquation;
  9974. this.blendSrcAlpha = source.blendSrcAlpha;
  9975. this.blendDstAlpha = source.blendDstAlpha;
  9976. this.blendEquationAlpha = source.blendEquationAlpha;
  9977. this.depthFunc = source.depthFunc;
  9978. this.depthTest = source.depthTest;
  9979. this.depthWrite = source.depthWrite;
  9980. this.colorWrite = source.colorWrite;
  9981. this.precision = source.precision;
  9982. this.polygonOffset = source.polygonOffset;
  9983. this.polygonOffsetFactor = source.polygonOffsetFactor;
  9984. this.polygonOffsetUnits = source.polygonOffsetUnits;
  9985. this.dithering = source.dithering;
  9986. this.alphaTest = source.alphaTest;
  9987. this.premultipliedAlpha = source.premultipliedAlpha;
  9988. this.overdraw = source.overdraw;
  9989. this.visible = source.visible;
  9990. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  9991. this.clipShadows = source.clipShadows;
  9992. this.clipIntersection = source.clipIntersection;
  9993. var srcPlanes = source.clippingPlanes,
  9994. dstPlanes = null;
  9995. if ( srcPlanes !== null ) {
  9996. var n = srcPlanes.length;
  9997. dstPlanes = new Array( n );
  9998. for ( var i = 0; i !== n; ++ i )
  9999. dstPlanes[ i ] = srcPlanes[ i ].clone();
  10000. }
  10001. this.clippingPlanes = dstPlanes;
  10002. return this;
  10003. },
  10004. dispose: function () {
  10005. this.dispatchEvent( { type: 'dispose' } );
  10006. }
  10007. } );
  10008. /**
  10009. * @author mrdoob / http://mrdoob.com/
  10010. * @author alteredq / http://alteredqualia.com/
  10011. *
  10012. * parameters = {
  10013. * color: <hex>,
  10014. * opacity: <float>,
  10015. * map: new THREE.Texture( <Image> ),
  10016. *
  10017. * lightMap: new THREE.Texture( <Image> ),
  10018. * lightMapIntensity: <float>
  10019. *
  10020. * aoMap: new THREE.Texture( <Image> ),
  10021. * aoMapIntensity: <float>
  10022. *
  10023. * specularMap: new THREE.Texture( <Image> ),
  10024. *
  10025. * alphaMap: new THREE.Texture( <Image> ),
  10026. *
  10027. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10028. * combine: THREE.Multiply,
  10029. * reflectivity: <float>,
  10030. * refractionRatio: <float>,
  10031. *
  10032. * depthTest: <bool>,
  10033. * depthWrite: <bool>,
  10034. *
  10035. * wireframe: <boolean>,
  10036. * wireframeLinewidth: <float>,
  10037. *
  10038. * skinning: <bool>,
  10039. * morphTargets: <bool>
  10040. * }
  10041. */
  10042. function MeshBasicMaterial( parameters ) {
  10043. Material.call( this );
  10044. this.type = 'MeshBasicMaterial';
  10045. this.color = new Color( 0xffffff ); // emissive
  10046. this.map = null;
  10047. this.lightMap = null;
  10048. this.lightMapIntensity = 1.0;
  10049. this.aoMap = null;
  10050. this.aoMapIntensity = 1.0;
  10051. this.specularMap = null;
  10052. this.alphaMap = null;
  10053. this.envMap = null;
  10054. this.combine = MultiplyOperation;
  10055. this.reflectivity = 1;
  10056. this.refractionRatio = 0.98;
  10057. this.wireframe = false;
  10058. this.wireframeLinewidth = 1;
  10059. this.wireframeLinecap = 'round';
  10060. this.wireframeLinejoin = 'round';
  10061. this.skinning = false;
  10062. this.morphTargets = false;
  10063. this.lights = false;
  10064. this.setValues( parameters );
  10065. }
  10066. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  10067. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  10068. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  10069. MeshBasicMaterial.prototype.copy = function ( source ) {
  10070. Material.prototype.copy.call( this, source );
  10071. this.color.copy( source.color );
  10072. this.map = source.map;
  10073. this.lightMap = source.lightMap;
  10074. this.lightMapIntensity = source.lightMapIntensity;
  10075. this.aoMap = source.aoMap;
  10076. this.aoMapIntensity = source.aoMapIntensity;
  10077. this.specularMap = source.specularMap;
  10078. this.alphaMap = source.alphaMap;
  10079. this.envMap = source.envMap;
  10080. this.combine = source.combine;
  10081. this.reflectivity = source.reflectivity;
  10082. this.refractionRatio = source.refractionRatio;
  10083. this.wireframe = source.wireframe;
  10084. this.wireframeLinewidth = source.wireframeLinewidth;
  10085. this.wireframeLinecap = source.wireframeLinecap;
  10086. this.wireframeLinejoin = source.wireframeLinejoin;
  10087. this.skinning = source.skinning;
  10088. this.morphTargets = source.morphTargets;
  10089. return this;
  10090. };
  10091. /**
  10092. * @author mrdoob / http://mrdoob.com/
  10093. * @author alteredq / http://alteredqualia.com/
  10094. * @author mikael emtinger / http://gomo.se/
  10095. * @author jonobr1 / http://jonobr1.com/
  10096. */
  10097. function Mesh( geometry, material ) {
  10098. Object3D.call( this );
  10099. this.type = 'Mesh';
  10100. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  10101. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  10102. this.drawMode = TrianglesDrawMode;
  10103. this.updateMorphTargets();
  10104. }
  10105. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  10106. constructor: Mesh,
  10107. isMesh: true,
  10108. setDrawMode: function ( value ) {
  10109. this.drawMode = value;
  10110. },
  10111. copy: function ( source ) {
  10112. Object3D.prototype.copy.call( this, source );
  10113. this.drawMode = source.drawMode;
  10114. if ( source.morphTargetInfluences !== undefined ) {
  10115. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  10116. }
  10117. if ( source.morphTargetDictionary !== undefined ) {
  10118. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  10119. }
  10120. return this;
  10121. },
  10122. updateMorphTargets: function () {
  10123. var geometry = this.geometry;
  10124. var m, ml, name;
  10125. if ( geometry.isBufferGeometry ) {
  10126. var morphAttributes = geometry.morphAttributes;
  10127. var keys = Object.keys( morphAttributes );
  10128. if ( keys.length > 0 ) {
  10129. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  10130. if ( morphAttribute !== undefined ) {
  10131. this.morphTargetInfluences = [];
  10132. this.morphTargetDictionary = {};
  10133. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  10134. name = morphAttribute[ m ].name || String( m );
  10135. this.morphTargetInfluences.push( 0 );
  10136. this.morphTargetDictionary[ name ] = m;
  10137. }
  10138. }
  10139. }
  10140. } else {
  10141. var morphTargets = geometry.morphTargets;
  10142. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  10143. this.morphTargetInfluences = [];
  10144. this.morphTargetDictionary = {};
  10145. for ( m = 0, ml = morphTargets.length; m < ml; m ++ ) {
  10146. name = morphTargets[ m ].name || String( m );
  10147. this.morphTargetInfluences.push( 0 );
  10148. this.morphTargetDictionary[ name ] = m;
  10149. }
  10150. }
  10151. }
  10152. },
  10153. raycast: ( function () {
  10154. var inverseMatrix = new Matrix4();
  10155. var ray = new Ray();
  10156. var sphere = new Sphere();
  10157. var vA = new Vector3();
  10158. var vB = new Vector3();
  10159. var vC = new Vector3();
  10160. var tempA = new Vector3();
  10161. var tempB = new Vector3();
  10162. var tempC = new Vector3();
  10163. var uvA = new Vector2();
  10164. var uvB = new Vector2();
  10165. var uvC = new Vector2();
  10166. var barycoord = new Vector3();
  10167. var intersectionPoint = new Vector3();
  10168. var intersectionPointWorld = new Vector3();
  10169. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  10170. Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  10171. uv1.multiplyScalar( barycoord.x );
  10172. uv2.multiplyScalar( barycoord.y );
  10173. uv3.multiplyScalar( barycoord.z );
  10174. uv1.add( uv2 ).add( uv3 );
  10175. return uv1.clone();
  10176. }
  10177. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  10178. var intersect;
  10179. if ( material.side === BackSide ) {
  10180. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  10181. } else {
  10182. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  10183. }
  10184. if ( intersect === null ) return null;
  10185. intersectionPointWorld.copy( point );
  10186. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  10187. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  10188. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  10189. return {
  10190. distance: distance,
  10191. point: intersectionPointWorld.clone(),
  10192. object: object
  10193. };
  10194. }
  10195. function checkBufferGeometryIntersection( object, raycaster, ray, position, uv, a, b, c ) {
  10196. vA.fromBufferAttribute( position, a );
  10197. vB.fromBufferAttribute( position, b );
  10198. vC.fromBufferAttribute( position, c );
  10199. var intersection = checkIntersection( object, object.material, raycaster, ray, vA, vB, vC, intersectionPoint );
  10200. if ( intersection ) {
  10201. if ( uv ) {
  10202. uvA.fromBufferAttribute( uv, a );
  10203. uvB.fromBufferAttribute( uv, b );
  10204. uvC.fromBufferAttribute( uv, c );
  10205. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  10206. }
  10207. intersection.face = new Face3( a, b, c, Triangle.normal( vA, vB, vC ) );
  10208. intersection.faceIndex = a;
  10209. }
  10210. return intersection;
  10211. }
  10212. return function raycast( raycaster, intersects ) {
  10213. var geometry = this.geometry;
  10214. var material = this.material;
  10215. var matrixWorld = this.matrixWorld;
  10216. if ( material === undefined ) return;
  10217. // Checking boundingSphere distance to ray
  10218. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10219. sphere.copy( geometry.boundingSphere );
  10220. sphere.applyMatrix4( matrixWorld );
  10221. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  10222. //
  10223. inverseMatrix.getInverse( matrixWorld );
  10224. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  10225. // Check boundingBox before continuing
  10226. if ( geometry.boundingBox !== null ) {
  10227. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  10228. }
  10229. var intersection;
  10230. if ( geometry.isBufferGeometry ) {
  10231. var a, b, c;
  10232. var index = geometry.index;
  10233. var position = geometry.attributes.position;
  10234. var uv = geometry.attributes.uv;
  10235. var i, l;
  10236. if ( index !== null ) {
  10237. // indexed buffer geometry
  10238. for ( i = 0, l = index.count; i < l; i += 3 ) {
  10239. a = index.getX( i );
  10240. b = index.getX( i + 1 );
  10241. c = index.getX( i + 2 );
  10242. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  10243. if ( intersection ) {
  10244. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  10245. intersects.push( intersection );
  10246. }
  10247. }
  10248. } else if ( position !== undefined ) {
  10249. // non-indexed buffer geometry
  10250. for ( i = 0, l = position.count; i < l; i += 3 ) {
  10251. a = i;
  10252. b = i + 1;
  10253. c = i + 2;
  10254. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  10255. if ( intersection ) {
  10256. intersection.index = a; // triangle number in positions buffer semantics
  10257. intersects.push( intersection );
  10258. }
  10259. }
  10260. }
  10261. } else if ( geometry.isGeometry ) {
  10262. var fvA, fvB, fvC;
  10263. var isMultiMaterial = Array.isArray( material );
  10264. var vertices = geometry.vertices;
  10265. var faces = geometry.faces;
  10266. var uvs;
  10267. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  10268. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  10269. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  10270. var face = faces[ f ];
  10271. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  10272. if ( faceMaterial === undefined ) continue;
  10273. fvA = vertices[ face.a ];
  10274. fvB = vertices[ face.b ];
  10275. fvC = vertices[ face.c ];
  10276. if ( faceMaterial.morphTargets === true ) {
  10277. var morphTargets = geometry.morphTargets;
  10278. var morphInfluences = this.morphTargetInfluences;
  10279. vA.set( 0, 0, 0 );
  10280. vB.set( 0, 0, 0 );
  10281. vC.set( 0, 0, 0 );
  10282. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  10283. var influence = morphInfluences[ t ];
  10284. if ( influence === 0 ) continue;
  10285. var targets = morphTargets[ t ].vertices;
  10286. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  10287. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  10288. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  10289. }
  10290. vA.add( fvA );
  10291. vB.add( fvB );
  10292. vC.add( fvC );
  10293. fvA = vA;
  10294. fvB = vB;
  10295. fvC = vC;
  10296. }
  10297. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  10298. if ( intersection ) {
  10299. if ( uvs && uvs[ f ] ) {
  10300. var uvs_f = uvs[ f ];
  10301. uvA.copy( uvs_f[ 0 ] );
  10302. uvB.copy( uvs_f[ 1 ] );
  10303. uvC.copy( uvs_f[ 2 ] );
  10304. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  10305. }
  10306. intersection.face = face;
  10307. intersection.faceIndex = f;
  10308. intersects.push( intersection );
  10309. }
  10310. }
  10311. }
  10312. };
  10313. }() ),
  10314. clone: function () {
  10315. return new this.constructor( this.geometry, this.material ).copy( this );
  10316. }
  10317. } );
  10318. /**
  10319. * @author TristanVALCKE / https://github.com/Itee
  10320. * @author Anonymous
  10321. */
  10322. /* global QUnit */
  10323. QUnit.module( 'Animation', () => {
  10324. QUnit.module.todo( 'PropertyBinding', () => {
  10325. // INSTANCING
  10326. QUnit.test( "Instancing", ( assert ) => {
  10327. assert.ok( false, "everything's gonna be alright" );
  10328. } );
  10329. // STATIC STUFF
  10330. QUnit.test( "Composite", ( assert ) => {
  10331. assert.ok( false, "everything's gonna be alright" );
  10332. } );
  10333. QUnit.test( "create", ( assert ) => {
  10334. assert.ok( false, "everything's gonna be alright" );
  10335. } );
  10336. QUnit.test( 'sanitizeNodeName', ( assert ) => {
  10337. assert.equal(
  10338. PropertyBinding.sanitizeNodeName( 'valid-name-123_' ),
  10339. 'valid-name-123_',
  10340. 'Leaves valid name intact.'
  10341. );
  10342. assert.equal(
  10343. PropertyBinding.sanitizeNodeName( 'space separated name 123_ -' ),
  10344. 'space_separated_name_123__-',
  10345. 'Replaces spaces with underscores.'
  10346. );
  10347. assert.equal(
  10348. PropertyBinding.sanitizeNodeName( '"invalid" name %123%_' ),
  10349. 'invalid_name_123_',
  10350. 'Strips invalid characters.'
  10351. );
  10352. } );
  10353. QUnit.test( 'parseTrackName', ( assert ) => {
  10354. var paths = [
  10355. [
  10356. '.property',
  10357. {
  10358. nodeName: undefined,
  10359. objectName: undefined,
  10360. objectIndex: undefined,
  10361. propertyName: 'property',
  10362. propertyIndex: undefined
  10363. }
  10364. ],
  10365. [
  10366. 'nodeName.property',
  10367. {
  10368. nodeName: 'nodeName',
  10369. objectName: undefined,
  10370. objectIndex: undefined,
  10371. propertyName: 'property',
  10372. propertyIndex: undefined
  10373. }
  10374. ],
  10375. [
  10376. 'a.property',
  10377. {
  10378. nodeName: 'a',
  10379. objectName: undefined,
  10380. objectIndex: undefined,
  10381. propertyName: 'property',
  10382. propertyIndex: undefined
  10383. }
  10384. ],
  10385. [
  10386. 'no.de.Name.property',
  10387. {
  10388. nodeName: 'no.de.Name',
  10389. objectName: undefined,
  10390. objectIndex: undefined,
  10391. propertyName: 'property',
  10392. propertyIndex: undefined
  10393. }
  10394. ],
  10395. [
  10396. 'no.d-e.Name.property',
  10397. {
  10398. nodeName: 'no.d-e.Name',
  10399. objectName: undefined,
  10400. objectIndex: undefined,
  10401. propertyName: 'property',
  10402. propertyIndex: undefined
  10403. }
  10404. ],
  10405. [
  10406. 'nodeName.property[accessor]',
  10407. {
  10408. nodeName: 'nodeName',
  10409. objectName: undefined,
  10410. objectIndex: undefined,
  10411. propertyName: 'property',
  10412. propertyIndex: 'accessor'
  10413. }
  10414. ],
  10415. [
  10416. 'nodeName.material.property[accessor]',
  10417. {
  10418. nodeName: 'nodeName',
  10419. objectName: 'material',
  10420. objectIndex: undefined,
  10421. propertyName: 'property',
  10422. propertyIndex: 'accessor'
  10423. }
  10424. ],
  10425. [
  10426. 'no.de.Name.material.property',
  10427. {
  10428. nodeName: 'no.de.Name',
  10429. objectName: 'material',
  10430. objectIndex: undefined,
  10431. propertyName: 'property',
  10432. propertyIndex: undefined
  10433. }
  10434. ],
  10435. [
  10436. 'no.de.Name.material[materialIndex].property',
  10437. {
  10438. nodeName: 'no.de.Name',
  10439. objectName: 'material',
  10440. objectIndex: 'materialIndex',
  10441. propertyName: 'property',
  10442. propertyIndex: undefined
  10443. }
  10444. ],
  10445. [
  10446. 'uuid.property[accessor]',
  10447. {
  10448. nodeName: 'uuid',
  10449. objectName: undefined,
  10450. objectIndex: undefined,
  10451. propertyName: 'property',
  10452. propertyIndex: 'accessor'
  10453. }
  10454. ],
  10455. [
  10456. 'uuid.objectName[objectIndex].propertyName[propertyIndex]',
  10457. {
  10458. nodeName: 'uuid',
  10459. objectName: 'objectName',
  10460. objectIndex: 'objectIndex',
  10461. propertyName: 'propertyName',
  10462. propertyIndex: 'propertyIndex'
  10463. }
  10464. ],
  10465. [
  10466. 'parentName/nodeName.property',
  10467. {
  10468. // directoryName is currently unused.
  10469. nodeName: 'nodeName',
  10470. objectName: undefined,
  10471. objectIndex: undefined,
  10472. propertyName: 'property',
  10473. propertyIndex: undefined
  10474. }
  10475. ],
  10476. [
  10477. 'parentName/no.de.Name.property',
  10478. {
  10479. // directoryName is currently unused.
  10480. nodeName: 'no.de.Name',
  10481. objectName: undefined,
  10482. objectIndex: undefined,
  10483. propertyName: 'property',
  10484. propertyIndex: undefined
  10485. }
  10486. ],
  10487. [
  10488. 'parentName/parentName/nodeName.property[index]',
  10489. {
  10490. // directoryName is currently unused.
  10491. nodeName: 'nodeName',
  10492. objectName: undefined,
  10493. objectIndex: undefined,
  10494. propertyName: 'property',
  10495. propertyIndex: 'index'
  10496. }
  10497. ],
  10498. [
  10499. '.bone[Armature.DEF_cog].position',
  10500. {
  10501. nodeName: undefined,
  10502. objectName: 'bone',
  10503. objectIndex: 'Armature.DEF_cog',
  10504. propertyName: 'position',
  10505. propertyIndex: undefined
  10506. }
  10507. ],
  10508. [
  10509. 'scene:helium_balloon_model:helium_balloon_model.position',
  10510. {
  10511. nodeName: 'helium_balloon_model',
  10512. objectName: undefined,
  10513. objectIndex: undefined,
  10514. propertyName: 'position',
  10515. propertyIndex: undefined
  10516. }
  10517. ]
  10518. ];
  10519. paths.forEach( function ( path ) {
  10520. assert.smartEqual(
  10521. PropertyBinding.parseTrackName( path[ 0 ] ),
  10522. path[ 1 ],
  10523. 'Parses track name: ' + path[ 0 ]
  10524. );
  10525. } );
  10526. } );
  10527. QUnit.test( "findNode", ( assert ) => {
  10528. assert.ok( false, "everything's gonna be alright" );
  10529. } );
  10530. // PUBLIC STUFF
  10531. QUnit.test( "BindingType", ( assert ) => {
  10532. assert.ok( false, "everything's gonna be alright" );
  10533. } );
  10534. QUnit.test( "Versioning", ( assert ) => {
  10535. assert.ok( false, "everything's gonna be alright" );
  10536. } );
  10537. QUnit.test( "GetterByBindingType", ( assert ) => {
  10538. assert.ok( false, "everything's gonna be alright" );
  10539. } );
  10540. QUnit.test( "SetterByBindingTypeAndVersioning", ( assert ) => {
  10541. assert.ok( false, "everything's gonna be alright" );
  10542. } );
  10543. QUnit.test( "getValue", ( assert ) => {
  10544. assert.ok( false, "everything's gonna be alright" );
  10545. } );
  10546. QUnit.test( 'setValue', ( assert ) => {
  10547. var paths = [
  10548. '.material.opacity',
  10549. '.material[opacity]'
  10550. ];
  10551. paths.forEach( function ( path ) {
  10552. var originalValue = 0;
  10553. var expectedValue = 1;
  10554. var geometry = new BoxGeometry();
  10555. var material = new MeshBasicMaterial();
  10556. material.opacity = originalValue;
  10557. var mesh = new Mesh( geometry, material );
  10558. var binding = new PropertyBinding( mesh, path, null );
  10559. binding.bind();
  10560. assert.equal(
  10561. material.opacity,
  10562. originalValue,
  10563. 'Sets property of material with "' + path + '" (pre-setValue)'
  10564. );
  10565. binding.setValue( [ expectedValue ], 0 );
  10566. assert.equal(
  10567. material.opacity,
  10568. expectedValue,
  10569. 'Sets property of material with "' + path + '" (post-setValue)'
  10570. );
  10571. } );
  10572. } );
  10573. QUnit.test( "bind", ( assert ) => {
  10574. assert.ok( false, "everything's gonna be alright" );
  10575. } );
  10576. QUnit.test( "unbind", ( assert ) => {
  10577. assert.ok( false, "everything's gonna be alright" );
  10578. } );
  10579. // OTHERS
  10580. QUnit.test( "_getValue_unavailable", ( assert ) => {
  10581. assert.ok( false, "everything's gonna be alright" );
  10582. } );
  10583. QUnit.test( "_setValue_unavailable", ( assert ) => {
  10584. assert.ok( false, "everything's gonna be alright" );
  10585. } );
  10586. } );
  10587. } );
  10588. /**
  10589. * @author TristanVALCKE / https://github.com/Itee
  10590. */
  10591. /* global QUnit */
  10592. QUnit.module( 'Animation', () => {
  10593. QUnit.module.todo( 'PropertyMixer', () => {
  10594. // INSTANCING
  10595. QUnit.test( "Instancing", ( assert ) => {
  10596. assert.ok( false, "everything's gonna be alright" );
  10597. } );
  10598. // PRIVATE STUFF
  10599. QUnit.test( "_select", ( assert ) => {
  10600. assert.ok( false, "everything's gonna be alright" );
  10601. } );
  10602. QUnit.test( "_slerp", ( assert ) => {
  10603. assert.ok( false, "everything's gonna be alright" );
  10604. } );
  10605. QUnit.test( "_lerp", ( assert ) => {
  10606. assert.ok( false, "everything's gonna be alright" );
  10607. } );
  10608. // PUBLIC STUFF
  10609. QUnit.test( "accumulate", ( assert ) => {
  10610. assert.ok( false, "everything's gonna be alright" );
  10611. } );
  10612. QUnit.test( "apply", ( assert ) => {
  10613. assert.ok( false, "everything's gonna be alright" );
  10614. } );
  10615. QUnit.test( "saveOriginalState", ( assert ) => {
  10616. assert.ok( false, "everything's gonna be alright" );
  10617. } );
  10618. QUnit.test( "restoreOriginalState", ( assert ) => {
  10619. assert.ok( false, "everything's gonna be alright" );
  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( 'BooleanKeyframeTrack', () => {
  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( 'ColorKeyframeTrack', () => {
  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( 'NumberKeyframeTrack', () => {
  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( 'QuaternionKeyframeTrack', () => {
  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( 'StringKeyframeTrack', () => {
  10682. QUnit.test( 'write me !', ( assert ) => {
  10683. assert.ok( false, "everything's gonna be alright" );
  10684. } );
  10685. } );
  10686. } );
  10687. } );
  10688. /**
  10689. * @author TristanVALCKE / https://github.com/Itee
  10690. */
  10691. /* global QUnit */
  10692. QUnit.module( 'Animation', () => {
  10693. QUnit.module( 'Tracks', () => {
  10694. QUnit.module.todo( 'VectorKeyframeTrack', () => {
  10695. QUnit.test( 'write me !', ( assert ) => {
  10696. assert.ok( false, "everything's gonna be alright" );
  10697. } );
  10698. } );
  10699. } );
  10700. } );
  10701. /**
  10702. * @author mrdoob / http://mrdoob.com/
  10703. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  10704. */
  10705. function Audio( listener ) {
  10706. Object3D.call( this );
  10707. this.type = 'Audio';
  10708. this.context = listener.context;
  10709. this.gain = this.context.createGain();
  10710. this.gain.connect( listener.getInput() );
  10711. this.autoplay = false;
  10712. this.buffer = null;
  10713. this.loop = false;
  10714. this.startTime = 0;
  10715. this.offset = 0;
  10716. this.playbackRate = 1;
  10717. this.isPlaying = false;
  10718. this.hasPlaybackControl = true;
  10719. this.sourceType = 'empty';
  10720. this.filters = [];
  10721. }
  10722. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  10723. constructor: Audio,
  10724. getOutput: function () {
  10725. return this.gain;
  10726. },
  10727. setNodeSource: function ( audioNode ) {
  10728. this.hasPlaybackControl = false;
  10729. this.sourceType = 'audioNode';
  10730. this.source = audioNode;
  10731. this.connect();
  10732. return this;
  10733. },
  10734. setBuffer: function ( audioBuffer ) {
  10735. this.buffer = audioBuffer;
  10736. this.sourceType = 'buffer';
  10737. if ( this.autoplay ) this.play();
  10738. return this;
  10739. },
  10740. play: function () {
  10741. if ( this.isPlaying === true ) {
  10742. console.warn( 'THREE.Audio: Audio is already playing.' );
  10743. return;
  10744. }
  10745. if ( this.hasPlaybackControl === false ) {
  10746. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10747. return;
  10748. }
  10749. var source = this.context.createBufferSource();
  10750. source.buffer = this.buffer;
  10751. source.loop = this.loop;
  10752. source.onended = this.onEnded.bind( this );
  10753. source.playbackRate.setValueAtTime( this.playbackRate, this.startTime );
  10754. this.startTime = this.context.currentTime;
  10755. source.start( this.startTime, this.offset );
  10756. this.isPlaying = true;
  10757. this.source = source;
  10758. return this.connect();
  10759. },
  10760. pause: function () {
  10761. if ( this.hasPlaybackControl === false ) {
  10762. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10763. return;
  10764. }
  10765. if ( this.isPlaying === true ) {
  10766. this.source.stop();
  10767. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  10768. this.isPlaying = false;
  10769. }
  10770. return this;
  10771. },
  10772. stop: function () {
  10773. if ( this.hasPlaybackControl === false ) {
  10774. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10775. return;
  10776. }
  10777. this.source.stop();
  10778. this.offset = 0;
  10779. this.isPlaying = false;
  10780. return this;
  10781. },
  10782. connect: function () {
  10783. if ( this.filters.length > 0 ) {
  10784. this.source.connect( this.filters[ 0 ] );
  10785. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  10786. this.filters[ i - 1 ].connect( this.filters[ i ] );
  10787. }
  10788. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  10789. } else {
  10790. this.source.connect( this.getOutput() );
  10791. }
  10792. return this;
  10793. },
  10794. disconnect: function () {
  10795. if ( this.filters.length > 0 ) {
  10796. this.source.disconnect( this.filters[ 0 ] );
  10797. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  10798. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  10799. }
  10800. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  10801. } else {
  10802. this.source.disconnect( this.getOutput() );
  10803. }
  10804. return this;
  10805. },
  10806. getFilters: function () {
  10807. return this.filters;
  10808. },
  10809. setFilters: function ( value ) {
  10810. if ( ! value ) value = [];
  10811. if ( this.isPlaying === true ) {
  10812. this.disconnect();
  10813. this.filters = value;
  10814. this.connect();
  10815. } else {
  10816. this.filters = value;
  10817. }
  10818. return this;
  10819. },
  10820. getFilter: function () {
  10821. return this.getFilters()[ 0 ];
  10822. },
  10823. setFilter: function ( filter ) {
  10824. return this.setFilters( filter ? [ filter ] : [] );
  10825. },
  10826. setPlaybackRate: function ( value ) {
  10827. if ( this.hasPlaybackControl === false ) {
  10828. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10829. return;
  10830. }
  10831. this.playbackRate = value;
  10832. if ( this.isPlaying === true ) {
  10833. this.source.playbackRate.setValueAtTime( this.playbackRate, this.context.currentTime );
  10834. }
  10835. return this;
  10836. },
  10837. getPlaybackRate: function () {
  10838. return this.playbackRate;
  10839. },
  10840. onEnded: function () {
  10841. this.isPlaying = false;
  10842. },
  10843. getLoop: function () {
  10844. if ( this.hasPlaybackControl === false ) {
  10845. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10846. return false;
  10847. }
  10848. return this.loop;
  10849. },
  10850. setLoop: function ( value ) {
  10851. if ( this.hasPlaybackControl === false ) {
  10852. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10853. return;
  10854. }
  10855. this.loop = value;
  10856. if ( this.isPlaying === true ) {
  10857. this.source.loop = this.loop;
  10858. }
  10859. return this;
  10860. },
  10861. getVolume: function () {
  10862. return this.gain.gain.value;
  10863. },
  10864. setVolume: function ( value ) {
  10865. this.gain.gain.value = value;
  10866. return this;
  10867. }
  10868. } );
  10869. /**
  10870. * @author TristanVALCKE / https://github.com/Itee
  10871. */
  10872. /* global QUnit */
  10873. QUnit.module( 'Audios', () => {
  10874. QUnit.module.todo( 'Audio', () => {
  10875. // INHERITANCE
  10876. QUnit.test( "Extending", ( assert ) => {
  10877. assert.ok( false, "everything's gonna be alright" );
  10878. } );
  10879. // INSTANCING
  10880. QUnit.test( "Instancing", ( assert ) => {
  10881. assert.ok( false, "everything's gonna be alright" );
  10882. } );
  10883. // PUBLIC STUFF
  10884. QUnit.test( "getOutput", ( assert ) => {
  10885. assert.ok( false, "everything's gonna be alright" );
  10886. } );
  10887. QUnit.test( "setNodeSource", ( assert ) => {
  10888. assert.ok( false, "everything's gonna be alright" );
  10889. } );
  10890. QUnit.test( "setBuffer", ( assert ) => {
  10891. assert.ok( false, "everything's gonna be alright" );
  10892. } );
  10893. QUnit.test( "play", ( assert ) => {
  10894. assert.ok( false, "everything's gonna be alright" );
  10895. } );
  10896. QUnit.test( "pause", ( assert ) => {
  10897. assert.ok( false, "everything's gonna be alright" );
  10898. } );
  10899. QUnit.test( "stop", ( assert ) => {
  10900. assert.ok( false, "everything's gonna be alright" );
  10901. } );
  10902. QUnit.test( "connect", ( assert ) => {
  10903. assert.ok( false, "everything's gonna be alright" );
  10904. } );
  10905. QUnit.test( "disconnect", ( assert ) => {
  10906. assert.ok( false, "everything's gonna be alright" );
  10907. } );
  10908. QUnit.test( "getFilters", ( assert ) => {
  10909. assert.ok( false, "everything's gonna be alright" );
  10910. } );
  10911. QUnit.test( "setFilters", ( assert ) => {
  10912. assert.ok( false, "everything's gonna be alright" );
  10913. } );
  10914. QUnit.test( "getFilter", ( assert ) => {
  10915. assert.ok( false, "everything's gonna be alright" );
  10916. } );
  10917. QUnit.test( "setFilter", ( assert ) => {
  10918. assert.ok( false, "everything's gonna be alright" );
  10919. } );
  10920. QUnit.test( "setPlaybackRate", ( assert ) => {
  10921. assert.ok( false, "everything's gonna be alright" );
  10922. } );
  10923. QUnit.test( "getPlaybackRate", ( assert ) => {
  10924. assert.ok( false, "everything's gonna be alright" );
  10925. } );
  10926. QUnit.test( "onEnded", ( assert ) => {
  10927. assert.ok( false, "everything's gonna be alright" );
  10928. } );
  10929. QUnit.test( "getLoop", ( assert ) => {
  10930. assert.ok( false, "everything's gonna be alright" );
  10931. } );
  10932. QUnit.test( "setLoop", ( assert ) => {
  10933. assert.ok( false, "everything's gonna be alright" );
  10934. } );
  10935. QUnit.test( "getVolume", ( assert ) => {
  10936. assert.ok( false, "everything's gonna be alright" );
  10937. } );
  10938. QUnit.test( "setVolume", ( assert ) => {
  10939. assert.ok( false, "everything's gonna be alright" );
  10940. } );
  10941. } );
  10942. } );
  10943. /**
  10944. * @author mrdoob / http://mrdoob.com/
  10945. */
  10946. function AudioAnalyser( audio, fftSize ) {
  10947. this.analyser = audio.context.createAnalyser();
  10948. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  10949. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  10950. audio.getOutput().connect( this.analyser );
  10951. }
  10952. Object.assign( AudioAnalyser.prototype, {
  10953. getFrequencyData: function () {
  10954. this.analyser.getByteFrequencyData( this.data );
  10955. return this.data;
  10956. },
  10957. getAverageFrequency: function () {
  10958. var value = 0, data = this.getFrequencyData();
  10959. for ( var i = 0; i < data.length; i ++ ) {
  10960. value += data[ i ];
  10961. }
  10962. return value / data.length;
  10963. }
  10964. } );
  10965. /**
  10966. * @author TristanVALCKE / https://github.com/Itee
  10967. */
  10968. /* global QUnit */
  10969. QUnit.module( 'Audios', () => {
  10970. QUnit.module.todo( 'AudioAnalyser', () => {
  10971. // INSTANCING
  10972. QUnit.test( "Instancing", ( assert ) => {
  10973. assert.ok( false, "everything's gonna be alright" );
  10974. } );
  10975. // PUBLIC STUFF
  10976. QUnit.test( "getFrequencyData", ( assert ) => {
  10977. assert.ok( false, "everything's gonna be alright" );
  10978. } );
  10979. QUnit.test( "getAverageFrequency", ( assert ) => {
  10980. assert.ok( false, "everything's gonna be alright" );
  10981. } );
  10982. } );
  10983. } );
  10984. var context;
  10985. var AudioContext = {
  10986. getContext: function () {
  10987. if ( context === undefined ) {
  10988. context = new ( window.AudioContext || window.webkitAudioContext )();
  10989. }
  10990. return context;
  10991. },
  10992. setContext: function ( value ) {
  10993. context = value;
  10994. }
  10995. };
  10996. /**
  10997. * @author TristanVALCKE / https://github.com/Itee
  10998. */
  10999. /* global QUnit */
  11000. QUnit.module( 'Audios', () => {
  11001. QUnit.module.todo( 'AudioContext', () => {
  11002. // PUBLIC STUFF
  11003. QUnit.test( "getContext", ( assert ) => {
  11004. assert.ok( false, "everything's gonna be alright" );
  11005. } );
  11006. QUnit.test( "setContext", ( assert ) => {
  11007. assert.ok( false, "everything's gonna be alright" );
  11008. } );
  11009. } );
  11010. } );
  11011. /**
  11012. * @author mrdoob / http://mrdoob.com/
  11013. */
  11014. function AudioListener() {
  11015. Object3D.call( this );
  11016. this.type = 'AudioListener';
  11017. this.context = AudioContext.getContext();
  11018. this.gain = this.context.createGain();
  11019. this.gain.connect( this.context.destination );
  11020. this.filter = null;
  11021. }
  11022. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  11023. constructor: AudioListener,
  11024. getInput: function () {
  11025. return this.gain;
  11026. },
  11027. removeFilter: function ( ) {
  11028. if ( this.filter !== null ) {
  11029. this.gain.disconnect( this.filter );
  11030. this.filter.disconnect( this.context.destination );
  11031. this.gain.connect( this.context.destination );
  11032. this.filter = null;
  11033. }
  11034. },
  11035. getFilter: function () {
  11036. return this.filter;
  11037. },
  11038. setFilter: function ( value ) {
  11039. if ( this.filter !== null ) {
  11040. this.gain.disconnect( this.filter );
  11041. this.filter.disconnect( this.context.destination );
  11042. } else {
  11043. this.gain.disconnect( this.context.destination );
  11044. }
  11045. this.filter = value;
  11046. this.gain.connect( this.filter );
  11047. this.filter.connect( this.context.destination );
  11048. },
  11049. getMasterVolume: function () {
  11050. return this.gain.gain.value;
  11051. },
  11052. setMasterVolume: function ( value ) {
  11053. this.gain.gain.value = value;
  11054. },
  11055. updateMatrixWorld: ( function () {
  11056. var position = new Vector3();
  11057. var quaternion = new Quaternion();
  11058. var scale = new Vector3();
  11059. var orientation = new Vector3();
  11060. return function updateMatrixWorld( force ) {
  11061. Object3D.prototype.updateMatrixWorld.call( this, force );
  11062. var listener = this.context.listener;
  11063. var up = this.up;
  11064. this.matrixWorld.decompose( position, quaternion, scale );
  11065. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  11066. if ( listener.positionX ) {
  11067. listener.positionX.setValueAtTime( position.x, this.context.currentTime );
  11068. listener.positionY.setValueAtTime( position.y, this.context.currentTime );
  11069. listener.positionZ.setValueAtTime( position.z, this.context.currentTime );
  11070. listener.forwardX.setValueAtTime( orientation.x, this.context.currentTime );
  11071. listener.forwardY.setValueAtTime( orientation.y, this.context.currentTime );
  11072. listener.forwardZ.setValueAtTime( orientation.z, this.context.currentTime );
  11073. listener.upX.setValueAtTime( up.x, this.context.currentTime );
  11074. listener.upY.setValueAtTime( up.y, this.context.currentTime );
  11075. listener.upZ.setValueAtTime( up.z, this.context.currentTime );
  11076. } else {
  11077. listener.setPosition( position.x, position.y, position.z );
  11078. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  11079. }
  11080. };
  11081. } )()
  11082. } );
  11083. /**
  11084. * @author TristanVALCKE / https://github.com/Itee
  11085. */
  11086. /* global QUnit */
  11087. QUnit.module( 'Audios', () => {
  11088. QUnit.module.todo( 'AudioListener', () => {
  11089. // INHERITANCE
  11090. QUnit.test( "Extending", ( assert ) => {
  11091. assert.ok( false, "everything's gonna be alright" );
  11092. } );
  11093. // INSTANCING
  11094. QUnit.test( "Instancing", ( assert ) => {
  11095. assert.ok( false, "everything's gonna be alright" );
  11096. } );
  11097. // PUBLIC STUFF
  11098. QUnit.test( "getInput", ( assert ) => {
  11099. assert.ok( false, "everything's gonna be alright" );
  11100. } );
  11101. QUnit.test( "removeFilter", ( assert ) => {
  11102. assert.ok( false, "everything's gonna be alright" );
  11103. } );
  11104. QUnit.test( "getFilter", ( assert ) => {
  11105. assert.ok( false, "everything's gonna be alright" );
  11106. } );
  11107. QUnit.test( "setFilter", ( assert ) => {
  11108. assert.ok( false, "everything's gonna be alright" );
  11109. } );
  11110. QUnit.test( "getMasterVolume", ( assert ) => {
  11111. assert.ok( false, "everything's gonna be alright" );
  11112. } );
  11113. QUnit.test( "setMasterVolume", ( assert ) => {
  11114. assert.ok( false, "everything's gonna be alright" );
  11115. } );
  11116. QUnit.test( "updateMatrixWorld", ( assert ) => {
  11117. assert.ok( false, "everything's gonna be alright" );
  11118. } );
  11119. } );
  11120. } );
  11121. /**
  11122. * @author mrdoob / http://mrdoob.com/
  11123. */
  11124. function PositionalAudio( listener ) {
  11125. Audio.call( this, listener );
  11126. this.panner = this.context.createPanner();
  11127. this.panner.connect( this.gain );
  11128. }
  11129. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  11130. constructor: PositionalAudio,
  11131. getOutput: function () {
  11132. return this.panner;
  11133. },
  11134. getRefDistance: function () {
  11135. return this.panner.refDistance;
  11136. },
  11137. setRefDistance: function ( value ) {
  11138. this.panner.refDistance = value;
  11139. },
  11140. getRolloffFactor: function () {
  11141. return this.panner.rolloffFactor;
  11142. },
  11143. setRolloffFactor: function ( value ) {
  11144. this.panner.rolloffFactor = value;
  11145. },
  11146. getDistanceModel: function () {
  11147. return this.panner.distanceModel;
  11148. },
  11149. setDistanceModel: function ( value ) {
  11150. this.panner.distanceModel = value;
  11151. },
  11152. getMaxDistance: function () {
  11153. return this.panner.maxDistance;
  11154. },
  11155. setMaxDistance: function ( value ) {
  11156. this.panner.maxDistance = value;
  11157. },
  11158. updateMatrixWorld: ( function () {
  11159. var position = new Vector3();
  11160. return function updateMatrixWorld( force ) {
  11161. Object3D.prototype.updateMatrixWorld.call( this, force );
  11162. position.setFromMatrixPosition( this.matrixWorld );
  11163. this.panner.setPosition( position.x, position.y, position.z );
  11164. };
  11165. } )()
  11166. } );
  11167. /**
  11168. * @author TristanVALCKE / https://github.com/Itee
  11169. */
  11170. /* global QUnit */
  11171. QUnit.module( 'Audios', () => {
  11172. QUnit.module.todo( 'PositionalAudio', () => {
  11173. // INHERITANCE
  11174. QUnit.test( "Extending", ( assert ) => {
  11175. assert.ok( false, "everything's gonna be alright" );
  11176. } );
  11177. // INSTANCING
  11178. QUnit.test( "Instancing", ( assert ) => {
  11179. assert.ok( false, "everything's gonna be alright" );
  11180. } );
  11181. // PUBLIC STUFF
  11182. QUnit.test( "getOutput", ( assert ) => {
  11183. assert.ok( false, "everything's gonna be alright" );
  11184. } );
  11185. QUnit.test( "getRefDistance", ( assert ) => {
  11186. assert.ok( false, "everything's gonna be alright" );
  11187. } );
  11188. QUnit.test( "setRefDistance", ( assert ) => {
  11189. assert.ok( false, "everything's gonna be alright" );
  11190. } );
  11191. QUnit.test( "getRolloffFactor", ( assert ) => {
  11192. assert.ok( false, "everything's gonna be alright" );
  11193. } );
  11194. QUnit.test( "setRolloffFactor", ( assert ) => {
  11195. assert.ok( false, "everything's gonna be alright" );
  11196. } );
  11197. QUnit.test( "getDistanceModel", ( assert ) => {
  11198. assert.ok( false, "everything's gonna be alright" );
  11199. } );
  11200. QUnit.test( "setDistanceModel", ( assert ) => {
  11201. assert.ok( false, "everything's gonna be alright" );
  11202. } );
  11203. QUnit.test( "getMaxDistance", ( assert ) => {
  11204. assert.ok( false, "everything's gonna be alright" );
  11205. } );
  11206. QUnit.test( "setMaxDistance", ( assert ) => {
  11207. assert.ok( false, "everything's gonna be alright" );
  11208. } );
  11209. QUnit.test( "updateMatrixWorld", ( assert ) => {
  11210. assert.ok( false, "everything's gonna be alright" );
  11211. } );
  11212. } );
  11213. } );
  11214. /**
  11215. * @author mrdoob / http://mrdoob.com/
  11216. * @author mikael emtinger / http://gomo.se/
  11217. * @author WestLangley / http://github.com/WestLangley
  11218. */
  11219. function Camera() {
  11220. Object3D.call( this );
  11221. this.type = 'Camera';
  11222. this.matrixWorldInverse = new Matrix4();
  11223. this.projectionMatrix = new Matrix4();
  11224. }
  11225. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  11226. constructor: Camera,
  11227. isCamera: true,
  11228. copy: function ( source, recursive ) {
  11229. Object3D.prototype.copy.call( this, source, recursive );
  11230. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  11231. this.projectionMatrix.copy( source.projectionMatrix );
  11232. return this;
  11233. },
  11234. getWorldDirection: function () {
  11235. var quaternion = new Quaternion();
  11236. return function getWorldDirection( optionalTarget ) {
  11237. var result = optionalTarget || new Vector3();
  11238. this.getWorldQuaternion( quaternion );
  11239. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  11240. };
  11241. }(),
  11242. updateMatrixWorld: function ( force ) {
  11243. Object3D.prototype.updateMatrixWorld.call( this, force );
  11244. this.matrixWorldInverse.getInverse( this.matrixWorld );
  11245. },
  11246. clone: function () {
  11247. return new this.constructor().copy( this );
  11248. }
  11249. } );
  11250. /**
  11251. * @author mrdoob / http://mrdoob.com/
  11252. * @author greggman / http://games.greggman.com/
  11253. * @author zz85 / http://www.lab4games.net/zz85/blog
  11254. * @author tschw
  11255. */
  11256. function PerspectiveCamera( fov, aspect, near, far ) {
  11257. Camera.call( this );
  11258. this.type = 'PerspectiveCamera';
  11259. this.fov = fov !== undefined ? fov : 50;
  11260. this.zoom = 1;
  11261. this.near = near !== undefined ? near : 0.1;
  11262. this.far = far !== undefined ? far : 2000;
  11263. this.focus = 10;
  11264. this.aspect = aspect !== undefined ? aspect : 1;
  11265. this.view = null;
  11266. this.filmGauge = 35; // width of the film (default in millimeters)
  11267. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  11268. this.updateProjectionMatrix();
  11269. }
  11270. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  11271. constructor: PerspectiveCamera,
  11272. isPerspectiveCamera: true,
  11273. copy: function ( source, recursive ) {
  11274. Camera.prototype.copy.call( this, source, recursive );
  11275. this.fov = source.fov;
  11276. this.zoom = source.zoom;
  11277. this.near = source.near;
  11278. this.far = source.far;
  11279. this.focus = source.focus;
  11280. this.aspect = source.aspect;
  11281. this.view = source.view === null ? null : Object.assign( {}, source.view );
  11282. this.filmGauge = source.filmGauge;
  11283. this.filmOffset = source.filmOffset;
  11284. return this;
  11285. },
  11286. /**
  11287. * Sets the FOV by focal length in respect to the current .filmGauge.
  11288. *
  11289. * The default film gauge is 35, so that the focal length can be specified for
  11290. * a 35mm (full frame) camera.
  11291. *
  11292. * Values for focal length and film gauge must have the same unit.
  11293. */
  11294. setFocalLength: function ( focalLength ) {
  11295. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  11296. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  11297. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  11298. this.updateProjectionMatrix();
  11299. },
  11300. /**
  11301. * Calculates the focal length from the current .fov and .filmGauge.
  11302. */
  11303. getFocalLength: function () {
  11304. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  11305. return 0.5 * this.getFilmHeight() / vExtentSlope;
  11306. },
  11307. getEffectiveFOV: function () {
  11308. return _Math.RAD2DEG * 2 * Math.atan(
  11309. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  11310. },
  11311. getFilmWidth: function () {
  11312. // film not completely covered in portrait format (aspect < 1)
  11313. return this.filmGauge * Math.min( this.aspect, 1 );
  11314. },
  11315. getFilmHeight: function () {
  11316. // film not completely covered in landscape format (aspect > 1)
  11317. return this.filmGauge / Math.max( this.aspect, 1 );
  11318. },
  11319. /**
  11320. * Sets an offset in a larger frustum. This is useful for multi-window or
  11321. * multi-monitor/multi-machine setups.
  11322. *
  11323. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  11324. * the monitors are in grid like this
  11325. *
  11326. * +---+---+---+
  11327. * | A | B | C |
  11328. * +---+---+---+
  11329. * | D | E | F |
  11330. * +---+---+---+
  11331. *
  11332. * then for each monitor you would call it like this
  11333. *
  11334. * var w = 1920;
  11335. * var h = 1080;
  11336. * var fullWidth = w * 3;
  11337. * var fullHeight = h * 2;
  11338. *
  11339. * --A--
  11340. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  11341. * --B--
  11342. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  11343. * --C--
  11344. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  11345. * --D--
  11346. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  11347. * --E--
  11348. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  11349. * --F--
  11350. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  11351. *
  11352. * Note there is no reason monitors have to be the same size or in a grid.
  11353. */
  11354. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  11355. this.aspect = fullWidth / fullHeight;
  11356. if ( this.view === null ) {
  11357. this.view = {
  11358. enabled: true,
  11359. fullWidth: 1,
  11360. fullHeight: 1,
  11361. offsetX: 0,
  11362. offsetY: 0,
  11363. width: 1,
  11364. height: 1
  11365. };
  11366. }
  11367. this.view.enabled = true;
  11368. this.view.fullWidth = fullWidth;
  11369. this.view.fullHeight = fullHeight;
  11370. this.view.offsetX = x;
  11371. this.view.offsetY = y;
  11372. this.view.width = width;
  11373. this.view.height = height;
  11374. this.updateProjectionMatrix();
  11375. },
  11376. clearViewOffset: function () {
  11377. if ( this.view !== null ) {
  11378. this.view.enabled = false;
  11379. }
  11380. this.updateProjectionMatrix();
  11381. },
  11382. updateProjectionMatrix: function () {
  11383. var near = this.near,
  11384. top = near * Math.tan(
  11385. _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  11386. height = 2 * top,
  11387. width = this.aspect * height,
  11388. left = - 0.5 * width,
  11389. view = this.view;
  11390. if ( this.view !== null && this.view.enabled ) {
  11391. var fullWidth = view.fullWidth,
  11392. fullHeight = view.fullHeight;
  11393. left += view.offsetX * width / fullWidth;
  11394. top -= view.offsetY * height / fullHeight;
  11395. width *= view.width / fullWidth;
  11396. height *= view.height / fullHeight;
  11397. }
  11398. var skew = this.filmOffset;
  11399. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  11400. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  11401. },
  11402. toJSON: function ( meta ) {
  11403. var data = Object3D.prototype.toJSON.call( this, meta );
  11404. data.object.fov = this.fov;
  11405. data.object.zoom = this.zoom;
  11406. data.object.near = this.near;
  11407. data.object.far = this.far;
  11408. data.object.focus = this.focus;
  11409. data.object.aspect = this.aspect;
  11410. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  11411. data.object.filmGauge = this.filmGauge;
  11412. data.object.filmOffset = this.filmOffset;
  11413. return data;
  11414. }
  11415. } );
  11416. /**
  11417. * @author mrdoob / http://mrdoob.com/
  11418. */
  11419. function ArrayCamera( array ) {
  11420. PerspectiveCamera.call( this );
  11421. this.cameras = array || [];
  11422. }
  11423. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  11424. constructor: ArrayCamera,
  11425. isArrayCamera: true
  11426. } );
  11427. /**
  11428. * @author TristanVALCKE / https://github.com/Itee
  11429. */
  11430. /* global QUnit */
  11431. QUnit.module( 'Cameras', () => {
  11432. QUnit.module.todo( 'ArrayCamera', () => {
  11433. // INHERITANCE
  11434. QUnit.test( "Extending", ( assert ) => {
  11435. assert.ok( false, "everything's gonna be alright" );
  11436. } );
  11437. // INSTANCING
  11438. QUnit.test( "Instancing", ( assert ) => {
  11439. assert.ok( false, "everything's gonna be alright" );
  11440. } );
  11441. // PUBLIC STUFF
  11442. QUnit.test( "isArrayCamera", ( assert ) => {
  11443. assert.ok( false, "everything's gonna be alright" );
  11444. } );
  11445. } );
  11446. } );
  11447. /**
  11448. * @author simonThiele / https://github.com/simonThiele
  11449. * @author TristanVALCKE / https://github.com/Itee
  11450. */
  11451. /* global QUnit */
  11452. QUnit.module( 'Cameras', () => {
  11453. QUnit.module.todo( 'Camera', () => {
  11454. // INHERITANCE
  11455. QUnit.test( "Extending", ( assert ) => {
  11456. assert.ok( false, "everything's gonna be alright" );
  11457. } );
  11458. // INSTANCING
  11459. QUnit.test( "Instancing", ( assert ) => {
  11460. assert.ok( false, "everything's gonna be alright" );
  11461. } );
  11462. // PUBLIC STUFF
  11463. QUnit.test( "isCamera", ( assert ) => {
  11464. assert.ok( false, "everything's gonna be alright" );
  11465. } );
  11466. QUnit.test( "copy", ( assert ) => {
  11467. assert.ok( false, "everything's gonna be alright" );
  11468. } );
  11469. QUnit.test( "getWorldDirection", ( assert ) => {
  11470. assert.ok( false, "everything's gonna be alright" );
  11471. } );
  11472. QUnit.test( "updateMatrixWorld", ( assert ) => {
  11473. assert.ok( false, "everything's gonna be alright" );
  11474. } );
  11475. QUnit.test( "clone", ( assert ) => {
  11476. var cam = new Camera();
  11477. // fill the matrices with any nonsense values just to see if they get copied
  11478. cam.matrixWorldInverse.set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  11479. cam.projectionMatrix.set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  11480. var clonedCam = cam.clone();
  11481. // TODO: Uuuummmhhh DO NOT relie equality on object methods !
  11482. // TODO: What's append if matrix.equal is wrongly implemented ???
  11483. // TODO: this MUST be check by assert
  11484. assert.ok( cam.matrixWorldInverse.equals( clonedCam.matrixWorldInverse ), "matrixWorldInverse is equal" );
  11485. assert.ok( cam.projectionMatrix.equals( clonedCam.projectionMatrix ), "projectionMatrix is equal" );
  11486. } );
  11487. // OTHERS
  11488. // TODO: this should not be here !!! This is Object3D stuff !!!
  11489. QUnit.test( "lookAt", ( assert ) => {
  11490. var cam = new Camera();
  11491. cam.lookAt( new Vector3( 0, 1, - 1 ) );
  11492. assert.numEqual( cam.rotation.x * ( 180 / Math.PI ), 45, "x is equal" );
  11493. } );
  11494. } );
  11495. } );
  11496. /**
  11497. * @author mrdoob / http://mrdoob.com/
  11498. * @author alteredq / http://alteredqualia.com/
  11499. * @author szimek / https://github.com/szimek/
  11500. */
  11501. var textureId = 0;
  11502. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  11503. Object.defineProperty( this, 'id', { value: textureId ++ } );
  11504. this.uuid = _Math.generateUUID();
  11505. this.name = '';
  11506. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  11507. this.mipmaps = [];
  11508. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  11509. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  11510. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  11511. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  11512. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  11513. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  11514. this.format = format !== undefined ? format : RGBAFormat;
  11515. this.type = type !== undefined ? type : UnsignedByteType;
  11516. this.offset = new Vector2( 0, 0 );
  11517. this.repeat = new Vector2( 1, 1 );
  11518. this.center = new Vector2( 0, 0 );
  11519. this.rotation = 0;
  11520. this.matrixAutoUpdate = true;
  11521. this.matrix = new Matrix3();
  11522. this.generateMipmaps = true;
  11523. this.premultiplyAlpha = false;
  11524. this.flipY = true;
  11525. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  11526. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  11527. //
  11528. // Also changing the encoding after already used by a Material will not automatically make the Material
  11529. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  11530. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  11531. this.version = 0;
  11532. this.onUpdate = null;
  11533. }
  11534. Texture.DEFAULT_IMAGE = undefined;
  11535. Texture.DEFAULT_MAPPING = UVMapping;
  11536. Object.defineProperty( Texture.prototype, "needsUpdate", {
  11537. set: function ( value ) {
  11538. if ( value === true ) this.version ++;
  11539. }
  11540. } );
  11541. Object.assign( Texture.prototype, EventDispatcher.prototype, {
  11542. constructor: Texture,
  11543. isTexture: true,
  11544. clone: function () {
  11545. return new this.constructor().copy( this );
  11546. },
  11547. copy: function ( source ) {
  11548. this.name = source.name;
  11549. this.image = source.image;
  11550. this.mipmaps = source.mipmaps.slice( 0 );
  11551. this.mapping = source.mapping;
  11552. this.wrapS = source.wrapS;
  11553. this.wrapT = source.wrapT;
  11554. this.magFilter = source.magFilter;
  11555. this.minFilter = source.minFilter;
  11556. this.anisotropy = source.anisotropy;
  11557. this.format = source.format;
  11558. this.type = source.type;
  11559. this.offset.copy( source.offset );
  11560. this.repeat.copy( source.repeat );
  11561. this.center.copy( source.center );
  11562. this.rotation = source.rotation;
  11563. this.matrixAutoUpdate = source.matrixAutoUpdate;
  11564. this.matrix.copy( source.matrix );
  11565. this.generateMipmaps = source.generateMipmaps;
  11566. this.premultiplyAlpha = source.premultiplyAlpha;
  11567. this.flipY = source.flipY;
  11568. this.unpackAlignment = source.unpackAlignment;
  11569. this.encoding = source.encoding;
  11570. return this;
  11571. },
  11572. toJSON: function ( meta ) {
  11573. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  11574. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  11575. return meta.textures[ this.uuid ];
  11576. }
  11577. function getDataURL( image ) {
  11578. var canvas;
  11579. if ( image instanceof HTMLCanvasElement ) {
  11580. canvas = image;
  11581. } else {
  11582. canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  11583. canvas.width = image.width;
  11584. canvas.height = image.height;
  11585. var context = canvas.getContext( '2d' );
  11586. if ( image instanceof ImageData ) {
  11587. context.putImageData( image, 0, 0 );
  11588. } else {
  11589. context.drawImage( image, 0, 0, image.width, image.height );
  11590. }
  11591. }
  11592. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  11593. return canvas.toDataURL( 'image/jpeg', 0.6 );
  11594. } else {
  11595. return canvas.toDataURL( 'image/png' );
  11596. }
  11597. }
  11598. var output = {
  11599. metadata: {
  11600. version: 4.5,
  11601. type: 'Texture',
  11602. generator: 'Texture.toJSON'
  11603. },
  11604. uuid: this.uuid,
  11605. name: this.name,
  11606. mapping: this.mapping,
  11607. repeat: [ this.repeat.x, this.repeat.y ],
  11608. offset: [ this.offset.x, this.offset.y ],
  11609. center: [ this.center.x, this.center.y ],
  11610. rotation: this.rotation,
  11611. wrap: [ this.wrapS, this.wrapT ],
  11612. minFilter: this.minFilter,
  11613. magFilter: this.magFilter,
  11614. anisotropy: this.anisotropy,
  11615. flipY: this.flipY
  11616. };
  11617. if ( this.image !== undefined ) {
  11618. // TODO: Move to THREE.Image
  11619. var image = this.image;
  11620. if ( image.uuid === undefined ) {
  11621. image.uuid = _Math.generateUUID(); // UGH
  11622. }
  11623. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  11624. meta.images[ image.uuid ] = {
  11625. uuid: image.uuid,
  11626. url: getDataURL( image )
  11627. };
  11628. }
  11629. output.image = image.uuid;
  11630. }
  11631. if ( ! isRootObject ) {
  11632. meta.textures[ this.uuid ] = output;
  11633. }
  11634. return output;
  11635. },
  11636. dispose: function () {
  11637. this.dispatchEvent( { type: 'dispose' } );
  11638. },
  11639. transformUv: function ( uv ) {
  11640. if ( this.mapping !== UVMapping ) return;
  11641. uv.applyMatrix3( this.matrix );
  11642. if ( uv.x < 0 || uv.x > 1 ) {
  11643. switch ( this.wrapS ) {
  11644. case RepeatWrapping:
  11645. uv.x = uv.x - Math.floor( uv.x );
  11646. break;
  11647. case ClampToEdgeWrapping:
  11648. uv.x = uv.x < 0 ? 0 : 1;
  11649. break;
  11650. case MirroredRepeatWrapping:
  11651. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  11652. uv.x = Math.ceil( uv.x ) - uv.x;
  11653. } else {
  11654. uv.x = uv.x - Math.floor( uv.x );
  11655. }
  11656. break;
  11657. }
  11658. }
  11659. if ( uv.y < 0 || uv.y > 1 ) {
  11660. switch ( this.wrapT ) {
  11661. case RepeatWrapping:
  11662. uv.y = uv.y - Math.floor( uv.y );
  11663. break;
  11664. case ClampToEdgeWrapping:
  11665. uv.y = uv.y < 0 ? 0 : 1;
  11666. break;
  11667. case MirroredRepeatWrapping:
  11668. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  11669. uv.y = Math.ceil( uv.y ) - uv.y;
  11670. } else {
  11671. uv.y = uv.y - Math.floor( uv.y );
  11672. }
  11673. break;
  11674. }
  11675. }
  11676. if ( this.flipY ) {
  11677. uv.y = 1 - uv.y;
  11678. }
  11679. }
  11680. } );
  11681. /**
  11682. * @author szimek / https://github.com/szimek/
  11683. * @author alteredq / http://alteredqualia.com/
  11684. * @author Marius Kintel / https://github.com/kintel
  11685. */
  11686. /*
  11687. In options, we can specify:
  11688. * Texture parameters for an auto-generated target texture
  11689. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  11690. */
  11691. function WebGLRenderTarget( width, height, options ) {
  11692. this.uuid = _Math.generateUUID();
  11693. this.width = width;
  11694. this.height = height;
  11695. this.scissor = new Vector4( 0, 0, width, height );
  11696. this.scissorTest = false;
  11697. this.viewport = new Vector4( 0, 0, width, height );
  11698. options = options || {};
  11699. if ( options.minFilter === undefined ) options.minFilter = LinearFilter;
  11700. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  11701. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  11702. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  11703. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  11704. }
  11705. Object.assign( WebGLRenderTarget.prototype, EventDispatcher.prototype, {
  11706. isWebGLRenderTarget: true,
  11707. setSize: function ( width, height ) {
  11708. if ( this.width !== width || this.height !== height ) {
  11709. this.width = width;
  11710. this.height = height;
  11711. this.dispose();
  11712. }
  11713. this.viewport.set( 0, 0, width, height );
  11714. this.scissor.set( 0, 0, width, height );
  11715. },
  11716. clone: function () {
  11717. return new this.constructor().copy( this );
  11718. },
  11719. copy: function ( source ) {
  11720. this.width = source.width;
  11721. this.height = source.height;
  11722. this.viewport.copy( source.viewport );
  11723. this.texture = source.texture.clone();
  11724. this.depthBuffer = source.depthBuffer;
  11725. this.stencilBuffer = source.stencilBuffer;
  11726. this.depthTexture = source.depthTexture;
  11727. return this;
  11728. },
  11729. dispose: function () {
  11730. this.dispatchEvent( { type: 'dispose' } );
  11731. }
  11732. } );
  11733. /**
  11734. * @author TristanVALCKE / https://github.com/Itee
  11735. */
  11736. /* global QUnit */
  11737. QUnit.module( 'Cameras', () => {
  11738. QUnit.module.todo( 'CubeCamera', () => {
  11739. // INHERITANCE
  11740. QUnit.test( "Extending", ( assert ) => {
  11741. assert.ok( false, "everything's gonna be alright" );
  11742. } );
  11743. // INSTANCING
  11744. QUnit.test( "Instancing", ( assert ) => {
  11745. assert.ok( false, "everything's gonna be alright" );
  11746. } );
  11747. } );
  11748. } );
  11749. /**
  11750. * @author alteredq / http://alteredqualia.com/
  11751. * @author arose / http://github.com/arose
  11752. */
  11753. function OrthographicCamera( left, right, top, bottom, near, far ) {
  11754. Camera.call( this );
  11755. this.type = 'OrthographicCamera';
  11756. this.zoom = 1;
  11757. this.view = null;
  11758. this.left = left;
  11759. this.right = right;
  11760. this.top = top;
  11761. this.bottom = bottom;
  11762. this.near = ( near !== undefined ) ? near : 0.1;
  11763. this.far = ( far !== undefined ) ? far : 2000;
  11764. this.updateProjectionMatrix();
  11765. }
  11766. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  11767. constructor: OrthographicCamera,
  11768. isOrthographicCamera: true,
  11769. copy: function ( source, recursive ) {
  11770. Camera.prototype.copy.call( this, source, recursive );
  11771. this.left = source.left;
  11772. this.right = source.right;
  11773. this.top = source.top;
  11774. this.bottom = source.bottom;
  11775. this.near = source.near;
  11776. this.far = source.far;
  11777. this.zoom = source.zoom;
  11778. this.view = source.view === null ? null : Object.assign( {}, source.view );
  11779. return this;
  11780. },
  11781. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  11782. if ( this.view === null ) {
  11783. this.view = {
  11784. enabled: true,
  11785. fullWidth: 1,
  11786. fullHeight: 1,
  11787. offsetX: 0,
  11788. offsetY: 0,
  11789. width: 1,
  11790. height: 1
  11791. };
  11792. }
  11793. this.view.enabled = true;
  11794. this.view.fullWidth = fullWidth;
  11795. this.view.fullHeight = fullHeight;
  11796. this.view.offsetX = x;
  11797. this.view.offsetY = y;
  11798. this.view.width = width;
  11799. this.view.height = height;
  11800. this.updateProjectionMatrix();
  11801. },
  11802. clearViewOffset: function () {
  11803. if ( this.view !== null ) {
  11804. this.view.enabled = false;
  11805. }
  11806. this.updateProjectionMatrix();
  11807. },
  11808. updateProjectionMatrix: function () {
  11809. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  11810. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  11811. var cx = ( this.right + this.left ) / 2;
  11812. var cy = ( this.top + this.bottom ) / 2;
  11813. var left = cx - dx;
  11814. var right = cx + dx;
  11815. var top = cy + dy;
  11816. var bottom = cy - dy;
  11817. if ( this.view !== null && this.view.enabled ) {
  11818. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  11819. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  11820. var scaleW = ( this.right - this.left ) / this.view.width;
  11821. var scaleH = ( this.top - this.bottom ) / this.view.height;
  11822. left += scaleW * ( this.view.offsetX / zoomW );
  11823. right = left + scaleW * ( this.view.width / zoomW );
  11824. top -= scaleH * ( this.view.offsetY / zoomH );
  11825. bottom = top - scaleH * ( this.view.height / zoomH );
  11826. }
  11827. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  11828. },
  11829. toJSON: function ( meta ) {
  11830. var data = Object3D.prototype.toJSON.call( this, meta );
  11831. data.object.zoom = this.zoom;
  11832. data.object.left = this.left;
  11833. data.object.right = this.right;
  11834. data.object.top = this.top;
  11835. data.object.bottom = this.bottom;
  11836. data.object.near = this.near;
  11837. data.object.far = this.far;
  11838. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  11839. return data;
  11840. }
  11841. } );
  11842. /**
  11843. * @author simonThiele / https://github.com/simonThiele
  11844. * @author TristanVALCKE / https://github.com/Itee
  11845. */
  11846. /* global QUnit */
  11847. QUnit.module( 'Cameras', () => {
  11848. QUnit.module.todo( 'OrthographicCamera', () => {
  11849. // INHERITANCE
  11850. QUnit.test( "Extending", ( assert ) => {
  11851. assert.ok( false, "everything's gonna be alright" );
  11852. } );
  11853. // INSTANCING
  11854. QUnit.test( "Instancing", ( assert ) => {
  11855. assert.ok( false, "everything's gonna be alright" );
  11856. } );
  11857. // PUBLIC STUFF
  11858. QUnit.test( "isOrthographicCamera", ( assert ) => {
  11859. assert.ok( false, "everything's gonna be alright" );
  11860. } );
  11861. QUnit.test( "copy", ( assert ) => {
  11862. assert.ok( false, "everything's gonna be alright" );
  11863. } );
  11864. QUnit.test( "setViewOffset", ( assert ) => {
  11865. assert.ok( false, "everything's gonna be alright" );
  11866. } );
  11867. QUnit.test( "clearViewOffset", ( assert ) => {
  11868. assert.ok( false, "everything's gonna be alright" );
  11869. } );
  11870. QUnit.test( "updateProjectionMatrix", ( assert ) => {
  11871. var left = - 1, right = 1, top = 1, bottom = - 1, near = 1, far = 3;
  11872. var cam = new OrthographicCamera( left, right, top, bottom, near, far );
  11873. // updateProjectionMatrix is called in contructor
  11874. var pMatrix = cam.projectionMatrix.elements;
  11875. // orthographic projection is given my the 4x4 Matrix
  11876. // 2/r-l 0 0 -(l+r/r-l)
  11877. // 0 2/t-b 0 -(t+b/t-b)
  11878. // 0 0 -2/f-n -(f+n/f-n)
  11879. // 0 0 0 1
  11880. assert.ok( pMatrix[ 0 ] === 2 / ( right - left ), "m[0,0] === 2 / (r - l)" );
  11881. assert.ok( pMatrix[ 5 ] === 2 / ( top - bottom ), "m[1,1] === 2 / (t - b)" );
  11882. assert.ok( pMatrix[ 10 ] === - 2 / ( far - near ), "m[2,2] === -2 / (f - n)" );
  11883. assert.ok( pMatrix[ 12 ] === - ( ( right + left ) / ( right - left ) ), "m[3,0] === -(r+l/r-l)" );
  11884. assert.ok( pMatrix[ 13 ] === - ( ( top + bottom ) / ( top - bottom ) ), "m[3,1] === -(t+b/b-t)" );
  11885. assert.ok( pMatrix[ 14 ] === - ( ( far + near ) / ( far - near ) ), "m[3,2] === -(f+n/f-n)" );
  11886. } );
  11887. QUnit.test( "toJSON", ( assert ) => {
  11888. assert.ok( false, "everything's gonna be alright" );
  11889. } );
  11890. // OTHERS
  11891. // TODO: no no no clone is a camera methods that relied to copy method
  11892. QUnit.test( "clone", ( assert ) => {
  11893. var left = - 1.5, right = 1.5, top = 1, bottom = - 1, near = 0.1, far = 42;
  11894. var cam = new OrthographicCamera( left, right, top, bottom, near, far );
  11895. var clonedCam = cam.clone();
  11896. assert.ok( cam.left === clonedCam.left, "left is equal" );
  11897. assert.ok( cam.right === clonedCam.right, "right is equal" );
  11898. assert.ok( cam.top === clonedCam.top, "top is equal" );
  11899. assert.ok( cam.bottom === clonedCam.bottom, "bottom is equal" );
  11900. assert.ok( cam.near === clonedCam.near, "near is equal" );
  11901. assert.ok( cam.far === clonedCam.far, "far is equal" );
  11902. assert.ok( cam.zoom === clonedCam.zoom, "zoom is equal" );
  11903. } );
  11904. } );
  11905. } );
  11906. /**
  11907. * @author simonThiele / https://github.com/simonThiele
  11908. * @author TristanVALCKE / https://github.com/Itee
  11909. */
  11910. /* global QUnit */
  11911. QUnit.module( 'Cameras', () => {
  11912. QUnit.module.todo( 'PerspectiveCamera', () => {
  11913. // see e.g. math/Matrix4.js
  11914. var matrixEquals4 = function ( a, b, tolerance ) {
  11915. tolerance = tolerance || 0.0001;
  11916. if ( a.elements.length != b.elements.length ) {
  11917. return false;
  11918. }
  11919. for ( var i = 0, il = a.elements.length; i < il; i ++ ) {
  11920. var delta = a.elements[ i ] - b.elements[ i ];
  11921. if ( delta > tolerance ) {
  11922. return false;
  11923. }
  11924. }
  11925. return true;
  11926. };
  11927. // INHERITANCE
  11928. QUnit.test( "Extending", ( assert ) => {
  11929. assert.ok( false, "everything's gonna be alright" );
  11930. } );
  11931. // INSTANCING
  11932. QUnit.test( "Instancing", ( assert ) => {
  11933. assert.ok( false, "everything's gonna be alright" );
  11934. } );
  11935. // PUBLIC STUFF
  11936. QUnit.test( "isPerspectiveCamera", ( assert ) => {
  11937. assert.ok( false, "everything's gonna be alright" );
  11938. } );
  11939. QUnit.test( "copy", ( assert ) => {
  11940. assert.ok( false, "everything's gonna be alright" );
  11941. } );
  11942. QUnit.test( "setFocalLength", ( assert ) => {
  11943. assert.ok( false, "everything's gonna be alright" );
  11944. } );
  11945. QUnit.test( "getFocalLength", ( assert ) => {
  11946. assert.ok( false, "everything's gonna be alright" );
  11947. } );
  11948. QUnit.test( "getEffectiveFOV", ( assert ) => {
  11949. assert.ok( false, "everything's gonna be alright" );
  11950. } );
  11951. QUnit.test( "getFilmWidth", ( assert ) => {
  11952. assert.ok( false, "everything's gonna be alright" );
  11953. } );
  11954. QUnit.test( "getFilmHeight", ( assert ) => {
  11955. assert.ok( false, "everything's gonna be alright" );
  11956. } );
  11957. QUnit.test( "setViewOffset", ( assert ) => {
  11958. assert.ok( false, "everything's gonna be alright" );
  11959. } );
  11960. QUnit.test( "clearViewOffset", ( assert ) => {
  11961. assert.ok( false, "everything's gonna be alright" );
  11962. } );
  11963. QUnit.test( "updateProjectionMatrix", ( assert ) => {
  11964. var cam = new PerspectiveCamera( 75, 16 / 9, 0.1, 300.0 );
  11965. // updateProjectionMatrix is called in contructor
  11966. var m = cam.projectionMatrix;
  11967. // perspective projection is given my the 4x4 Matrix
  11968. // 2n/r-l 0 l+r/r-l 0
  11969. // 0 2n/t-b t+b/t-b 0
  11970. // 0 0 -(f+n/f-n) -(2fn/f-n)
  11971. // 0 0 -1 0
  11972. // this matrix was calculated by hand via glMatrix.perspective(75, 16 / 9, 0.1, 300.0, pMatrix)
  11973. // to get a reference matrix from plain WebGL
  11974. var reference = new Matrix4().set(
  11975. 0.7330642938613892, 0, 0, 0,
  11976. 0, 1.3032253980636597, 0, 0,
  11977. 0, 0, - 1.000666856765747, - 0.2000666856765747,
  11978. 0, 0, - 1, 0
  11979. );
  11980. // assert.ok( reference.equals(m) );
  11981. assert.ok( matrixEquals4( reference, m, 0.000001 ) );
  11982. } );
  11983. QUnit.test( "toJSON", ( assert ) => {
  11984. assert.ok( false, "everything's gonna be alright" );
  11985. } );
  11986. // OTHERS
  11987. // TODO: no no no clone is a camera methods that relied to copy method
  11988. QUnit.test( "clone", ( assert ) => {
  11989. var near = 1,
  11990. far = 3,
  11991. aspect = 16 / 9,
  11992. fov = 90;
  11993. var cam = new PerspectiveCamera( fov, aspect, near, far );
  11994. var clonedCam = cam.clone();
  11995. assert.ok( cam.fov === clonedCam.fov, "fov is equal" );
  11996. assert.ok( cam.aspect === clonedCam.aspect, "aspect is equal" );
  11997. assert.ok( cam.near === clonedCam.near, "near is equal" );
  11998. assert.ok( cam.far === clonedCam.far, "far is equal" );
  11999. assert.ok( cam.zoom === clonedCam.zoom, "zoom is equal" );
  12000. assert.ok( cam.projectionMatrix.equals( clonedCam.projectionMatrix ), "projectionMatrix is equal" );
  12001. } );
  12002. } );
  12003. } );
  12004. /**
  12005. * @author mrdoob / http://mrdoob.com/
  12006. */
  12007. function StereoCamera() {
  12008. this.type = 'StereoCamera';
  12009. this.aspect = 1;
  12010. this.eyeSep = 0.064;
  12011. this.cameraL = new PerspectiveCamera();
  12012. this.cameraL.layers.enable( 1 );
  12013. this.cameraL.matrixAutoUpdate = false;
  12014. this.cameraR = new PerspectiveCamera();
  12015. this.cameraR.layers.enable( 2 );
  12016. this.cameraR.matrixAutoUpdate = false;
  12017. }
  12018. Object.assign( StereoCamera.prototype, {
  12019. update: ( function () {
  12020. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  12021. var eyeRight = new Matrix4();
  12022. var eyeLeft = new Matrix4();
  12023. return function update( camera ) {
  12024. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  12025. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  12026. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  12027. if ( needsUpdate ) {
  12028. instance = this;
  12029. focus = camera.focus;
  12030. fov = camera.fov;
  12031. aspect = camera.aspect * this.aspect;
  12032. near = camera.near;
  12033. far = camera.far;
  12034. zoom = camera.zoom;
  12035. // Off-axis stereoscopic effect based on
  12036. // http://paulbourke.net/stereographics/stereorender/
  12037. var projectionMatrix = camera.projectionMatrix.clone();
  12038. eyeSep = this.eyeSep / 2;
  12039. var eyeSepOnProjection = eyeSep * near / focus;
  12040. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  12041. var xmin, xmax;
  12042. // translate xOffset
  12043. eyeLeft.elements[ 12 ] = - eyeSep;
  12044. eyeRight.elements[ 12 ] = eyeSep;
  12045. // for left eye
  12046. xmin = - ymax * aspect + eyeSepOnProjection;
  12047. xmax = ymax * aspect + eyeSepOnProjection;
  12048. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  12049. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  12050. this.cameraL.projectionMatrix.copy( projectionMatrix );
  12051. // for right eye
  12052. xmin = - ymax * aspect - eyeSepOnProjection;
  12053. xmax = ymax * aspect - eyeSepOnProjection;
  12054. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  12055. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  12056. this.cameraR.projectionMatrix.copy( projectionMatrix );
  12057. }
  12058. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  12059. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  12060. };
  12061. } )()
  12062. } );
  12063. /**
  12064. * @author TristanVALCKE / https://github.com/Itee
  12065. */
  12066. /* global QUnit */
  12067. QUnit.module( 'Cameras', () => {
  12068. QUnit.module.todo( 'StereoCamera', () => {
  12069. // INSTANCING
  12070. QUnit.test( "Instancing", ( assert ) => {
  12071. assert.ok( false, "everything's gonna be alright" );
  12072. } );
  12073. // PUBLIC STUFF
  12074. QUnit.test( "update", ( assert ) => {
  12075. assert.ok( false, "everything's gonna be alright" );
  12076. } );
  12077. } );
  12078. } );
  12079. /**
  12080. * @author simonThiele / https://github.com/simonThiele
  12081. */
  12082. /* global QUnit */
  12083. QUnit.module( 'Core', () => {
  12084. QUnit.module.todo( 'BufferAttribute', () => {
  12085. // INSTANCING
  12086. QUnit.test( "Instancing", ( assert ) => {
  12087. assert.throws(
  12088. function () {
  12089. var a = new BufferAttribute( [ 1, 2, 3, 4 ], 2, false );
  12090. },
  12091. /array should be a Typed Array/,
  12092. "Calling constructor with a simple array throws Error"
  12093. );
  12094. } );
  12095. // PROPERTIES
  12096. QUnit.test( "needsUpdate", ( assert ) => {
  12097. assert.ok( false, "everything's gonna be alright" );
  12098. } );
  12099. // PUBLIC STUFF
  12100. QUnit.test( "isBufferAttribute", ( assert ) => {
  12101. assert.ok( false, "everything's gonna be alright" );
  12102. } );
  12103. QUnit.test( "setArray", ( assert ) => {
  12104. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  12105. var a = new BufferAttribute( f32a, 2, false );
  12106. a.setArray( f32a, 2 );
  12107. assert.strictEqual( a.count, 2, "Check item count" );
  12108. assert.strictEqual( a.array, f32a, "Check array" );
  12109. assert.throws(
  12110. function () {
  12111. a.setArray( [ 1, 2, 3, 4 ] );
  12112. },
  12113. /array should be a Typed Array/,
  12114. "Calling setArray with a simple array throws Error"
  12115. );
  12116. } );
  12117. QUnit.test( "setDynamic", ( assert ) => {
  12118. assert.ok( false, "everything's gonna be alright" );
  12119. } );
  12120. QUnit.test( "copy", ( assert ) => {
  12121. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 );
  12122. attr.setDynamic( true );
  12123. attr.needsUpdate = true;
  12124. var attrCopy = new BufferAttribute().copy( attr );
  12125. assert.ok( attr.count === attrCopy.count, 'count is equal' );
  12126. assert.ok( attr.itemSize === attrCopy.itemSize, 'itemSize is equal' );
  12127. assert.ok( attr.dynamic === attrCopy.dynamic, 'dynamic is equal' );
  12128. assert.ok( attr.array.length === attrCopy.array.length, 'array length is equal' );
  12129. assert.ok( attr.version === 1 && attrCopy.version === 0, 'version is not copied which is good' );
  12130. } );
  12131. QUnit.test( "copyAt", ( assert ) => {
  12132. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ), 3 );
  12133. var attr2 = new BufferAttribute( new Float32Array( 9 ), 3 );
  12134. attr2.copyAt( 1, attr, 2 );
  12135. attr2.copyAt( 0, attr, 1 );
  12136. attr2.copyAt( 2, attr, 0 );
  12137. var i = attr.array;
  12138. var i2 = attr2.array; // should be [4, 5, 6, 7, 8, 9, 1, 2, 3]
  12139. assert.ok( i2[ 0 ] === i[ 3 ] && i2[ 1 ] === i[ 4 ] && i2[ 2 ] === i[ 5 ], 'chunck copied to correct place' );
  12140. assert.ok( i2[ 3 ] === i[ 6 ] && i2[ 4 ] === i[ 7 ] && i2[ 5 ] === i[ 8 ], 'chunck copied to correct place' );
  12141. assert.ok( i2[ 6 ] === i[ 0 ] && i2[ 7 ] === i[ 1 ] && i2[ 8 ] === i[ 2 ], 'chunck copied to correct place' );
  12142. } );
  12143. QUnit.test( "copyArray", ( assert ) => {
  12144. var f32a = new Float32Array( [ 5, 6, 7, 8 ] );
  12145. var a = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4 ] ), 2, false );
  12146. a.copyArray( f32a );
  12147. assert.deepEqual( a.array, f32a, "Check array has new values" );
  12148. } );
  12149. QUnit.test( "copyColorsArray", ( assert ) => {
  12150. var attr = new BufferAttribute( new Float32Array( 6 ), 3 );
  12151. attr.copyColorsArray( [
  12152. new Color( 0, 0.5, 1 ),
  12153. new Color( 0.25, 1, 0 )
  12154. ] );
  12155. var i = attr.array;
  12156. assert.ok( i[ 0 ] === 0 && i[ 1 ] === 0.5 && i[ 2 ] === 1, 'first color was copied correctly' );
  12157. assert.ok( i[ 3 ] === 0.25 && i[ 4 ] === 1 && i[ 5 ] === 0, 'second color was copied correctly' );
  12158. } );
  12159. QUnit.test( "copyIndicesArray", ( assert ) => {
  12160. var attr = new BufferAttribute( new Float32Array( 6 ), 3 );
  12161. attr.copyIndicesArray( [
  12162. {
  12163. a: 1,
  12164. b: 2,
  12165. c: 3
  12166. },
  12167. {
  12168. a: 4,
  12169. b: 5,
  12170. c: 6
  12171. }
  12172. ] );
  12173. var i = attr.array;
  12174. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2 && i[ 2 ] === 3, 'first indices were copied correctly' );
  12175. assert.ok( i[ 3 ] === 4 && i[ 4 ] === 5 && i[ 5 ] === 6, 'second indices were copied correctly' );
  12176. } );
  12177. QUnit.test( "copyVector2sArray", ( assert ) => {
  12178. var attr = new BufferAttribute( new Float32Array( 4 ), 2 );
  12179. attr.copyVector2sArray( [
  12180. new Vector2( 1, 2 ),
  12181. new Vector2( 4, 5 )
  12182. ] );
  12183. var i = attr.array;
  12184. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2, 'first vector was copied correctly' );
  12185. assert.ok( i[ 2 ] === 4 && i[ 3 ] === 5, 'second vector was copied correctly' );
  12186. } );
  12187. QUnit.test( "copyVector3sArray", ( assert ) => {
  12188. var attr = new BufferAttribute( new Float32Array( 6 ), 2 );
  12189. attr.copyVector3sArray( [
  12190. new Vector3( 1, 2, 3 ),
  12191. new Vector3( 10, 20, 30 )
  12192. ] );
  12193. var i = attr.array;
  12194. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2 && i[ 2 ] === 3, 'first vector was copied correctly' );
  12195. assert.ok( i[ 3 ] === 10 && i[ 4 ] === 20 && i[ 5 ] === 30, 'second vector was copied correctly' );
  12196. } );
  12197. QUnit.test( "copyVector4sArray", ( assert ) => {
  12198. var attr = new BufferAttribute( new Float32Array( 8 ), 2 );
  12199. attr.copyVector4sArray( [
  12200. new Vector4( 1, 2, 3, 4 ),
  12201. new Vector4( 10, 20, 30, 40 )
  12202. ] );
  12203. var i = attr.array;
  12204. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2 && i[ 2 ] === 3 && i[ 3 ] === 4, 'first vector was copied correctly' );
  12205. assert.ok( i[ 4 ] === 10 && i[ 5 ] === 20 && i[ 6 ] === 30 && i[ 7 ] === 40, 'second vector was copied correctly' );
  12206. } );
  12207. QUnit.test( "set", ( assert ) => {
  12208. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  12209. var a = new BufferAttribute( f32a, 2, false );
  12210. var expected = new Float32Array( [ 9, 2, 8, 4 ] );
  12211. a.set( [ 9 ] );
  12212. a.set( [ 8 ], 2 );
  12213. assert.deepEqual( a.array, expected, "Check array has expected values" );
  12214. } );
  12215. QUnit.test( "set[X, Y, Z, W, XYZ, XYZW]/get[X, Y, Z, W]", ( assert ) => {
  12216. var f32a = new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
  12217. var a = new BufferAttribute( f32a, 4, false );
  12218. var expected = new Float32Array( [ 1, 2, - 3, - 4, - 5, - 6, 7, 8 ] );
  12219. a.setX( 1, a.getX( 1 ) * - 1 );
  12220. a.setY( 1, a.getY( 1 ) * - 1 );
  12221. a.setZ( 0, a.getZ( 0 ) * - 1 );
  12222. a.setW( 0, a.getW( 0 ) * - 1 );
  12223. assert.deepEqual( a.array, expected, "Check all set* calls set the correct values" );
  12224. } );
  12225. QUnit.test( "setXY", ( assert ) => {
  12226. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  12227. var a = new BufferAttribute( f32a, 2, false );
  12228. var expected = new Float32Array( [ - 1, - 2, 3, 4 ] );
  12229. a.setXY( 0, - 1, - 2 );
  12230. assert.deepEqual( a.array, expected, "Check for the correct values" );
  12231. } );
  12232. QUnit.test( "setXYZ", ( assert ) => {
  12233. var f32a = new Float32Array( [ 1, 2, 3, 4, 5, 6 ] );
  12234. var a = new BufferAttribute( f32a, 3, false );
  12235. var expected = new Float32Array( [ 1, 2, 3, - 4, - 5, - 6 ] );
  12236. a.setXYZ( 1, - 4, - 5, - 6 );
  12237. assert.deepEqual( a.array, expected, "Check for the correct values" );
  12238. } );
  12239. QUnit.test( "setXYZW", ( assert ) => {
  12240. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  12241. var a = new BufferAttribute( f32a, 4, false );
  12242. var expected = new Float32Array( [ - 1, - 2, - 3, - 4 ] );
  12243. a.setXYZW( 0, - 1, - 2, - 3, - 4 );
  12244. assert.deepEqual( a.array, expected, "Check for the correct values" );
  12245. } );
  12246. QUnit.test( "onUpload", ( assert ) => {
  12247. var a = new BufferAttribute();
  12248. var func = function () { };
  12249. a.onUpload( func );
  12250. assert.strictEqual( a.onUploadCallback, func, "Check callback was set properly" );
  12251. } );
  12252. QUnit.test( "clone", ( assert ) => {
  12253. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 0.12, - 12 ] ), 2 );
  12254. var attrCopy = attr.clone();
  12255. assert.ok( attr.array.length === attrCopy.array.length, 'attribute was cloned' );
  12256. for ( var i = 0; i < attr.array.length; i ++ ) {
  12257. assert.ok( attr.array[ i ] === attrCopy.array[ i ], 'array item is equal' );
  12258. }
  12259. } );
  12260. // OTHERS
  12261. QUnit.test( "count", ( assert ) => {
  12262. assert.ok(
  12263. new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ).count === 2,
  12264. 'count is equal to the number of chunks'
  12265. );
  12266. } );
  12267. } );
  12268. QUnit.module.todo( 'Int8BufferAttribute', () => {
  12269. // INHERITANCE
  12270. QUnit.test( "Extending", ( assert ) => {
  12271. assert.ok( false, "everything's gonna be alright" );
  12272. } );
  12273. // INSTANCING
  12274. QUnit.test( "Instancing", ( assert ) => {
  12275. assert.ok( false, "everything's gonna be alright" );
  12276. } );
  12277. } );
  12278. QUnit.module.todo( 'Uint8BufferAttribute', () => {
  12279. // INHERITANCE
  12280. QUnit.test( "Extending", ( assert ) => {
  12281. assert.ok( false, "everything's gonna be alright" );
  12282. } );
  12283. // INSTANCING
  12284. QUnit.test( "Instancing", ( assert ) => {
  12285. assert.ok( false, "everything's gonna be alright" );
  12286. } );
  12287. } );
  12288. QUnit.module.todo( 'Uint8ClampedBufferAttribute', () => {
  12289. // INHERITANCE
  12290. QUnit.test( "Extending", ( assert ) => {
  12291. assert.ok( false, "everything's gonna be alright" );
  12292. } );
  12293. // INSTANCING
  12294. QUnit.test( "Instancing", ( assert ) => {
  12295. assert.ok( false, "everything's gonna be alright" );
  12296. } );
  12297. } );
  12298. QUnit.module.todo( 'Int16BufferAttribute', () => {
  12299. // INHERITANCE
  12300. QUnit.test( "Extending", ( assert ) => {
  12301. assert.ok( false, "everything's gonna be alright" );
  12302. } );
  12303. // INSTANCING
  12304. QUnit.test( "Instancing", ( assert ) => {
  12305. assert.ok( false, "everything's gonna be alright" );
  12306. } );
  12307. } );
  12308. QUnit.module.todo( 'Uint16BufferAttribute', () => {
  12309. // INHERITANCE
  12310. QUnit.test( "Extending", ( assert ) => {
  12311. assert.ok( false, "everything's gonna be alright" );
  12312. } );
  12313. // INSTANCING
  12314. QUnit.test( "Instancing", ( assert ) => {
  12315. assert.ok( false, "everything's gonna be alright" );
  12316. } );
  12317. } );
  12318. QUnit.module.todo( 'Int32BufferAttribute', () => {
  12319. // INHERITANCE
  12320. QUnit.test( "Extending", ( assert ) => {
  12321. assert.ok( false, "everything's gonna be alright" );
  12322. } );
  12323. // INSTANCING
  12324. QUnit.test( "Instancing", ( assert ) => {
  12325. assert.ok( false, "everything's gonna be alright" );
  12326. } );
  12327. } );
  12328. QUnit.module.todo( 'Uint32BufferAttribute', () => {
  12329. // INHERITANCE
  12330. QUnit.test( "Extending", ( assert ) => {
  12331. assert.ok( false, "everything's gonna be alright" );
  12332. } );
  12333. // INSTANCING
  12334. QUnit.test( "Instancing", ( assert ) => {
  12335. assert.ok( false, "everything's gonna be alright" );
  12336. } );
  12337. } );
  12338. QUnit.module.todo( 'Float32BufferAttribute', () => {
  12339. // INHERITANCE
  12340. QUnit.test( "Extending", ( assert ) => {
  12341. assert.ok( false, "everything's gonna be alright" );
  12342. } );
  12343. // INSTANCING
  12344. QUnit.test( "Instancing", ( assert ) => {
  12345. assert.ok( false, "everything's gonna be alright" );
  12346. } );
  12347. } );
  12348. QUnit.module.todo( 'Float64BufferAttribute', () => {
  12349. // INHERITANCE
  12350. QUnit.test( "Extending", ( assert ) => {
  12351. assert.ok( false, "everything's gonna be alright" );
  12352. } );
  12353. // INSTANCING
  12354. QUnit.test( "Instancing", ( assert ) => {
  12355. assert.ok( false, "everything's gonna be alright" );
  12356. } );
  12357. } );
  12358. } );
  12359. /**
  12360. * @author mrdoob / http://mrdoob.com/
  12361. */
  12362. var Cache = {
  12363. enabled: false,
  12364. files: {},
  12365. add: function ( key, file ) {
  12366. if ( this.enabled === false ) return;
  12367. // console.log( 'THREE.Cache', 'Adding key:', key );
  12368. this.files[ key ] = file;
  12369. },
  12370. get: function ( key ) {
  12371. if ( this.enabled === false ) return;
  12372. // console.log( 'THREE.Cache', 'Checking key:', key );
  12373. return this.files[ key ];
  12374. },
  12375. remove: function ( key ) {
  12376. delete this.files[ key ];
  12377. },
  12378. clear: function () {
  12379. this.files = {};
  12380. }
  12381. };
  12382. /**
  12383. * @author mrdoob / http://mrdoob.com/
  12384. */
  12385. function LoadingManager( onLoad, onProgress, onError ) {
  12386. var scope = this;
  12387. var isLoading = false;
  12388. var itemsLoaded = 0;
  12389. var itemsTotal = 0;
  12390. var urlModifier = undefined;
  12391. this.onStart = undefined;
  12392. this.onLoad = onLoad;
  12393. this.onProgress = onProgress;
  12394. this.onError = onError;
  12395. this.itemStart = function ( url ) {
  12396. itemsTotal ++;
  12397. if ( isLoading === false ) {
  12398. if ( scope.onStart !== undefined ) {
  12399. scope.onStart( url, itemsLoaded, itemsTotal );
  12400. }
  12401. }
  12402. isLoading = true;
  12403. };
  12404. this.itemEnd = function ( url ) {
  12405. itemsLoaded ++;
  12406. if ( scope.onProgress !== undefined ) {
  12407. scope.onProgress( url, itemsLoaded, itemsTotal );
  12408. }
  12409. if ( itemsLoaded === itemsTotal ) {
  12410. isLoading = false;
  12411. if ( scope.onLoad !== undefined ) {
  12412. scope.onLoad();
  12413. }
  12414. }
  12415. };
  12416. this.itemError = function ( url ) {
  12417. if ( scope.onError !== undefined ) {
  12418. scope.onError( url );
  12419. }
  12420. };
  12421. this.resolveURL = function ( url ) {
  12422. if ( urlModifier ) {
  12423. return urlModifier( url );
  12424. }
  12425. return url;
  12426. };
  12427. this.setURLModifier = function ( transform ) {
  12428. urlModifier = transform;
  12429. };
  12430. }
  12431. var DefaultLoadingManager = new LoadingManager();
  12432. /**
  12433. * @author mrdoob / http://mrdoob.com/
  12434. */
  12435. var loading = {};
  12436. function FileLoader( manager ) {
  12437. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  12438. }
  12439. Object.assign( FileLoader.prototype, {
  12440. load: function ( url, onLoad, onProgress, onError ) {
  12441. if ( url === undefined ) url = '';
  12442. if ( this.path !== undefined ) url = this.path + url;
  12443. url = this.manager.resolveURL( url );
  12444. var scope = this;
  12445. var cached = Cache.get( url );
  12446. if ( cached !== undefined ) {
  12447. scope.manager.itemStart( url );
  12448. setTimeout( function () {
  12449. if ( onLoad ) onLoad( cached );
  12450. scope.manager.itemEnd( url );
  12451. }, 0 );
  12452. return cached;
  12453. }
  12454. // Check if request is duplicate
  12455. if ( loading[ url ] !== undefined ) {
  12456. loading[ url ].push( {
  12457. onLoad: onLoad,
  12458. onProgress: onProgress,
  12459. onError: onError
  12460. } );
  12461. return;
  12462. }
  12463. // Check for data: URI
  12464. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  12465. var dataUriRegexResult = url.match( dataUriRegex );
  12466. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  12467. if ( dataUriRegexResult ) {
  12468. var mimeType = dataUriRegexResult[ 1 ];
  12469. var isBase64 = !! dataUriRegexResult[ 2 ];
  12470. var data = dataUriRegexResult[ 3 ];
  12471. data = window.decodeURIComponent( data );
  12472. if ( isBase64 ) data = window.atob( data );
  12473. try {
  12474. var response;
  12475. var responseType = ( this.responseType || '' ).toLowerCase();
  12476. switch ( responseType ) {
  12477. case 'arraybuffer':
  12478. case 'blob':
  12479. var view = new Uint8Array( data.length );
  12480. for ( var i = 0; i < data.length; i ++ ) {
  12481. view[ i ] = data.charCodeAt( i );
  12482. }
  12483. if ( responseType === 'blob' ) {
  12484. response = new Blob( [ view.buffer ], { type: mimeType } );
  12485. } else {
  12486. response = view.buffer;
  12487. }
  12488. break;
  12489. case 'document':
  12490. var parser = new DOMParser();
  12491. response = parser.parseFromString( data, mimeType );
  12492. break;
  12493. case 'json':
  12494. response = JSON.parse( data );
  12495. break;
  12496. default: // 'text' or other
  12497. response = data;
  12498. break;
  12499. }
  12500. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  12501. window.setTimeout( function () {
  12502. if ( onLoad ) onLoad( response );
  12503. scope.manager.itemEnd( url );
  12504. }, 0 );
  12505. } catch ( error ) {
  12506. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  12507. window.setTimeout( function () {
  12508. if ( onError ) onError( error );
  12509. scope.manager.itemEnd( url );
  12510. scope.manager.itemError( url );
  12511. }, 0 );
  12512. }
  12513. } else {
  12514. // Initialise array for duplicate requests
  12515. loading[ url ] = [];
  12516. loading[ url ].push( {
  12517. onLoad: onLoad,
  12518. onProgress: onProgress,
  12519. onError: onError
  12520. } );
  12521. var request = new XMLHttpRequest();
  12522. request.open( 'GET', url, true );
  12523. request.addEventListener( 'load', function ( event ) {
  12524. var response = event.target.response;
  12525. Cache.add( url, response );
  12526. var callbacks = loading[ url ];
  12527. delete loading[ url ];
  12528. if ( this.status === 200 ) {
  12529. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  12530. var callback = callbacks[ i ];
  12531. if ( callback.onLoad ) callback.onLoad( response );
  12532. }
  12533. scope.manager.itemEnd( url );
  12534. } else if ( this.status === 0 ) {
  12535. // Some browsers return HTTP Status 0 when using non-http protocol
  12536. // e.g. 'file://' or 'data://'. Handle as success.
  12537. console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  12538. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  12539. var callback = callbacks[ i ];
  12540. if ( callback.onLoad ) callback.onLoad( response );
  12541. }
  12542. scope.manager.itemEnd( url );
  12543. } else {
  12544. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  12545. var callback = callbacks[ i ];
  12546. if ( callback.onError ) callback.onError( event );
  12547. }
  12548. scope.manager.itemEnd( url );
  12549. scope.manager.itemError( url );
  12550. }
  12551. }, false );
  12552. request.addEventListener( 'progress', function ( event ) {
  12553. var callbacks = loading[ url ];
  12554. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  12555. var callback = callbacks[ i ];
  12556. if ( callback.onProgress ) callback.onProgress( event );
  12557. }
  12558. }, false );
  12559. request.addEventListener( 'error', function ( event ) {
  12560. var callbacks = loading[ url ];
  12561. delete loading[ url ];
  12562. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  12563. var callback = callbacks[ i ];
  12564. if ( callback.onError ) callback.onError( event );
  12565. }
  12566. scope.manager.itemEnd( url );
  12567. scope.manager.itemError( url );
  12568. }, false );
  12569. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  12570. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  12571. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  12572. for ( var header in this.requestHeader ) {
  12573. request.setRequestHeader( header, this.requestHeader[ header ] );
  12574. }
  12575. request.send( null );
  12576. }
  12577. scope.manager.itemStart( url );
  12578. return request;
  12579. },
  12580. setPath: function ( value ) {
  12581. this.path = value;
  12582. return this;
  12583. },
  12584. setResponseType: function ( value ) {
  12585. this.responseType = value;
  12586. return this;
  12587. },
  12588. setWithCredentials: function ( value ) {
  12589. this.withCredentials = value;
  12590. return this;
  12591. },
  12592. setMimeType: function ( value ) {
  12593. this.mimeType = value;
  12594. return this;
  12595. },
  12596. setRequestHeader: function ( value ) {
  12597. this.requestHeader = value;
  12598. return this;
  12599. }
  12600. } );
  12601. /**
  12602. * @author mrdoob / http://mrdoob.com/
  12603. *
  12604. * parameters = {
  12605. * color: <THREE.Color>,
  12606. * opacity: <float>
  12607. * }
  12608. */
  12609. function ShadowMaterial( parameters ) {
  12610. Material.call( this );
  12611. this.type = 'ShadowMaterial';
  12612. this.color = new Color( 0x000000 );
  12613. this.opacity = 1.0;
  12614. this.lights = true;
  12615. this.transparent = true;
  12616. this.setValues( parameters );
  12617. }
  12618. ShadowMaterial.prototype = Object.create( Material.prototype );
  12619. ShadowMaterial.prototype.constructor = ShadowMaterial;
  12620. ShadowMaterial.prototype.isShadowMaterial = true;
  12621. /**
  12622. * @author alteredq / http://alteredqualia.com/
  12623. *
  12624. * parameters = {
  12625. * color: <hex>,
  12626. * opacity: <float>,
  12627. * map: new THREE.Texture( <Image> ),
  12628. *
  12629. * uvOffset: new THREE.Vector2(),
  12630. * uvScale: new THREE.Vector2()
  12631. * }
  12632. */
  12633. function SpriteMaterial( parameters ) {
  12634. Material.call( this );
  12635. this.type = 'SpriteMaterial';
  12636. this.color = new Color( 0xffffff );
  12637. this.map = null;
  12638. this.rotation = 0;
  12639. this.fog = false;
  12640. this.lights = false;
  12641. this.setValues( parameters );
  12642. }
  12643. SpriteMaterial.prototype = Object.create( Material.prototype );
  12644. SpriteMaterial.prototype.constructor = SpriteMaterial;
  12645. SpriteMaterial.prototype.isSpriteMaterial = true;
  12646. SpriteMaterial.prototype.copy = function ( source ) {
  12647. Material.prototype.copy.call( this, source );
  12648. this.color.copy( source.color );
  12649. this.map = source.map;
  12650. this.rotation = source.rotation;
  12651. return this;
  12652. };
  12653. /**
  12654. * Uniform Utilities
  12655. */
  12656. var UniformsUtils = {
  12657. merge: function ( uniforms ) {
  12658. var merged = {};
  12659. for ( var u = 0; u < uniforms.length; u ++ ) {
  12660. var tmp = this.clone( uniforms[ u ] );
  12661. for ( var p in tmp ) {
  12662. merged[ p ] = tmp[ p ];
  12663. }
  12664. }
  12665. return merged;
  12666. },
  12667. clone: function ( uniforms_src ) {
  12668. var uniforms_dst = {};
  12669. for ( var u in uniforms_src ) {
  12670. uniforms_dst[ u ] = {};
  12671. for ( var p in uniforms_src[ u ] ) {
  12672. var parameter_src = uniforms_src[ u ][ p ];
  12673. if ( parameter_src && ( parameter_src.isColor ||
  12674. parameter_src.isMatrix3 || parameter_src.isMatrix4 ||
  12675. parameter_src.isVector2 || parameter_src.isVector3 || parameter_src.isVector4 ||
  12676. parameter_src.isTexture ) ) {
  12677. uniforms_dst[ u ][ p ] = parameter_src.clone();
  12678. } else if ( Array.isArray( parameter_src ) ) {
  12679. uniforms_dst[ u ][ p ] = parameter_src.slice();
  12680. } else {
  12681. uniforms_dst[ u ][ p ] = parameter_src;
  12682. }
  12683. }
  12684. }
  12685. return uniforms_dst;
  12686. }
  12687. };
  12688. /**
  12689. * @author alteredq / http://alteredqualia.com/
  12690. *
  12691. * parameters = {
  12692. * defines: { "label" : "value" },
  12693. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  12694. *
  12695. * fragmentShader: <string>,
  12696. * vertexShader: <string>,
  12697. *
  12698. * wireframe: <boolean>,
  12699. * wireframeLinewidth: <float>,
  12700. *
  12701. * lights: <bool>,
  12702. *
  12703. * skinning: <bool>,
  12704. * morphTargets: <bool>,
  12705. * morphNormals: <bool>
  12706. * }
  12707. */
  12708. function ShaderMaterial( parameters ) {
  12709. Material.call( this );
  12710. this.type = 'ShaderMaterial';
  12711. this.defines = {};
  12712. this.uniforms = {};
  12713. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12714. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12715. this.linewidth = 1;
  12716. this.wireframe = false;
  12717. this.wireframeLinewidth = 1;
  12718. this.fog = false; // set to use scene fog
  12719. this.lights = false; // set to use scene lights
  12720. this.clipping = false; // set to use user-defined clipping planes
  12721. this.skinning = false; // set to use skinning attribute streams
  12722. this.morphTargets = false; // set to use morph targets
  12723. this.morphNormals = false; // set to use morph normals
  12724. this.extensions = {
  12725. derivatives: false, // set to use derivatives
  12726. fragDepth: false, // set to use fragment depth values
  12727. drawBuffers: false, // set to use draw buffers
  12728. shaderTextureLOD: false // set to use shader texture LOD
  12729. };
  12730. // When rendered geometry doesn't include these attributes but the material does,
  12731. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12732. this.defaultAttributeValues = {
  12733. 'color': [ 1, 1, 1 ],
  12734. 'uv': [ 0, 0 ],
  12735. 'uv2': [ 0, 0 ]
  12736. };
  12737. this.index0AttributeName = undefined;
  12738. if ( parameters !== undefined ) {
  12739. if ( parameters.attributes !== undefined ) {
  12740. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12741. }
  12742. this.setValues( parameters );
  12743. }
  12744. }
  12745. ShaderMaterial.prototype = Object.create( Material.prototype );
  12746. ShaderMaterial.prototype.constructor = ShaderMaterial;
  12747. ShaderMaterial.prototype.isShaderMaterial = true;
  12748. ShaderMaterial.prototype.copy = function ( source ) {
  12749. Material.prototype.copy.call( this, source );
  12750. this.fragmentShader = source.fragmentShader;
  12751. this.vertexShader = source.vertexShader;
  12752. this.uniforms = UniformsUtils.clone( source.uniforms );
  12753. this.defines = source.defines;
  12754. this.wireframe = source.wireframe;
  12755. this.wireframeLinewidth = source.wireframeLinewidth;
  12756. this.lights = source.lights;
  12757. this.clipping = source.clipping;
  12758. this.skinning = source.skinning;
  12759. this.morphTargets = source.morphTargets;
  12760. this.morphNormals = source.morphNormals;
  12761. this.extensions = source.extensions;
  12762. return this;
  12763. };
  12764. ShaderMaterial.prototype.toJSON = function ( meta ) {
  12765. var data = Material.prototype.toJSON.call( this, meta );
  12766. data.uniforms = this.uniforms;
  12767. data.vertexShader = this.vertexShader;
  12768. data.fragmentShader = this.fragmentShader;
  12769. return data;
  12770. };
  12771. /**
  12772. * @author mrdoob / http://mrdoob.com/
  12773. */
  12774. function RawShaderMaterial( parameters ) {
  12775. ShaderMaterial.call( this, parameters );
  12776. this.type = 'RawShaderMaterial';
  12777. }
  12778. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  12779. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  12780. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  12781. /**
  12782. * @author mrdoob / http://mrdoob.com/
  12783. * @author alteredq / http://alteredqualia.com/
  12784. *
  12785. * parameters = {
  12786. * color: <hex>,
  12787. * opacity: <float>,
  12788. * map: new THREE.Texture( <Image> ),
  12789. *
  12790. * size: <float>,
  12791. * sizeAttenuation: <bool>
  12792. * }
  12793. */
  12794. function PointsMaterial( parameters ) {
  12795. Material.call( this );
  12796. this.type = 'PointsMaterial';
  12797. this.color = new Color( 0xffffff );
  12798. this.map = null;
  12799. this.size = 1;
  12800. this.sizeAttenuation = true;
  12801. this.lights = false;
  12802. this.setValues( parameters );
  12803. }
  12804. PointsMaterial.prototype = Object.create( Material.prototype );
  12805. PointsMaterial.prototype.constructor = PointsMaterial;
  12806. PointsMaterial.prototype.isPointsMaterial = true;
  12807. PointsMaterial.prototype.copy = function ( source ) {
  12808. Material.prototype.copy.call( this, source );
  12809. this.color.copy( source.color );
  12810. this.map = source.map;
  12811. this.size = source.size;
  12812. this.sizeAttenuation = source.sizeAttenuation;
  12813. return this;
  12814. };
  12815. /**
  12816. * @author WestLangley / http://github.com/WestLangley
  12817. *
  12818. * parameters = {
  12819. * color: <hex>,
  12820. * roughness: <float>,
  12821. * metalness: <float>,
  12822. * opacity: <float>,
  12823. *
  12824. * map: new THREE.Texture( <Image> ),
  12825. *
  12826. * lightMap: new THREE.Texture( <Image> ),
  12827. * lightMapIntensity: <float>
  12828. *
  12829. * aoMap: new THREE.Texture( <Image> ),
  12830. * aoMapIntensity: <float>
  12831. *
  12832. * emissive: <hex>,
  12833. * emissiveIntensity: <float>
  12834. * emissiveMap: new THREE.Texture( <Image> ),
  12835. *
  12836. * bumpMap: new THREE.Texture( <Image> ),
  12837. * bumpScale: <float>,
  12838. *
  12839. * normalMap: new THREE.Texture( <Image> ),
  12840. * normalScale: <Vector2>,
  12841. *
  12842. * displacementMap: new THREE.Texture( <Image> ),
  12843. * displacementScale: <float>,
  12844. * displacementBias: <float>,
  12845. *
  12846. * roughnessMap: new THREE.Texture( <Image> ),
  12847. *
  12848. * metalnessMap: new THREE.Texture( <Image> ),
  12849. *
  12850. * alphaMap: new THREE.Texture( <Image> ),
  12851. *
  12852. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12853. * envMapIntensity: <float>
  12854. *
  12855. * refractionRatio: <float>,
  12856. *
  12857. * wireframe: <boolean>,
  12858. * wireframeLinewidth: <float>,
  12859. *
  12860. * skinning: <bool>,
  12861. * morphTargets: <bool>,
  12862. * morphNormals: <bool>
  12863. * }
  12864. */
  12865. function MeshStandardMaterial( parameters ) {
  12866. Material.call( this );
  12867. this.defines = { 'STANDARD': '' };
  12868. this.type = 'MeshStandardMaterial';
  12869. this.color = new Color( 0xffffff ); // diffuse
  12870. this.roughness = 0.5;
  12871. this.metalness = 0.5;
  12872. this.map = null;
  12873. this.lightMap = null;
  12874. this.lightMapIntensity = 1.0;
  12875. this.aoMap = null;
  12876. this.aoMapIntensity = 1.0;
  12877. this.emissive = new Color( 0x000000 );
  12878. this.emissiveIntensity = 1.0;
  12879. this.emissiveMap = null;
  12880. this.bumpMap = null;
  12881. this.bumpScale = 1;
  12882. this.normalMap = null;
  12883. this.normalScale = new Vector2( 1, 1 );
  12884. this.displacementMap = null;
  12885. this.displacementScale = 1;
  12886. this.displacementBias = 0;
  12887. this.roughnessMap = null;
  12888. this.metalnessMap = null;
  12889. this.alphaMap = null;
  12890. this.envMap = null;
  12891. this.envMapIntensity = 1.0;
  12892. this.refractionRatio = 0.98;
  12893. this.wireframe = false;
  12894. this.wireframeLinewidth = 1;
  12895. this.wireframeLinecap = 'round';
  12896. this.wireframeLinejoin = 'round';
  12897. this.skinning = false;
  12898. this.morphTargets = false;
  12899. this.morphNormals = false;
  12900. this.setValues( parameters );
  12901. }
  12902. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  12903. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  12904. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  12905. MeshStandardMaterial.prototype.copy = function ( source ) {
  12906. Material.prototype.copy.call( this, source );
  12907. this.defines = { 'STANDARD': '' };
  12908. this.color.copy( source.color );
  12909. this.roughness = source.roughness;
  12910. this.metalness = source.metalness;
  12911. this.map = source.map;
  12912. this.lightMap = source.lightMap;
  12913. this.lightMapIntensity = source.lightMapIntensity;
  12914. this.aoMap = source.aoMap;
  12915. this.aoMapIntensity = source.aoMapIntensity;
  12916. this.emissive.copy( source.emissive );
  12917. this.emissiveMap = source.emissiveMap;
  12918. this.emissiveIntensity = source.emissiveIntensity;
  12919. this.bumpMap = source.bumpMap;
  12920. this.bumpScale = source.bumpScale;
  12921. this.normalMap = source.normalMap;
  12922. this.normalScale.copy( source.normalScale );
  12923. this.displacementMap = source.displacementMap;
  12924. this.displacementScale = source.displacementScale;
  12925. this.displacementBias = source.displacementBias;
  12926. this.roughnessMap = source.roughnessMap;
  12927. this.metalnessMap = source.metalnessMap;
  12928. this.alphaMap = source.alphaMap;
  12929. this.envMap = source.envMap;
  12930. this.envMapIntensity = source.envMapIntensity;
  12931. this.refractionRatio = source.refractionRatio;
  12932. this.wireframe = source.wireframe;
  12933. this.wireframeLinewidth = source.wireframeLinewidth;
  12934. this.wireframeLinecap = source.wireframeLinecap;
  12935. this.wireframeLinejoin = source.wireframeLinejoin;
  12936. this.skinning = source.skinning;
  12937. this.morphTargets = source.morphTargets;
  12938. this.morphNormals = source.morphNormals;
  12939. return this;
  12940. };
  12941. /**
  12942. * @author WestLangley / http://github.com/WestLangley
  12943. *
  12944. * parameters = {
  12945. * reflectivity: <float>
  12946. * }
  12947. */
  12948. function MeshPhysicalMaterial( parameters ) {
  12949. MeshStandardMaterial.call( this );
  12950. this.defines = { 'PHYSICAL': '' };
  12951. this.type = 'MeshPhysicalMaterial';
  12952. this.reflectivity = 0.5; // maps to F0 = 0.04
  12953. this.clearCoat = 0.0;
  12954. this.clearCoatRoughness = 0.0;
  12955. this.setValues( parameters );
  12956. }
  12957. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  12958. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  12959. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  12960. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  12961. MeshStandardMaterial.prototype.copy.call( this, source );
  12962. this.defines = { 'PHYSICAL': '' };
  12963. this.reflectivity = source.reflectivity;
  12964. this.clearCoat = source.clearCoat;
  12965. this.clearCoatRoughness = source.clearCoatRoughness;
  12966. return this;
  12967. };
  12968. /**
  12969. * @author mrdoob / http://mrdoob.com/
  12970. * @author alteredq / http://alteredqualia.com/
  12971. *
  12972. * parameters = {
  12973. * color: <hex>,
  12974. * specular: <hex>,
  12975. * shininess: <float>,
  12976. * opacity: <float>,
  12977. *
  12978. * map: new THREE.Texture( <Image> ),
  12979. *
  12980. * lightMap: new THREE.Texture( <Image> ),
  12981. * lightMapIntensity: <float>
  12982. *
  12983. * aoMap: new THREE.Texture( <Image> ),
  12984. * aoMapIntensity: <float>
  12985. *
  12986. * emissive: <hex>,
  12987. * emissiveIntensity: <float>
  12988. * emissiveMap: new THREE.Texture( <Image> ),
  12989. *
  12990. * bumpMap: new THREE.Texture( <Image> ),
  12991. * bumpScale: <float>,
  12992. *
  12993. * normalMap: new THREE.Texture( <Image> ),
  12994. * normalScale: <Vector2>,
  12995. *
  12996. * displacementMap: new THREE.Texture( <Image> ),
  12997. * displacementScale: <float>,
  12998. * displacementBias: <float>,
  12999. *
  13000. * specularMap: new THREE.Texture( <Image> ),
  13001. *
  13002. * alphaMap: new THREE.Texture( <Image> ),
  13003. *
  13004. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  13005. * combine: THREE.Multiply,
  13006. * reflectivity: <float>,
  13007. * refractionRatio: <float>,
  13008. *
  13009. * wireframe: <boolean>,
  13010. * wireframeLinewidth: <float>,
  13011. *
  13012. * skinning: <bool>,
  13013. * morphTargets: <bool>,
  13014. * morphNormals: <bool>
  13015. * }
  13016. */
  13017. function MeshPhongMaterial( parameters ) {
  13018. Material.call( this );
  13019. this.type = 'MeshPhongMaterial';
  13020. this.color = new Color( 0xffffff ); // diffuse
  13021. this.specular = new Color( 0x111111 );
  13022. this.shininess = 30;
  13023. this.map = null;
  13024. this.lightMap = null;
  13025. this.lightMapIntensity = 1.0;
  13026. this.aoMap = null;
  13027. this.aoMapIntensity = 1.0;
  13028. this.emissive = new Color( 0x000000 );
  13029. this.emissiveIntensity = 1.0;
  13030. this.emissiveMap = null;
  13031. this.bumpMap = null;
  13032. this.bumpScale = 1;
  13033. this.normalMap = null;
  13034. this.normalScale = new Vector2( 1, 1 );
  13035. this.displacementMap = null;
  13036. this.displacementScale = 1;
  13037. this.displacementBias = 0;
  13038. this.specularMap = null;
  13039. this.alphaMap = null;
  13040. this.envMap = null;
  13041. this.combine = MultiplyOperation;
  13042. this.reflectivity = 1;
  13043. this.refractionRatio = 0.98;
  13044. this.wireframe = false;
  13045. this.wireframeLinewidth = 1;
  13046. this.wireframeLinecap = 'round';
  13047. this.wireframeLinejoin = 'round';
  13048. this.skinning = false;
  13049. this.morphTargets = false;
  13050. this.morphNormals = false;
  13051. this.setValues( parameters );
  13052. }
  13053. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  13054. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  13055. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  13056. MeshPhongMaterial.prototype.copy = function ( source ) {
  13057. Material.prototype.copy.call( this, source );
  13058. this.color.copy( source.color );
  13059. this.specular.copy( source.specular );
  13060. this.shininess = source.shininess;
  13061. this.map = source.map;
  13062. this.lightMap = source.lightMap;
  13063. this.lightMapIntensity = source.lightMapIntensity;
  13064. this.aoMap = source.aoMap;
  13065. this.aoMapIntensity = source.aoMapIntensity;
  13066. this.emissive.copy( source.emissive );
  13067. this.emissiveMap = source.emissiveMap;
  13068. this.emissiveIntensity = source.emissiveIntensity;
  13069. this.bumpMap = source.bumpMap;
  13070. this.bumpScale = source.bumpScale;
  13071. this.normalMap = source.normalMap;
  13072. this.normalScale.copy( source.normalScale );
  13073. this.displacementMap = source.displacementMap;
  13074. this.displacementScale = source.displacementScale;
  13075. this.displacementBias = source.displacementBias;
  13076. this.specularMap = source.specularMap;
  13077. this.alphaMap = source.alphaMap;
  13078. this.envMap = source.envMap;
  13079. this.combine = source.combine;
  13080. this.reflectivity = source.reflectivity;
  13081. this.refractionRatio = source.refractionRatio;
  13082. this.wireframe = source.wireframe;
  13083. this.wireframeLinewidth = source.wireframeLinewidth;
  13084. this.wireframeLinecap = source.wireframeLinecap;
  13085. this.wireframeLinejoin = source.wireframeLinejoin;
  13086. this.skinning = source.skinning;
  13087. this.morphTargets = source.morphTargets;
  13088. this.morphNormals = source.morphNormals;
  13089. return this;
  13090. };
  13091. /**
  13092. * @author takahirox / http://github.com/takahirox
  13093. *
  13094. * parameters = {
  13095. * gradientMap: new THREE.Texture( <Image> )
  13096. * }
  13097. */
  13098. function MeshToonMaterial( parameters ) {
  13099. MeshPhongMaterial.call( this );
  13100. this.defines = { 'TOON': '' };
  13101. this.type = 'MeshToonMaterial';
  13102. this.gradientMap = null;
  13103. this.setValues( parameters );
  13104. }
  13105. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  13106. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  13107. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  13108. MeshToonMaterial.prototype.copy = function ( source ) {
  13109. MeshPhongMaterial.prototype.copy.call( this, source );
  13110. this.gradientMap = source.gradientMap;
  13111. return this;
  13112. };
  13113. /**
  13114. * @author mrdoob / http://mrdoob.com/
  13115. * @author WestLangley / http://github.com/WestLangley
  13116. *
  13117. * parameters = {
  13118. * opacity: <float>,
  13119. *
  13120. * bumpMap: new THREE.Texture( <Image> ),
  13121. * bumpScale: <float>,
  13122. *
  13123. * normalMap: new THREE.Texture( <Image> ),
  13124. * normalScale: <Vector2>,
  13125. *
  13126. * displacementMap: new THREE.Texture( <Image> ),
  13127. * displacementScale: <float>,
  13128. * displacementBias: <float>,
  13129. *
  13130. * wireframe: <boolean>,
  13131. * wireframeLinewidth: <float>
  13132. *
  13133. * skinning: <bool>,
  13134. * morphTargets: <bool>,
  13135. * morphNormals: <bool>
  13136. * }
  13137. */
  13138. function MeshNormalMaterial( parameters ) {
  13139. Material.call( this );
  13140. this.type = 'MeshNormalMaterial';
  13141. this.bumpMap = null;
  13142. this.bumpScale = 1;
  13143. this.normalMap = null;
  13144. this.normalScale = new Vector2( 1, 1 );
  13145. this.displacementMap = null;
  13146. this.displacementScale = 1;
  13147. this.displacementBias = 0;
  13148. this.wireframe = false;
  13149. this.wireframeLinewidth = 1;
  13150. this.fog = false;
  13151. this.lights = false;
  13152. this.skinning = false;
  13153. this.morphTargets = false;
  13154. this.morphNormals = false;
  13155. this.setValues( parameters );
  13156. }
  13157. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  13158. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  13159. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  13160. MeshNormalMaterial.prototype.copy = function ( source ) {
  13161. Material.prototype.copy.call( this, source );
  13162. this.bumpMap = source.bumpMap;
  13163. this.bumpScale = source.bumpScale;
  13164. this.normalMap = source.normalMap;
  13165. this.normalScale.copy( source.normalScale );
  13166. this.displacementMap = source.displacementMap;
  13167. this.displacementScale = source.displacementScale;
  13168. this.displacementBias = source.displacementBias;
  13169. this.wireframe = source.wireframe;
  13170. this.wireframeLinewidth = source.wireframeLinewidth;
  13171. this.skinning = source.skinning;
  13172. this.morphTargets = source.morphTargets;
  13173. this.morphNormals = source.morphNormals;
  13174. return this;
  13175. };
  13176. /**
  13177. * @author mrdoob / http://mrdoob.com/
  13178. * @author alteredq / http://alteredqualia.com/
  13179. *
  13180. * parameters = {
  13181. * color: <hex>,
  13182. * opacity: <float>,
  13183. *
  13184. * map: new THREE.Texture( <Image> ),
  13185. *
  13186. * lightMap: new THREE.Texture( <Image> ),
  13187. * lightMapIntensity: <float>
  13188. *
  13189. * aoMap: new THREE.Texture( <Image> ),
  13190. * aoMapIntensity: <float>
  13191. *
  13192. * emissive: <hex>,
  13193. * emissiveIntensity: <float>
  13194. * emissiveMap: new THREE.Texture( <Image> ),
  13195. *
  13196. * specularMap: new THREE.Texture( <Image> ),
  13197. *
  13198. * alphaMap: new THREE.Texture( <Image> ),
  13199. *
  13200. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  13201. * combine: THREE.Multiply,
  13202. * reflectivity: <float>,
  13203. * refractionRatio: <float>,
  13204. *
  13205. * wireframe: <boolean>,
  13206. * wireframeLinewidth: <float>,
  13207. *
  13208. * skinning: <bool>,
  13209. * morphTargets: <bool>,
  13210. * morphNormals: <bool>
  13211. * }
  13212. */
  13213. function MeshLambertMaterial( parameters ) {
  13214. Material.call( this );
  13215. this.type = 'MeshLambertMaterial';
  13216. this.color = new Color( 0xffffff ); // diffuse
  13217. this.map = null;
  13218. this.lightMap = null;
  13219. this.lightMapIntensity = 1.0;
  13220. this.aoMap = null;
  13221. this.aoMapIntensity = 1.0;
  13222. this.emissive = new Color( 0x000000 );
  13223. this.emissiveIntensity = 1.0;
  13224. this.emissiveMap = null;
  13225. this.specularMap = null;
  13226. this.alphaMap = null;
  13227. this.envMap = null;
  13228. this.combine = MultiplyOperation;
  13229. this.reflectivity = 1;
  13230. this.refractionRatio = 0.98;
  13231. this.wireframe = false;
  13232. this.wireframeLinewidth = 1;
  13233. this.wireframeLinecap = 'round';
  13234. this.wireframeLinejoin = 'round';
  13235. this.skinning = false;
  13236. this.morphTargets = false;
  13237. this.morphNormals = false;
  13238. this.setValues( parameters );
  13239. }
  13240. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  13241. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  13242. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  13243. MeshLambertMaterial.prototype.copy = function ( source ) {
  13244. Material.prototype.copy.call( this, source );
  13245. this.color.copy( source.color );
  13246. this.map = source.map;
  13247. this.lightMap = source.lightMap;
  13248. this.lightMapIntensity = source.lightMapIntensity;
  13249. this.aoMap = source.aoMap;
  13250. this.aoMapIntensity = source.aoMapIntensity;
  13251. this.emissive.copy( source.emissive );
  13252. this.emissiveMap = source.emissiveMap;
  13253. this.emissiveIntensity = source.emissiveIntensity;
  13254. this.specularMap = source.specularMap;
  13255. this.alphaMap = source.alphaMap;
  13256. this.envMap = source.envMap;
  13257. this.combine = source.combine;
  13258. this.reflectivity = source.reflectivity;
  13259. this.refractionRatio = source.refractionRatio;
  13260. this.wireframe = source.wireframe;
  13261. this.wireframeLinewidth = source.wireframeLinewidth;
  13262. this.wireframeLinecap = source.wireframeLinecap;
  13263. this.wireframeLinejoin = source.wireframeLinejoin;
  13264. this.skinning = source.skinning;
  13265. this.morphTargets = source.morphTargets;
  13266. this.morphNormals = source.morphNormals;
  13267. return this;
  13268. };
  13269. /**
  13270. * @author mrdoob / http://mrdoob.com/
  13271. * @author alteredq / http://alteredqualia.com/
  13272. * @author bhouston / https://clara.io
  13273. * @author WestLangley / http://github.com/WestLangley
  13274. *
  13275. * parameters = {
  13276. *
  13277. * opacity: <float>,
  13278. *
  13279. * map: new THREE.Texture( <Image> ),
  13280. *
  13281. * alphaMap: new THREE.Texture( <Image> ),
  13282. *
  13283. * displacementMap: new THREE.Texture( <Image> ),
  13284. * displacementScale: <float>,
  13285. * displacementBias: <float>,
  13286. *
  13287. * wireframe: <boolean>,
  13288. * wireframeLinewidth: <float>
  13289. * }
  13290. */
  13291. function MeshDepthMaterial( parameters ) {
  13292. Material.call( this );
  13293. this.type = 'MeshDepthMaterial';
  13294. this.depthPacking = BasicDepthPacking;
  13295. this.skinning = false;
  13296. this.morphTargets = false;
  13297. this.map = null;
  13298. this.alphaMap = null;
  13299. this.displacementMap = null;
  13300. this.displacementScale = 1;
  13301. this.displacementBias = 0;
  13302. this.wireframe = false;
  13303. this.wireframeLinewidth = 1;
  13304. this.fog = false;
  13305. this.lights = false;
  13306. this.setValues( parameters );
  13307. }
  13308. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  13309. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  13310. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  13311. MeshDepthMaterial.prototype.copy = function ( source ) {
  13312. Material.prototype.copy.call( this, source );
  13313. this.depthPacking = source.depthPacking;
  13314. this.skinning = source.skinning;
  13315. this.morphTargets = source.morphTargets;
  13316. this.map = source.map;
  13317. this.alphaMap = source.alphaMap;
  13318. this.displacementMap = source.displacementMap;
  13319. this.displacementScale = source.displacementScale;
  13320. this.displacementBias = source.displacementBias;
  13321. this.wireframe = source.wireframe;
  13322. this.wireframeLinewidth = source.wireframeLinewidth;
  13323. return this;
  13324. };
  13325. /**
  13326. * @author WestLangley / http://github.com/WestLangley
  13327. *
  13328. * parameters = {
  13329. *
  13330. * referencePosition: <float>,
  13331. * nearDistance: <float>,
  13332. * farDistance: <float>,
  13333. *
  13334. * skinning: <bool>,
  13335. * morphTargets: <bool>,
  13336. *
  13337. * map: new THREE.Texture( <Image> ),
  13338. *
  13339. * alphaMap: new THREE.Texture( <Image> ),
  13340. *
  13341. * displacementMap: new THREE.Texture( <Image> ),
  13342. * displacementScale: <float>,
  13343. * displacementBias: <float>
  13344. *
  13345. * }
  13346. */
  13347. function MeshDistanceMaterial( parameters ) {
  13348. Material.call( this );
  13349. this.type = 'MeshDistanceMaterial';
  13350. this.referencePosition = new Vector3();
  13351. this.nearDistance = 1;
  13352. this.farDistance = 1000;
  13353. this.skinning = false;
  13354. this.morphTargets = false;
  13355. this.map = null;
  13356. this.alphaMap = null;
  13357. this.displacementMap = null;
  13358. this.displacementScale = 1;
  13359. this.displacementBias = 0;
  13360. this.fog = false;
  13361. this.lights = false;
  13362. this.setValues( parameters );
  13363. }
  13364. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  13365. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  13366. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  13367. MeshDistanceMaterial.prototype.copy = function ( source ) {
  13368. Material.prototype.copy.call( this, source );
  13369. this.referencePosition.copy( source.referencePosition );
  13370. this.nearDistance = source.nearDistance;
  13371. this.farDistance = source.farDistance;
  13372. this.skinning = source.skinning;
  13373. this.morphTargets = source.morphTargets;
  13374. this.map = source.map;
  13375. this.alphaMap = source.alphaMap;
  13376. this.displacementMap = source.displacementMap;
  13377. this.displacementScale = source.displacementScale;
  13378. this.displacementBias = source.displacementBias;
  13379. return this;
  13380. };
  13381. /**
  13382. * @author mrdoob / http://mrdoob.com/
  13383. * @author alteredq / http://alteredqualia.com/
  13384. *
  13385. * parameters = {
  13386. * color: <hex>,
  13387. * opacity: <float>,
  13388. *
  13389. * linewidth: <float>,
  13390. * linecap: "round",
  13391. * linejoin: "round"
  13392. * }
  13393. */
  13394. function LineBasicMaterial( parameters ) {
  13395. Material.call( this );
  13396. this.type = 'LineBasicMaterial';
  13397. this.color = new Color( 0xffffff );
  13398. this.linewidth = 1;
  13399. this.linecap = 'round';
  13400. this.linejoin = 'round';
  13401. this.lights = false;
  13402. this.setValues( parameters );
  13403. }
  13404. LineBasicMaterial.prototype = Object.create( Material.prototype );
  13405. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  13406. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  13407. LineBasicMaterial.prototype.copy = function ( source ) {
  13408. Material.prototype.copy.call( this, source );
  13409. this.color.copy( source.color );
  13410. this.linewidth = source.linewidth;
  13411. this.linecap = source.linecap;
  13412. this.linejoin = source.linejoin;
  13413. return this;
  13414. };
  13415. /**
  13416. * @author alteredq / http://alteredqualia.com/
  13417. *
  13418. * parameters = {
  13419. * color: <hex>,
  13420. * opacity: <float>,
  13421. *
  13422. * linewidth: <float>,
  13423. *
  13424. * scale: <float>,
  13425. * dashSize: <float>,
  13426. * gapSize: <float>
  13427. * }
  13428. */
  13429. function LineDashedMaterial( parameters ) {
  13430. LineBasicMaterial.call( this );
  13431. this.type = 'LineDashedMaterial';
  13432. this.scale = 1;
  13433. this.dashSize = 3;
  13434. this.gapSize = 1;
  13435. this.setValues( parameters );
  13436. }
  13437. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  13438. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  13439. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  13440. LineDashedMaterial.prototype.copy = function ( source ) {
  13441. LineBasicMaterial.prototype.copy.call( this, source );
  13442. this.scale = source.scale;
  13443. this.dashSize = source.dashSize;
  13444. this.gapSize = source.gapSize;
  13445. return this;
  13446. };
  13447. var Materials = Object.freeze({
  13448. ShadowMaterial: ShadowMaterial,
  13449. SpriteMaterial: SpriteMaterial,
  13450. RawShaderMaterial: RawShaderMaterial,
  13451. ShaderMaterial: ShaderMaterial,
  13452. PointsMaterial: PointsMaterial,
  13453. MeshPhysicalMaterial: MeshPhysicalMaterial,
  13454. MeshStandardMaterial: MeshStandardMaterial,
  13455. MeshPhongMaterial: MeshPhongMaterial,
  13456. MeshToonMaterial: MeshToonMaterial,
  13457. MeshNormalMaterial: MeshNormalMaterial,
  13458. MeshLambertMaterial: MeshLambertMaterial,
  13459. MeshDepthMaterial: MeshDepthMaterial,
  13460. MeshDistanceMaterial: MeshDistanceMaterial,
  13461. MeshBasicMaterial: MeshBasicMaterial,
  13462. LineDashedMaterial: LineDashedMaterial,
  13463. LineBasicMaterial: LineBasicMaterial,
  13464. Material: Material
  13465. });
  13466. /**
  13467. * @author mrdoob / http://mrdoob.com/
  13468. */
  13469. function MaterialLoader( manager ) {
  13470. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  13471. this.textures = {};
  13472. }
  13473. Object.assign( MaterialLoader.prototype, {
  13474. load: function ( url, onLoad, onProgress, onError ) {
  13475. var scope = this;
  13476. var loader = new FileLoader( scope.manager );
  13477. loader.load( url, function ( text ) {
  13478. onLoad( scope.parse( JSON.parse( text ) ) );
  13479. }, onProgress, onError );
  13480. },
  13481. setTextures: function ( value ) {
  13482. this.textures = value;
  13483. },
  13484. parse: function ( json ) {
  13485. var textures = this.textures;
  13486. function getTexture( name ) {
  13487. if ( textures[ name ] === undefined ) {
  13488. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  13489. }
  13490. return textures[ name ];
  13491. }
  13492. var material = new Materials[ json.type ]();
  13493. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  13494. if ( json.name !== undefined ) material.name = json.name;
  13495. if ( json.color !== undefined ) material.color.setHex( json.color );
  13496. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  13497. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  13498. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  13499. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  13500. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  13501. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  13502. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  13503. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  13504. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  13505. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  13506. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  13507. if ( json.fog !== undefined ) material.fog = json.fog;
  13508. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  13509. if ( json.blending !== undefined ) material.blending = json.blending;
  13510. if ( json.side !== undefined ) material.side = json.side;
  13511. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  13512. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  13513. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  13514. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  13515. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  13516. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  13517. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  13518. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  13519. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  13520. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  13521. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  13522. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  13523. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  13524. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  13525. if ( json.scale !== undefined ) material.scale = json.scale;
  13526. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  13527. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  13528. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  13529. if ( json.visible !== undefined ) material.visible = json.visible;
  13530. if ( json.userData !== undefined ) material.userData = json.userData;
  13531. // Deprecated
  13532. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  13533. // for PointsMaterial
  13534. if ( json.size !== undefined ) material.size = json.size;
  13535. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  13536. // maps
  13537. if ( json.map !== undefined ) material.map = getTexture( json.map );
  13538. if ( json.alphaMap !== undefined ) {
  13539. material.alphaMap = getTexture( json.alphaMap );
  13540. material.transparent = true;
  13541. }
  13542. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  13543. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  13544. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  13545. if ( json.normalScale !== undefined ) {
  13546. var normalScale = json.normalScale;
  13547. if ( Array.isArray( normalScale ) === false ) {
  13548. // Blender exporter used to export a scalar. See #7459
  13549. normalScale = [ normalScale, normalScale ];
  13550. }
  13551. material.normalScale = new Vector2().fromArray( normalScale );
  13552. }
  13553. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  13554. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  13555. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  13556. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  13557. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  13558. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  13559. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  13560. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  13561. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  13562. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  13563. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  13564. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  13565. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  13566. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  13567. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  13568. return material;
  13569. }
  13570. } );
  13571. /**
  13572. * @author mrdoob / http://mrdoob.com/
  13573. */
  13574. function ImageLoader( manager ) {
  13575. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  13576. }
  13577. Object.assign( ImageLoader.prototype, {
  13578. crossOrigin: 'Anonymous',
  13579. load: function ( url, onLoad, onProgress, onError ) {
  13580. if ( url === undefined ) url = '';
  13581. if ( this.path !== undefined ) url = this.path + url;
  13582. url = this.manager.resolveURL( url );
  13583. var scope = this;
  13584. var cached = Cache.get( url );
  13585. if ( cached !== undefined ) {
  13586. scope.manager.itemStart( url );
  13587. setTimeout( function () {
  13588. if ( onLoad ) onLoad( cached );
  13589. scope.manager.itemEnd( url );
  13590. }, 0 );
  13591. return cached;
  13592. }
  13593. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  13594. image.addEventListener( 'load', function () {
  13595. Cache.add( url, this );
  13596. if ( onLoad ) onLoad( this );
  13597. scope.manager.itemEnd( url );
  13598. }, false );
  13599. /*
  13600. image.addEventListener( 'progress', function ( event ) {
  13601. if ( onProgress ) onProgress( event );
  13602. }, false );
  13603. */
  13604. image.addEventListener( 'error', function ( event ) {
  13605. if ( onError ) onError( event );
  13606. scope.manager.itemEnd( url );
  13607. scope.manager.itemError( url );
  13608. }, false );
  13609. if ( url.substr( 0, 5 ) !== 'data:' ) {
  13610. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  13611. }
  13612. scope.manager.itemStart( url );
  13613. image.src = url;
  13614. return image;
  13615. },
  13616. setCrossOrigin: function ( value ) {
  13617. this.crossOrigin = value;
  13618. return this;
  13619. },
  13620. setPath: function ( value ) {
  13621. this.path = value;
  13622. return this;
  13623. }
  13624. } );
  13625. /**
  13626. * @author mrdoob / http://mrdoob.com/
  13627. */
  13628. function TextureLoader( manager ) {
  13629. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  13630. }
  13631. Object.assign( TextureLoader.prototype, {
  13632. crossOrigin: 'Anonymous',
  13633. load: function ( url, onLoad, onProgress, onError ) {
  13634. var loader = new ImageLoader( this.manager );
  13635. loader.setCrossOrigin( this.crossOrigin );
  13636. loader.setPath( this.path );
  13637. var texture = new Texture();
  13638. texture.image = loader.load( url, function () {
  13639. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  13640. var isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  13641. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  13642. texture.needsUpdate = true;
  13643. if ( onLoad !== undefined ) {
  13644. onLoad( texture );
  13645. }
  13646. }, onProgress, onError );
  13647. return texture;
  13648. },
  13649. setCrossOrigin: function ( value ) {
  13650. this.crossOrigin = value;
  13651. return this;
  13652. },
  13653. setPath: function ( value ) {
  13654. this.path = value;
  13655. return this;
  13656. }
  13657. } );
  13658. /**
  13659. * @author alteredq / http://alteredqualia.com/
  13660. */
  13661. function Loader() {
  13662. this.onLoadStart = function () {};
  13663. this.onLoadProgress = function () {};
  13664. this.onLoadComplete = function () {};
  13665. }
  13666. Loader.Handlers = {
  13667. handlers: [],
  13668. add: function ( regex, loader ) {
  13669. this.handlers.push( regex, loader );
  13670. },
  13671. get: function ( file ) {
  13672. var handlers = this.handlers;
  13673. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  13674. var regex = handlers[ i ];
  13675. var loader = handlers[ i + 1 ];
  13676. if ( regex.test( file ) ) {
  13677. return loader;
  13678. }
  13679. }
  13680. return null;
  13681. }
  13682. };
  13683. Object.assign( Loader.prototype, {
  13684. crossOrigin: undefined,
  13685. extractUrlBase: function ( url ) {
  13686. var parts = url.split( '/' );
  13687. if ( parts.length === 1 ) return './';
  13688. parts.pop();
  13689. return parts.join( '/' ) + '/';
  13690. },
  13691. initMaterials: function ( materials, texturePath, crossOrigin ) {
  13692. var array = [];
  13693. for ( var i = 0; i < materials.length; ++ i ) {
  13694. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  13695. }
  13696. return array;
  13697. },
  13698. createMaterial: ( function () {
  13699. var BlendingMode = {
  13700. NoBlending: NoBlending,
  13701. NormalBlending: NormalBlending,
  13702. AdditiveBlending: AdditiveBlending,
  13703. SubtractiveBlending: SubtractiveBlending,
  13704. MultiplyBlending: MultiplyBlending,
  13705. CustomBlending: CustomBlending
  13706. };
  13707. var color = new Color();
  13708. var textureLoader = new TextureLoader();
  13709. var materialLoader = new MaterialLoader();
  13710. return function createMaterial( m, texturePath, crossOrigin ) {
  13711. // convert from old material format
  13712. var textures = {};
  13713. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  13714. var fullPath = texturePath + path;
  13715. var loader = Loader.Handlers.get( fullPath );
  13716. var texture;
  13717. if ( loader !== null ) {
  13718. texture = loader.load( fullPath );
  13719. } else {
  13720. textureLoader.setCrossOrigin( crossOrigin );
  13721. texture = textureLoader.load( fullPath );
  13722. }
  13723. if ( repeat !== undefined ) {
  13724. texture.repeat.fromArray( repeat );
  13725. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  13726. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  13727. }
  13728. if ( offset !== undefined ) {
  13729. texture.offset.fromArray( offset );
  13730. }
  13731. if ( wrap !== undefined ) {
  13732. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  13733. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  13734. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  13735. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  13736. }
  13737. if ( anisotropy !== undefined ) {
  13738. texture.anisotropy = anisotropy;
  13739. }
  13740. var uuid = _Math.generateUUID();
  13741. textures[ uuid ] = texture;
  13742. return uuid;
  13743. }
  13744. //
  13745. var json = {
  13746. uuid: _Math.generateUUID(),
  13747. type: 'MeshLambertMaterial'
  13748. };
  13749. for ( var name in m ) {
  13750. var value = m[ name ];
  13751. switch ( name ) {
  13752. case 'DbgColor':
  13753. case 'DbgIndex':
  13754. case 'opticalDensity':
  13755. case 'illumination':
  13756. break;
  13757. case 'DbgName':
  13758. json.name = value;
  13759. break;
  13760. case 'blending':
  13761. json.blending = BlendingMode[ value ];
  13762. break;
  13763. case 'colorAmbient':
  13764. case 'mapAmbient':
  13765. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  13766. break;
  13767. case 'colorDiffuse':
  13768. json.color = color.fromArray( value ).getHex();
  13769. break;
  13770. case 'colorSpecular':
  13771. json.specular = color.fromArray( value ).getHex();
  13772. break;
  13773. case 'colorEmissive':
  13774. json.emissive = color.fromArray( value ).getHex();
  13775. break;
  13776. case 'specularCoef':
  13777. json.shininess = value;
  13778. break;
  13779. case 'shading':
  13780. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  13781. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  13782. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  13783. break;
  13784. case 'mapDiffuse':
  13785. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  13786. break;
  13787. case 'mapDiffuseRepeat':
  13788. case 'mapDiffuseOffset':
  13789. case 'mapDiffuseWrap':
  13790. case 'mapDiffuseAnisotropy':
  13791. break;
  13792. case 'mapEmissive':
  13793. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  13794. break;
  13795. case 'mapEmissiveRepeat':
  13796. case 'mapEmissiveOffset':
  13797. case 'mapEmissiveWrap':
  13798. case 'mapEmissiveAnisotropy':
  13799. break;
  13800. case 'mapLight':
  13801. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  13802. break;
  13803. case 'mapLightRepeat':
  13804. case 'mapLightOffset':
  13805. case 'mapLightWrap':
  13806. case 'mapLightAnisotropy':
  13807. break;
  13808. case 'mapAO':
  13809. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  13810. break;
  13811. case 'mapAORepeat':
  13812. case 'mapAOOffset':
  13813. case 'mapAOWrap':
  13814. case 'mapAOAnisotropy':
  13815. break;
  13816. case 'mapBump':
  13817. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  13818. break;
  13819. case 'mapBumpScale':
  13820. json.bumpScale = value;
  13821. break;
  13822. case 'mapBumpRepeat':
  13823. case 'mapBumpOffset':
  13824. case 'mapBumpWrap':
  13825. case 'mapBumpAnisotropy':
  13826. break;
  13827. case 'mapNormal':
  13828. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  13829. break;
  13830. case 'mapNormalFactor':
  13831. json.normalScale = [ value, value ];
  13832. break;
  13833. case 'mapNormalRepeat':
  13834. case 'mapNormalOffset':
  13835. case 'mapNormalWrap':
  13836. case 'mapNormalAnisotropy':
  13837. break;
  13838. case 'mapSpecular':
  13839. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  13840. break;
  13841. case 'mapSpecularRepeat':
  13842. case 'mapSpecularOffset':
  13843. case 'mapSpecularWrap':
  13844. case 'mapSpecularAnisotropy':
  13845. break;
  13846. case 'mapMetalness':
  13847. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  13848. break;
  13849. case 'mapMetalnessRepeat':
  13850. case 'mapMetalnessOffset':
  13851. case 'mapMetalnessWrap':
  13852. case 'mapMetalnessAnisotropy':
  13853. break;
  13854. case 'mapRoughness':
  13855. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  13856. break;
  13857. case 'mapRoughnessRepeat':
  13858. case 'mapRoughnessOffset':
  13859. case 'mapRoughnessWrap':
  13860. case 'mapRoughnessAnisotropy':
  13861. break;
  13862. case 'mapAlpha':
  13863. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  13864. break;
  13865. case 'mapAlphaRepeat':
  13866. case 'mapAlphaOffset':
  13867. case 'mapAlphaWrap':
  13868. case 'mapAlphaAnisotropy':
  13869. break;
  13870. case 'flipSided':
  13871. json.side = BackSide;
  13872. break;
  13873. case 'doubleSided':
  13874. json.side = DoubleSide;
  13875. break;
  13876. case 'transparency':
  13877. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  13878. json.opacity = value;
  13879. break;
  13880. case 'depthTest':
  13881. case 'depthWrite':
  13882. case 'colorWrite':
  13883. case 'opacity':
  13884. case 'reflectivity':
  13885. case 'transparent':
  13886. case 'visible':
  13887. case 'wireframe':
  13888. json[ name ] = value;
  13889. break;
  13890. case 'vertexColors':
  13891. if ( value === true ) json.vertexColors = VertexColors;
  13892. if ( value === 'face' ) json.vertexColors = FaceColors;
  13893. break;
  13894. default:
  13895. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  13896. break;
  13897. }
  13898. }
  13899. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  13900. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  13901. if ( json.opacity < 1 ) json.transparent = true;
  13902. materialLoader.setTextures( textures );
  13903. return materialLoader.parse( json );
  13904. };
  13905. } )()
  13906. } );
  13907. /**
  13908. * @author mrdoob / http://mrdoob.com/
  13909. * @author alteredq / http://alteredqualia.com/
  13910. */
  13911. function JSONLoader( manager ) {
  13912. if ( typeof manager === 'boolean' ) {
  13913. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  13914. manager = undefined;
  13915. }
  13916. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  13917. this.withCredentials = false;
  13918. }
  13919. Object.assign( JSONLoader.prototype, {
  13920. load: function ( url, onLoad, onProgress, onError ) {
  13921. var scope = this;
  13922. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : Loader.prototype.extractUrlBase( url );
  13923. var loader = new FileLoader( this.manager );
  13924. loader.setWithCredentials( this.withCredentials );
  13925. loader.load( url, function ( text ) {
  13926. var json = JSON.parse( text );
  13927. var metadata = json.metadata;
  13928. if ( metadata !== undefined ) {
  13929. var type = metadata.type;
  13930. if ( type !== undefined ) {
  13931. if ( type.toLowerCase() === 'object' ) {
  13932. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  13933. return;
  13934. }
  13935. if ( type.toLowerCase() === 'scene' ) {
  13936. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  13937. return;
  13938. }
  13939. }
  13940. }
  13941. var object = scope.parse( json, texturePath );
  13942. onLoad( object.geometry, object.materials );
  13943. }, onProgress, onError );
  13944. },
  13945. setTexturePath: function ( value ) {
  13946. this.texturePath = value;
  13947. },
  13948. parse: ( function () {
  13949. function parseModel( json, geometry ) {
  13950. function isBitSet( value, position ) {
  13951. return value & ( 1 << position );
  13952. }
  13953. var i, j, fi,
  13954. offset, zLength,
  13955. colorIndex, normalIndex, uvIndex, materialIndex,
  13956. type,
  13957. isQuad,
  13958. hasMaterial,
  13959. hasFaceVertexUv,
  13960. hasFaceNormal, hasFaceVertexNormal,
  13961. hasFaceColor, hasFaceVertexColor,
  13962. vertex, face, faceA, faceB, hex, normal,
  13963. uvLayer, uv, u, v,
  13964. faces = json.faces,
  13965. vertices = json.vertices,
  13966. normals = json.normals,
  13967. colors = json.colors,
  13968. scale = json.scale,
  13969. nUvLayers = 0;
  13970. if ( json.uvs !== undefined ) {
  13971. // disregard empty arrays
  13972. for ( i = 0; i < json.uvs.length; i ++ ) {
  13973. if ( json.uvs[ i ].length ) nUvLayers ++;
  13974. }
  13975. for ( i = 0; i < nUvLayers; i ++ ) {
  13976. geometry.faceVertexUvs[ i ] = [];
  13977. }
  13978. }
  13979. offset = 0;
  13980. zLength = vertices.length;
  13981. while ( offset < zLength ) {
  13982. vertex = new Vector3();
  13983. vertex.x = vertices[ offset ++ ] * scale;
  13984. vertex.y = vertices[ offset ++ ] * scale;
  13985. vertex.z = vertices[ offset ++ ] * scale;
  13986. geometry.vertices.push( vertex );
  13987. }
  13988. offset = 0;
  13989. zLength = faces.length;
  13990. while ( offset < zLength ) {
  13991. type = faces[ offset ++ ];
  13992. isQuad = isBitSet( type, 0 );
  13993. hasMaterial = isBitSet( type, 1 );
  13994. hasFaceVertexUv = isBitSet( type, 3 );
  13995. hasFaceNormal = isBitSet( type, 4 );
  13996. hasFaceVertexNormal = isBitSet( type, 5 );
  13997. hasFaceColor = isBitSet( type, 6 );
  13998. hasFaceVertexColor = isBitSet( type, 7 );
  13999. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  14000. if ( isQuad ) {
  14001. faceA = new Face3();
  14002. faceA.a = faces[ offset ];
  14003. faceA.b = faces[ offset + 1 ];
  14004. faceA.c = faces[ offset + 3 ];
  14005. faceB = new Face3();
  14006. faceB.a = faces[ offset + 1 ];
  14007. faceB.b = faces[ offset + 2 ];
  14008. faceB.c = faces[ offset + 3 ];
  14009. offset += 4;
  14010. if ( hasMaterial ) {
  14011. materialIndex = faces[ offset ++ ];
  14012. faceA.materialIndex = materialIndex;
  14013. faceB.materialIndex = materialIndex;
  14014. }
  14015. // to get face <=> uv index correspondence
  14016. fi = geometry.faces.length;
  14017. if ( hasFaceVertexUv ) {
  14018. for ( i = 0; i < nUvLayers; i ++ ) {
  14019. uvLayer = json.uvs[ i ];
  14020. geometry.faceVertexUvs[ i ][ fi ] = [];
  14021. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  14022. for ( j = 0; j < 4; j ++ ) {
  14023. uvIndex = faces[ offset ++ ];
  14024. u = uvLayer[ uvIndex * 2 ];
  14025. v = uvLayer[ uvIndex * 2 + 1 ];
  14026. uv = new Vector2( u, v );
  14027. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  14028. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  14029. }
  14030. }
  14031. }
  14032. if ( hasFaceNormal ) {
  14033. normalIndex = faces[ offset ++ ] * 3;
  14034. faceA.normal.set(
  14035. normals[ normalIndex ++ ],
  14036. normals[ normalIndex ++ ],
  14037. normals[ normalIndex ]
  14038. );
  14039. faceB.normal.copy( faceA.normal );
  14040. }
  14041. if ( hasFaceVertexNormal ) {
  14042. for ( i = 0; i < 4; i ++ ) {
  14043. normalIndex = faces[ offset ++ ] * 3;
  14044. normal = new Vector3(
  14045. normals[ normalIndex ++ ],
  14046. normals[ normalIndex ++ ],
  14047. normals[ normalIndex ]
  14048. );
  14049. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  14050. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  14051. }
  14052. }
  14053. if ( hasFaceColor ) {
  14054. colorIndex = faces[ offset ++ ];
  14055. hex = colors[ colorIndex ];
  14056. faceA.color.setHex( hex );
  14057. faceB.color.setHex( hex );
  14058. }
  14059. if ( hasFaceVertexColor ) {
  14060. for ( i = 0; i < 4; i ++ ) {
  14061. colorIndex = faces[ offset ++ ];
  14062. hex = colors[ colorIndex ];
  14063. if ( i !== 2 ) faceA.vertexColors.push( new Color( hex ) );
  14064. if ( i !== 0 ) faceB.vertexColors.push( new Color( hex ) );
  14065. }
  14066. }
  14067. geometry.faces.push( faceA );
  14068. geometry.faces.push( faceB );
  14069. } else {
  14070. face = new Face3();
  14071. face.a = faces[ offset ++ ];
  14072. face.b = faces[ offset ++ ];
  14073. face.c = faces[ offset ++ ];
  14074. if ( hasMaterial ) {
  14075. materialIndex = faces[ offset ++ ];
  14076. face.materialIndex = materialIndex;
  14077. }
  14078. // to get face <=> uv index correspondence
  14079. fi = geometry.faces.length;
  14080. if ( hasFaceVertexUv ) {
  14081. for ( i = 0; i < nUvLayers; i ++ ) {
  14082. uvLayer = json.uvs[ i ];
  14083. geometry.faceVertexUvs[ i ][ fi ] = [];
  14084. for ( j = 0; j < 3; j ++ ) {
  14085. uvIndex = faces[ offset ++ ];
  14086. u = uvLayer[ uvIndex * 2 ];
  14087. v = uvLayer[ uvIndex * 2 + 1 ];
  14088. uv = new Vector2( u, v );
  14089. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  14090. }
  14091. }
  14092. }
  14093. if ( hasFaceNormal ) {
  14094. normalIndex = faces[ offset ++ ] * 3;
  14095. face.normal.set(
  14096. normals[ normalIndex ++ ],
  14097. normals[ normalIndex ++ ],
  14098. normals[ normalIndex ]
  14099. );
  14100. }
  14101. if ( hasFaceVertexNormal ) {
  14102. for ( i = 0; i < 3; i ++ ) {
  14103. normalIndex = faces[ offset ++ ] * 3;
  14104. normal = new Vector3(
  14105. normals[ normalIndex ++ ],
  14106. normals[ normalIndex ++ ],
  14107. normals[ normalIndex ]
  14108. );
  14109. face.vertexNormals.push( normal );
  14110. }
  14111. }
  14112. if ( hasFaceColor ) {
  14113. colorIndex = faces[ offset ++ ];
  14114. face.color.setHex( colors[ colorIndex ] );
  14115. }
  14116. if ( hasFaceVertexColor ) {
  14117. for ( i = 0; i < 3; i ++ ) {
  14118. colorIndex = faces[ offset ++ ];
  14119. face.vertexColors.push( new Color( colors[ colorIndex ] ) );
  14120. }
  14121. }
  14122. geometry.faces.push( face );
  14123. }
  14124. }
  14125. }
  14126. function parseSkin( json, geometry ) {
  14127. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  14128. if ( json.skinWeights ) {
  14129. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  14130. var x = json.skinWeights[ i ];
  14131. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  14132. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  14133. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  14134. geometry.skinWeights.push( new Vector4( x, y, z, w ) );
  14135. }
  14136. }
  14137. if ( json.skinIndices ) {
  14138. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  14139. var a = json.skinIndices[ i ];
  14140. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  14141. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  14142. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  14143. geometry.skinIndices.push( new Vector4( a, b, c, d ) );
  14144. }
  14145. }
  14146. geometry.bones = json.bones;
  14147. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  14148. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  14149. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  14150. }
  14151. }
  14152. function parseMorphing( json, geometry ) {
  14153. var scale = json.scale;
  14154. if ( json.morphTargets !== undefined ) {
  14155. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  14156. geometry.morphTargets[ i ] = {};
  14157. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  14158. geometry.morphTargets[ i ].vertices = [];
  14159. var dstVertices = geometry.morphTargets[ i ].vertices;
  14160. var srcVertices = json.morphTargets[ i ].vertices;
  14161. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  14162. var vertex = new Vector3();
  14163. vertex.x = srcVertices[ v ] * scale;
  14164. vertex.y = srcVertices[ v + 1 ] * scale;
  14165. vertex.z = srcVertices[ v + 2 ] * scale;
  14166. dstVertices.push( vertex );
  14167. }
  14168. }
  14169. }
  14170. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  14171. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  14172. var faces = geometry.faces;
  14173. var morphColors = json.morphColors[ 0 ].colors;
  14174. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  14175. faces[ i ].color.fromArray( morphColors, i * 3 );
  14176. }
  14177. }
  14178. }
  14179. function parseAnimations( json, geometry ) {
  14180. var outputAnimations = [];
  14181. // parse old style Bone/Hierarchy animations
  14182. var animations = [];
  14183. if ( json.animation !== undefined ) {
  14184. animations.push( json.animation );
  14185. }
  14186. if ( json.animations !== undefined ) {
  14187. if ( json.animations.length ) {
  14188. animations = animations.concat( json.animations );
  14189. } else {
  14190. animations.push( json.animations );
  14191. }
  14192. }
  14193. for ( var i = 0; i < animations.length; i ++ ) {
  14194. var clip = AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  14195. if ( clip ) outputAnimations.push( clip );
  14196. }
  14197. // parse implicit morph animations
  14198. if ( geometry.morphTargets ) {
  14199. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  14200. var morphAnimationClips = AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  14201. outputAnimations = outputAnimations.concat( morphAnimationClips );
  14202. }
  14203. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  14204. }
  14205. return function ( json, texturePath ) {
  14206. if ( json.data !== undefined ) {
  14207. // Geometry 4.0 spec
  14208. json = json.data;
  14209. }
  14210. if ( json.scale !== undefined ) {
  14211. json.scale = 1.0 / json.scale;
  14212. } else {
  14213. json.scale = 1.0;
  14214. }
  14215. var geometry = new Geometry();
  14216. parseModel( json, geometry );
  14217. parseSkin( json, geometry );
  14218. parseMorphing( json, geometry );
  14219. parseAnimations( json, geometry );
  14220. geometry.computeFaceNormals();
  14221. geometry.computeBoundingSphere();
  14222. if ( json.materials === undefined || json.materials.length === 0 ) {
  14223. return { geometry: geometry };
  14224. } else {
  14225. var materials = Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  14226. return { geometry: geometry, materials: materials };
  14227. }
  14228. };
  14229. } )()
  14230. } );
  14231. /**
  14232. * @author mrdoob / http://mrdoob.com/
  14233. */
  14234. function Line( geometry, material, mode ) {
  14235. if ( mode === 1 ) {
  14236. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  14237. return new LineSegments( geometry, material );
  14238. }
  14239. Object3D.call( this );
  14240. this.type = 'Line';
  14241. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  14242. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  14243. }
  14244. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14245. constructor: Line,
  14246. isLine: true,
  14247. raycast: ( function () {
  14248. var inverseMatrix = new Matrix4();
  14249. var ray = new Ray();
  14250. var sphere = new Sphere();
  14251. return function raycast( raycaster, intersects ) {
  14252. var precision = raycaster.linePrecision;
  14253. var precisionSq = precision * precision;
  14254. var geometry = this.geometry;
  14255. var matrixWorld = this.matrixWorld;
  14256. // Checking boundingSphere distance to ray
  14257. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  14258. sphere.copy( geometry.boundingSphere );
  14259. sphere.applyMatrix4( matrixWorld );
  14260. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  14261. //
  14262. inverseMatrix.getInverse( matrixWorld );
  14263. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  14264. var vStart = new Vector3();
  14265. var vEnd = new Vector3();
  14266. var interSegment = new Vector3();
  14267. var interRay = new Vector3();
  14268. var step = ( this && this.isLineSegments ) ? 2 : 1;
  14269. if ( geometry.isBufferGeometry ) {
  14270. var index = geometry.index;
  14271. var attributes = geometry.attributes;
  14272. var positions = attributes.position.array;
  14273. if ( index !== null ) {
  14274. var indices = index.array;
  14275. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  14276. var a = indices[ i ];
  14277. var b = indices[ i + 1 ];
  14278. vStart.fromArray( positions, a * 3 );
  14279. vEnd.fromArray( positions, b * 3 );
  14280. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14281. if ( distSq > precisionSq ) continue;
  14282. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14283. var distance = raycaster.ray.origin.distanceTo( interRay );
  14284. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14285. intersects.push( {
  14286. distance: distance,
  14287. // What do we want? intersection point on the ray or on the segment??
  14288. // point: raycaster.ray.at( distance ),
  14289. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14290. index: i,
  14291. face: null,
  14292. faceIndex: null,
  14293. object: this
  14294. } );
  14295. }
  14296. } else {
  14297. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  14298. vStart.fromArray( positions, 3 * i );
  14299. vEnd.fromArray( positions, 3 * i + 3 );
  14300. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14301. if ( distSq > precisionSq ) continue;
  14302. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14303. var distance = raycaster.ray.origin.distanceTo( interRay );
  14304. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14305. intersects.push( {
  14306. distance: distance,
  14307. // What do we want? intersection point on the ray or on the segment??
  14308. // point: raycaster.ray.at( distance ),
  14309. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14310. index: i,
  14311. face: null,
  14312. faceIndex: null,
  14313. object: this
  14314. } );
  14315. }
  14316. }
  14317. } else if ( geometry.isGeometry ) {
  14318. var vertices = geometry.vertices;
  14319. var nbVertices = vertices.length;
  14320. for ( var i = 0; i < nbVertices - 1; i += step ) {
  14321. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  14322. if ( distSq > precisionSq ) continue;
  14323. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14324. var distance = raycaster.ray.origin.distanceTo( interRay );
  14325. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14326. intersects.push( {
  14327. distance: distance,
  14328. // What do we want? intersection point on the ray or on the segment??
  14329. // point: raycaster.ray.at( distance ),
  14330. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14331. index: i,
  14332. face: null,
  14333. faceIndex: null,
  14334. object: this
  14335. } );
  14336. }
  14337. }
  14338. };
  14339. }() ),
  14340. clone: function () {
  14341. return new this.constructor( this.geometry, this.material ).copy( this );
  14342. }
  14343. } );
  14344. /**
  14345. * @author mrdoob / http://mrdoob.com/
  14346. */
  14347. function LineSegments( geometry, material ) {
  14348. Line.call( this, geometry, material );
  14349. this.type = 'LineSegments';
  14350. }
  14351. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  14352. constructor: LineSegments,
  14353. isLineSegments: true
  14354. } );
  14355. /**
  14356. * @author bhouston / http://exocortex.com
  14357. */
  14358. const x = 2;
  14359. const y = 3;
  14360. const z = 4;
  14361. const w = 5;
  14362. const negInf2 = new Vector2( - Infinity, - Infinity );
  14363. const posInf2 = new Vector2( Infinity, Infinity );
  14364. const zero2 = new Vector2();
  14365. const one2 = new Vector2( 1, 1 );
  14366. const two2 = new Vector2( 2, 2 );
  14367. const negInf3 = new Vector3( - Infinity, - Infinity, - Infinity );
  14368. const posInf3 = new Vector3( Infinity, Infinity, Infinity );
  14369. const zero3 = new Vector3();
  14370. const one3 = new Vector3( 1, 1, 1 );
  14371. const two3 = new Vector3( 2, 2, 2 );
  14372. const eps = 0.0001;
  14373. /**
  14374. * @author simonThiele / https://github.com/simonThiele
  14375. * @author TristanVALCKE / https://github.com/Itee
  14376. */
  14377. /* global QUnit */
  14378. var DegToRad = Math.PI / 180;
  14379. function bufferAttributeEquals( a, b, tolerance ) {
  14380. tolerance = tolerance || 0.0001;
  14381. if ( a.count !== b.count || a.itemSize !== b.itemSize ) {
  14382. return false;
  14383. }
  14384. for ( var i = 0, il = a.count * a.itemSize; i < il; i ++ ) {
  14385. var delta = a[ i ] - b[ i ];
  14386. if ( delta > tolerance ) {
  14387. return false;
  14388. }
  14389. }
  14390. return true;
  14391. }
  14392. function getBBForVertices( vertices ) {
  14393. var geometry = new BufferGeometry();
  14394. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( vertices ), 3 ) );
  14395. geometry.computeBoundingBox();
  14396. return geometry.boundingBox;
  14397. }
  14398. function getBSForVertices( vertices ) {
  14399. var geometry = new BufferGeometry();
  14400. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( vertices ), 3 ) );
  14401. geometry.computeBoundingSphere();
  14402. return geometry.boundingSphere;
  14403. }
  14404. function getNormalsForVertices( vertices, assert ) {
  14405. var geometry = new BufferGeometry();
  14406. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( vertices ), 3 ) );
  14407. geometry.computeVertexNormals();
  14408. assert.ok( geometry.attributes.normal !== undefined, "normal attribute was created" );
  14409. return geometry.attributes.normal.array;
  14410. }
  14411. function comparePositions( pos, v ) {
  14412. return (
  14413. pos[ 0 ] === v[ 0 ].x && pos[ 1 ] === v[ 0 ].y && pos[ 2 ] === v[ 0 ].z &&
  14414. pos[ 3 ] === v[ 1 ].x && pos[ 4 ] === v[ 1 ].y && pos[ 5 ] === v[ 1 ].z &&
  14415. pos[ 6 ] === v[ 2 ].x && pos[ 7 ] === v[ 2 ].y && pos[ 8 ] === v[ 2 ].z
  14416. );
  14417. }
  14418. function compareColors( col, c ) {
  14419. return (
  14420. col[ 0 ] === c[ 0 ].r && col[ 1 ] === c[ 0 ].g && col[ 2 ] === c[ 0 ].b &&
  14421. col[ 3 ] === c[ 1 ].r && col[ 4 ] === c[ 1 ].g && col[ 5 ] === c[ 1 ].b &&
  14422. col[ 6 ] === c[ 2 ].r && col[ 7 ] === c[ 2 ].g && col[ 8 ] === c[ 2 ].b
  14423. );
  14424. }
  14425. function compareUvs( uvs, u ) {
  14426. return (
  14427. uvs[ 0 ] === u[ 0 ].x && uvs[ 1 ] === u[ 0 ].y &&
  14428. uvs[ 2 ] === u[ 1 ].x && uvs[ 3 ] === u[ 1 ].y &&
  14429. uvs[ 4 ] === u[ 2 ].x && uvs[ 5 ] === u[ 2 ].y
  14430. );
  14431. }
  14432. QUnit.module( 'Core', () => {
  14433. QUnit.module.todo( 'BufferGeometry', () => {
  14434. // INHERITANCE
  14435. QUnit.test( "Extending", ( assert ) => {
  14436. assert.ok( false, "everything's gonna be alright" );
  14437. } );
  14438. // INSTANCING
  14439. QUnit.test( "Instancing", ( assert ) => {
  14440. assert.ok( false, "everything's gonna be alright" );
  14441. } );
  14442. // PUBLIC STUFF
  14443. QUnit.test( "isBufferGeometry", ( assert ) => {
  14444. assert.ok( false, "everything's gonna be alright" );
  14445. } );
  14446. QUnit.test( "setIndex/getIndex", ( assert ) => {
  14447. var a = new BufferGeometry();
  14448. var uint16 = [ 1, 2, 3 ];
  14449. var uint32 = [ 65535, 65536, 65537 ];
  14450. var str = "foo";
  14451. a.setIndex( uint16 );
  14452. assert.ok( a.getIndex() instanceof Uint16BufferAttribute, "Index has the right type" );
  14453. assert.deepEqual( a.getIndex().array, new Uint16Array( uint16 ), "Small index gets stored correctly" );
  14454. a.setIndex( uint32 );
  14455. assert.ok( a.getIndex() instanceof Uint32BufferAttribute, "Index has the right type" );
  14456. assert.deepEqual( a.getIndex().array, new Uint32Array( uint32 ), "Large index gets stored correctly" );
  14457. a.setIndex( str );
  14458. assert.strictEqual( a.getIndex(), str, "Weird index gets stored correctly" );
  14459. } );
  14460. QUnit.test( "getAttribute", ( assert ) => {
  14461. assert.ok( false, "everything's gonna be alright" );
  14462. } );
  14463. QUnit.test( "add / delete Attribute", ( assert ) => {
  14464. var geometry = new BufferGeometry();
  14465. var attributeName = "position";
  14466. assert.ok( geometry.attributes[ attributeName ] === undefined, 'no attribute defined' );
  14467. geometry.addAttribute( attributeName, new BufferAttribute( new Float32Array( [ 1, 2, 3 ], 1 ) ) );
  14468. assert.ok( geometry.attributes[ attributeName ] !== undefined, 'attribute is defined' );
  14469. geometry.removeAttribute( attributeName );
  14470. assert.ok( geometry.attributes[ attributeName ] === undefined, 'no attribute defined' );
  14471. } );
  14472. QUnit.test( "addGroup", ( assert ) => {
  14473. var a = new BufferGeometry();
  14474. var expected = [
  14475. {
  14476. start: 0,
  14477. count: 1,
  14478. materialIndex: 0
  14479. },
  14480. {
  14481. start: 1,
  14482. count: 2,
  14483. materialIndex: 2
  14484. }
  14485. ];
  14486. a.addGroup( 0, 1, 0 );
  14487. a.addGroup( 1, 2, 2 );
  14488. assert.deepEqual( a.groups, expected, "Check groups were stored correctly and in order" );
  14489. a.clearGroups();
  14490. assert.strictEqual( a.groups.length, 0, "Check groups were deleted correctly" );
  14491. } );
  14492. QUnit.test( "clearGroups", ( assert ) => {
  14493. assert.ok( false, "everything's gonna be alright" );
  14494. } );
  14495. QUnit.test( "setDrawRange", ( assert ) => {
  14496. var a = new BufferGeometry();
  14497. a.setDrawRange( 1.0, 7 );
  14498. assert.deepEqual( a.drawRange, {
  14499. start: 1,
  14500. count: 7
  14501. }, "Check draw range was stored correctly" );
  14502. } );
  14503. QUnit.test( "applyMatrix", ( assert ) => {
  14504. var geometry = new BufferGeometry();
  14505. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( 6 ), 3 ) );
  14506. var matrix = new Matrix4().set(
  14507. 1, 0, 0, 1.5,
  14508. 0, 1, 0, - 2,
  14509. 0, 0, 1, 3,
  14510. 0, 0, 0, 1
  14511. );
  14512. geometry.applyMatrix( matrix );
  14513. var position = geometry.attributes.position.array;
  14514. var m = matrix.elements;
  14515. assert.ok( position[ 0 ] === m[ 12 ] && position[ 1 ] === m[ 13 ] && position[ 2 ] === m[ 14 ], "position was extracted from matrix" );
  14516. assert.ok( position[ 3 ] === m[ 12 ] && position[ 4 ] === m[ 13 ] && position[ 5 ] === m[ 14 ], "position was extracted from matrix twice" );
  14517. assert.ok( geometry.attributes.position.version === 1, "version was increased during update" );
  14518. } );
  14519. QUnit.test( "rotateX/Y/Z", ( assert ) => {
  14520. var geometry = new BufferGeometry();
  14521. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  14522. var pos = geometry.attributes.position.array;
  14523. geometry.rotateX( 180 * DegToRad );
  14524. // object was rotated around x so all items should be flipped but the x ones
  14525. assert.ok( pos[ 0 ] === 1 && pos[ 1 ] === - 2 && pos[ 2 ] === - 3 &&
  14526. pos[ 3 ] === 4 && pos[ 4 ] === - 5 && pos[ 5 ] === - 6, "vertices were rotated around x by 180 degrees" );
  14527. geometry.rotateY( 180 * DegToRad );
  14528. // vertices were rotated around y so all items should be flipped again but the y ones
  14529. assert.ok( pos[ 0 ] === - 1 && pos[ 1 ] === - 2 && pos[ 2 ] === 3 &&
  14530. pos[ 3 ] === - 4 && pos[ 4 ] === - 5 && pos[ 5 ] === 6, "vertices were rotated around y by 180 degrees" );
  14531. geometry.rotateZ( 180 * DegToRad );
  14532. // vertices were rotated around z so all items should be flipped again but the z ones
  14533. assert.ok( pos[ 0 ] === 1 && pos[ 1 ] === 2 && pos[ 2 ] === 3 &&
  14534. pos[ 3 ] === 4 && pos[ 4 ] === 5 && pos[ 5 ] === 6, "vertices were rotated around z by 180 degrees" );
  14535. } );
  14536. QUnit.test( "translate", ( assert ) => {
  14537. var geometry = new BufferGeometry();
  14538. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  14539. var pos = geometry.attributes.position.array;
  14540. geometry.translate( 10, 20, 30 );
  14541. assert.ok( pos[ 0 ] === 11 && pos[ 1 ] === 22 && pos[ 2 ] === 33 &&
  14542. pos[ 3 ] === 14 && pos[ 4 ] === 25 && pos[ 5 ] === 36, "vertices were translated" );
  14543. } );
  14544. QUnit.test( "scale", ( assert ) => {
  14545. var geometry = new BufferGeometry();
  14546. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( [ - 1, - 1, - 1, 2, 2, 2 ] ), 3 ) );
  14547. var pos = geometry.attributes.position.array;
  14548. geometry.scale( 1, 2, 3 );
  14549. assert.ok( pos[ 0 ] === - 1 && pos[ 1 ] === - 2 && pos[ 2 ] === - 3 &&
  14550. pos[ 3 ] === 2 && pos[ 4 ] === 4 && pos[ 5 ] === 6, "vertices were scaled" );
  14551. } );
  14552. QUnit.test( "lookAt", ( assert ) => {
  14553. var a = new BufferGeometry();
  14554. var vertices = new Float32Array( [
  14555. - 1.0, - 1.0, 1.0,
  14556. 1.0, - 1.0, 1.0,
  14557. 1.0, 1.0, 1.0,
  14558. 1.0, 1.0, 1.0,
  14559. - 1.0, 1.0, 1.0,
  14560. - 1.0, - 1.0, 1.0
  14561. ] );
  14562. a.addAttribute( 'position', new BufferAttribute( vertices, 3 ) );
  14563. var sqrt = Math.sqrt( 2 );
  14564. var expected = new Float32Array( [
  14565. 1, 0, - sqrt,
  14566. - 1, 0, - sqrt,
  14567. - 1, sqrt, 0,
  14568. - 1, sqrt, 0,
  14569. 1, sqrt, 0,
  14570. 1, 0, - sqrt
  14571. ] );
  14572. a.lookAt( new Vector3( 0, 1, - 1 ) );
  14573. assert.ok( bufferAttributeEquals( a.attributes.position.array, expected ), "Rotation is correct" );
  14574. } );
  14575. QUnit.test( "center", ( assert ) => {
  14576. var geometry = new BufferGeometry();
  14577. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( [
  14578. - 1, - 1, - 1,
  14579. 1, 1, 1,
  14580. 4, 4, 4
  14581. ] ), 3 ) );
  14582. geometry.center();
  14583. var pos = geometry.attributes.position.array;
  14584. // the boundingBox should go from (-1, -1, -1) to (4, 4, 4) so it has a size of (5, 5, 5)
  14585. // after centering it the vertices should be placed between (-2.5, -2.5, -2.5) and (2.5, 2.5, 2.5)
  14586. assert.ok( pos[ 0 ] === - 2.5 && pos[ 1 ] === - 2.5 && pos[ 2 ] === - 2.5 &&
  14587. pos[ 3 ] === - 0.5 && pos[ 4 ] === - 0.5 && pos[ 5 ] === - 0.5 &&
  14588. pos[ 6 ] === 2.5 && pos[ 7 ] === 2.5 && pos[ 8 ] === 2.5, "vertices were replaced by boundingBox dimensions" );
  14589. } );
  14590. QUnit.test( "setFromObject", ( assert ) => {
  14591. var lineGeo = new Geometry();
  14592. lineGeo.vertices.push(
  14593. new Vector3( - 10, 0, 0 ),
  14594. new Vector3( 0, 10, 0 ),
  14595. new Vector3( 10, 0, 0 )
  14596. );
  14597. lineGeo.colors.push(
  14598. new Color( 1, 0, 0 ),
  14599. new Color( 0, 1, 0 ),
  14600. new Color( 0, 0, 1 )
  14601. );
  14602. var line = new LineSegments( lineGeo, null );
  14603. var geometry = new BufferGeometry().setFromObject( line );
  14604. var pos = geometry.attributes.position.array;
  14605. var col = geometry.attributes.color.array;
  14606. var v = lineGeo.vertices;
  14607. var c = lineGeo.colors;
  14608. assert.ok(
  14609. // position exists
  14610. pos !== undefined &&
  14611. // vertex arrays have the same size
  14612. v.length * 3 === pos.length &&
  14613. // there are three complete vertices (each vertex contains three values)
  14614. geometry.attributes.position.count === 3 &&
  14615. // check if both arrays contains the same data
  14616. pos[ 0 ] === v[ 0 ].x && pos[ 1 ] === v[ 0 ].y && pos[ 2 ] === v[ 0 ].z &&
  14617. pos[ 3 ] === v[ 1 ].x && pos[ 4 ] === v[ 1 ].y && pos[ 5 ] === v[ 1 ].z &&
  14618. pos[ 6 ] === v[ 2 ].x && pos[ 7 ] === v[ 2 ].y && pos[ 8 ] === v[ 2 ].z
  14619. , "positions are equal" );
  14620. assert.ok(
  14621. // color exists
  14622. col !== undefined &&
  14623. // color arrays have the same size
  14624. c.length * 3 === col.length &&
  14625. // there are three complete colors (each color contains three values)
  14626. geometry.attributes.color.count === 3 &&
  14627. // check if both arrays contains the same data
  14628. col[ 0 ] === c[ 0 ].r && col[ 1 ] === c[ 0 ].g && col[ 2 ] === c[ 0 ].b &&
  14629. col[ 3 ] === c[ 1 ].r && col[ 4 ] === c[ 1 ].g && col[ 5 ] === c[ 1 ].b &&
  14630. col[ 6 ] === c[ 2 ].r && col[ 7 ] === c[ 2 ].g && col[ 8 ] === c[ 2 ].b
  14631. , "colors are equal" );
  14632. } );
  14633. QUnit.test( "setFromObject (more)", ( assert ) => {
  14634. var lineGeo = new Geometry();
  14635. lineGeo.vertices.push(
  14636. new Vector3( - 10, 0, 0 ),
  14637. new Vector3( 0, 10, 0 ),
  14638. new Vector3( 10, 0, 0 )
  14639. );
  14640. lineGeo.colors.push(
  14641. new Color( 1, 0, 0 ),
  14642. new Color( 0, 1, 0 ),
  14643. new Color( 0, 0, 1 )
  14644. );
  14645. lineGeo.computeBoundingBox();
  14646. lineGeo.computeBoundingSphere();
  14647. var line = new LineSegments( lineGeo );
  14648. var geometry = new BufferGeometry().setFromObject( line );
  14649. assert.ok( geometry.boundingBox.equals( lineGeo.boundingBox ), "BoundingBox was set correctly" );
  14650. assert.ok( geometry.boundingSphere.equals( lineGeo.boundingSphere ), "BoundingSphere was set correctly" );
  14651. var pos = geometry.attributes.position.array;
  14652. var col = geometry.attributes.color.array;
  14653. var v = lineGeo.vertices;
  14654. var c = lineGeo.colors;
  14655. // adapted from setFromObject QUnit.test (way up)
  14656. assert.notStrictEqual( pos, undefined, "Position attribute exists" );
  14657. assert.strictEqual( v.length * 3, pos.length, "Vertex arrays have the same size" );
  14658. assert.strictEqual( geometry.attributes.position.count, 3, "Correct number of vertices" );
  14659. assert.ok( comparePositions( pos, v ), "Positions are identical" );
  14660. assert.notStrictEqual( col, undefined, "Color attribute exists" );
  14661. assert.strictEqual( c.length * 3, col.length, "Color arrays have the same size" );
  14662. assert.strictEqual( geometry.attributes.color.count, 3, "Correct number of colors" );
  14663. assert.ok( compareColors( col, c ), "Colors are identical" );
  14664. // setFromObject with a Mesh as object
  14665. lineGeo.faces.push( new Face3( 0, 1, 2 ) );
  14666. var lineMesh = new Mesh( lineGeo );
  14667. var geometry = new BufferGeometry().setFromObject( lineMesh );
  14668. // no colors
  14669. var pos = geometry.attributes.position.array;
  14670. var v = lineGeo.vertices;
  14671. assert.notStrictEqual( pos, undefined, "Mesh: position attribute exists" );
  14672. assert.strictEqual( v.length * 3, pos.length, "Mesh: vertex arrays have the same size" );
  14673. assert.strictEqual( geometry.attributes.position.count, 3, "Mesh: correct number of vertices" );
  14674. assert.ok( comparePositions( pos, v ), "Mesh: positions are identical" );
  14675. } );
  14676. QUnit.test( "updateFromObject", ( assert ) => {
  14677. var geo = new Geometry();
  14678. geo.vertices.push(
  14679. new Vector3( - 10, 0, 0 ),
  14680. new Vector3( 0, 10, 0 ),
  14681. new Vector3( 10, 0, 0 )
  14682. );
  14683. geo.faces.push( new Face3( 0, 1, 2 ) );
  14684. geo.faces[ 0 ].vertexColors.push(
  14685. new Color( 1, 0, 0 ),
  14686. new Color( 0, 1, 0 ),
  14687. new Color( 0, 0, 1 )
  14688. );
  14689. geo.faceVertexUvs[ 0 ] = [
  14690. [
  14691. new Vector2( 0, 0 ),
  14692. new Vector2( 1, 0 ),
  14693. new Vector2( 1, 1 )
  14694. ]
  14695. ];
  14696. geo.computeFaceNormals();
  14697. geo.computeVertexNormals();
  14698. geo.verticesNeedUpdate = true;
  14699. geo.normalsNeedUpdate = true;
  14700. geo.colorsNeedUpdate = true;
  14701. geo.uvsNeedUpdate = true;
  14702. geo.groupsNeedUpdate = true;
  14703. var mesh = new Mesh( geo );
  14704. var geometry = new BufferGeometry();
  14705. geometry.updateFromObject( mesh ); // first call to create the underlying structure (DirectGeometry)
  14706. geometry.updateFromObject( mesh ); // second time to actually go thru the motions and update
  14707. var pos = geometry.attributes.position.array;
  14708. var col = geometry.attributes.color.array;
  14709. var norm = geometry.attributes.normal.array;
  14710. var uvs = geometry.attributes.uv.array;
  14711. var v = geo.vertices;
  14712. var c = geo.faces[ 0 ].vertexColors;
  14713. var n = geo.faces[ 0 ].vertexNormals;
  14714. var u = geo.faceVertexUvs[ 0 ][ 0 ];
  14715. assert.notStrictEqual( pos, undefined, "Position attribute exists" );
  14716. assert.strictEqual( v.length * 3, pos.length, "Both arrays have the same size" );
  14717. assert.strictEqual( geometry.attributes.position.count, v.length, "Correct number of vertices" );
  14718. assert.ok( comparePositions( pos, v ), "Positions are identical" );
  14719. assert.notStrictEqual( col, undefined, "Color attribute exists" );
  14720. assert.strictEqual( c.length * 3, col.length, "Both arrays have the same size" );
  14721. assert.strictEqual( geometry.attributes.color.count, c.length, "Correct number of colors" );
  14722. assert.ok( compareColors( col, c ), "Colors are identical" );
  14723. assert.notStrictEqual( norm, undefined, "Normal attribute exists" );
  14724. assert.strictEqual( n.length * 3, norm.length, "Both arrays have the same size" );
  14725. assert.strictEqual( geometry.attributes.normal.count, n.length, "Correct number of normals" );
  14726. assert.ok( comparePositions( norm, n ), "Normals are identical" );
  14727. assert.notStrictEqual( uvs, undefined, "UV attribute exists" );
  14728. assert.strictEqual( u.length * 2, uvs.length, "Both arrays have the same size" );
  14729. assert.strictEqual( geometry.attributes.uv.count, u.length, "Correct number of UV coordinates" );
  14730. assert.ok( compareUvs( uvs, u ), "UVs are identical" );
  14731. } );
  14732. QUnit.test( "fromGeometry/fromDirectGeometry", ( assert ) => {
  14733. var a = new BufferGeometry();
  14734. // BoxGeometry is a bit too simple but works fine in a pinch
  14735. // var b = new BoxGeometry( 1, 1, 1 );
  14736. // b.mergeVertices();
  14737. // b.computeVertexNormals();
  14738. // b.computeBoundingBox();
  14739. // b.computeBoundingSphere();
  14740. var asyncDone = assert.async(); // tell QUnit we're done with asserts
  14741. var loader = new JSONLoader();
  14742. loader.load( "../../examples/models/skinned/simple/simple.js", function ( modelGeometry ) {
  14743. a.fromGeometry( modelGeometry );
  14744. var attr;
  14745. var geometry = new DirectGeometry().fromGeometry( modelGeometry );
  14746. var positions = new Float32Array( geometry.vertices.length * 3 );
  14747. attr = new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices );
  14748. assert.ok( bufferAttributeEquals( a.attributes.position, attr ), "Vertices are identical" );
  14749. if ( geometry.normals.length > 0 ) {
  14750. var normals = new Float32Array( geometry.normals.length * 3 );
  14751. attr = new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals );
  14752. assert.ok( bufferAttributeEquals( a.attributes.normal, attr ), "Normals are identical" );
  14753. }
  14754. if ( geometry.colors.length > 0 ) {
  14755. var colors = new Float32Array( geometry.colors.length * 3 );
  14756. attr = new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors );
  14757. assert.ok( bufferAttributeEquals( a.attributes.color, attr ), "Colors are identical" );
  14758. }
  14759. if ( geometry.uvs.length > 0 ) {
  14760. var uvs = new Float32Array( geometry.uvs.length * 2 );
  14761. attr = new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs );
  14762. assert.ok( bufferAttributeEquals( a.attributes.uv, attr ), "UVs are identical" );
  14763. }
  14764. if ( geometry.uvs2.length > 0 ) {
  14765. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  14766. attr = new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 );
  14767. assert.ok( bufferAttributeEquals( a.attributes.uv2, attr ), "UV2s are identical" );
  14768. }
  14769. if ( geometry.indices.length > 0 ) {
  14770. var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
  14771. var indices = new TypeArray( geometry.indices.length * 3 );
  14772. attr = new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices );
  14773. assert.ok( bufferAttributeEquals( a.indices, attr ), "Indices are identical" );
  14774. }
  14775. // groups
  14776. assert.deepEqual( a.groups, geometry.groups, "Groups are identical" );
  14777. // morphs
  14778. if ( geometry.morphTargets !== undefined ) {
  14779. for ( var name in geometry.morphTargets ) {
  14780. var morphTargets = geometry.morphTargets[ name ];
  14781. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  14782. var morphTarget = morphTargets[ i ];
  14783. attr = new Float32BufferAttribute( morphTarget.length * 3, 3 );
  14784. attr.copyVector3sArray( morphTarget );
  14785. assert.ok(
  14786. bufferAttributeEquals( a.morphAttributes[ name ][ i ], attr ),
  14787. "MorphTargets #" + i + " are identical"
  14788. );
  14789. }
  14790. }
  14791. }
  14792. // skinning
  14793. if ( geometry.skinIndices.length > 0 ) {
  14794. attr = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  14795. attr.copyVector4sArray( geometry.skinIndices );
  14796. assert.ok( bufferAttributeEquals( a.attributes.skinIndex, attr ), "SkinIndices are identical" );
  14797. }
  14798. if ( geometry.skinWeights.length > 0 ) {
  14799. attr = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  14800. attr.copyVector4sArray( geometry.skinWeights );
  14801. assert.ok( bufferAttributeEquals( a.attributes.skinWeight, attr ), "SkinWeights are identical" );
  14802. }
  14803. // TODO
  14804. // DirectGeometry doesn't actually copy boundingSphere and boundingBox yet,
  14805. // so they're always null
  14806. if ( geometry.boundingSphere !== null ) {
  14807. assert.ok( a.boundingSphere.equals( geometry.boundingSphere ), "BoundingSphere is identical" );
  14808. }
  14809. if ( geometry.boundingBox !== null ) {
  14810. assert.ok( a.boundingBox.equals( geometry.boundingBox ), "BoundingBox is identical" );
  14811. }
  14812. asyncDone();
  14813. } );
  14814. } );
  14815. QUnit.test( "computeBoundingBox", ( assert ) => {
  14816. var bb = getBBForVertices( [ - 1, - 2, - 3, 13, - 2, - 3.5, - 1, - 20, 0, - 4, 5, 6 ] );
  14817. assert.ok( bb.min.x === - 4 && bb.min.y === - 20 && bb.min.z === - 3.5, "min values are set correctly" );
  14818. assert.ok( bb.max.x === 13 && bb.max.y === 5 && bb.max.z === 6, "max values are set correctly" );
  14819. var bb = getBBForVertices( [ - 1, - 1, - 1 ] );
  14820. 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" );
  14821. 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" );
  14822. } );
  14823. QUnit.test( "computeBoundingSphere", ( assert ) => {
  14824. var bs = getBSForVertices( [ - 10, 0, 0, 10, 0, 0 ] );
  14825. assert.ok( bs.radius === ( 10 + 10 ) / 2, "radius is equal to deltaMinMax / 2" );
  14826. assert.ok( bs.center.x === 0 && bs.center.y === 0 && bs.center.y === 0, "bounding sphere is at ( 0, 0, 0 )" );
  14827. var bs = getBSForVertices( [ - 5, 11, - 3, 5, - 11, 3 ] );
  14828. var radius = new Vector3( 5, 11, 3 ).length();
  14829. assert.ok( bs.radius === radius, "radius is equal to directionLength" );
  14830. assert.ok( bs.center.x === 0 && bs.center.y === 0 && bs.center.y === 0, "bounding sphere is at ( 0, 0, 0 )" );
  14831. } );
  14832. QUnit.test( "computeFaceNormals", ( assert ) => {
  14833. assert.ok( false, "everything's gonna be alright" );
  14834. } );
  14835. QUnit.test( "computeVertexNormals", ( assert ) => {
  14836. // get normals for a counter clockwise created triangle
  14837. var normals = getNormalsForVertices( [ - 1, 0, 0, 1, 0, 0, 0, 1, 0 ], assert );
  14838. assert.ok( normals[ 0 ] === 0 && normals[ 1 ] === 0 && normals[ 2 ] === 1,
  14839. "first normal is pointing to screen since the the triangle was created counter clockwise" );
  14840. assert.ok( normals[ 3 ] === 0 && normals[ 4 ] === 0 && normals[ 5 ] === 1,
  14841. "second normal is pointing to screen since the the triangle was created counter clockwise" );
  14842. assert.ok( normals[ 6 ] === 0 && normals[ 7 ] === 0 && normals[ 8 ] === 1,
  14843. "third normal is pointing to screen since the the triangle was created counter clockwise" );
  14844. // get normals for a clockwise created triangle
  14845. var normals = getNormalsForVertices( [ 1, 0, 0, - 1, 0, 0, 0, 1, 0 ], assert );
  14846. assert.ok( normals[ 0 ] === 0 && normals[ 1 ] === 0 && normals[ 2 ] === - 1,
  14847. "first normal is pointing to screen since the the triangle was created clockwise" );
  14848. assert.ok( normals[ 3 ] === 0 && normals[ 4 ] === 0 && normals[ 5 ] === - 1,
  14849. "second normal is pointing to screen since the the triangle was created clockwise" );
  14850. assert.ok( normals[ 6 ] === 0 && normals[ 7 ] === 0 && normals[ 8 ] === - 1,
  14851. "third normal is pointing to screen since the the triangle was created clockwise" );
  14852. var normals = getNormalsForVertices( [ 0, 0, 1, 0, 0, - 1, 1, 1, 0 ], assert );
  14853. // the triangle is rotated by 45 degrees to the right so the normals of the three vertices
  14854. // should point to (1, -1, 0).normalized(). The simplest solution is to check against a normalized
  14855. // vector (1, -1, 0) but you will get calculation errors because of floating calculations so another
  14856. // valid technique is to create a vector which stands in 90 degrees to the normals and calculate the
  14857. // dot product which is the cos of the angle between them. This should be < floating calculation error
  14858. // which can be taken from Number.EPSILON
  14859. var direction = new Vector3( 1, 1, 0 ).normalize(); // a vector which should have 90 degrees difference to normals
  14860. var difference = direction.dot( new Vector3( normals[ 0 ], normals[ 1 ], normals[ 2 ] ) );
  14861. assert.ok( difference < Number.EPSILON, "normal is equal to reference vector" );
  14862. // get normals for a line should be NAN because you need min a triangle to calculate normals
  14863. var normals = getNormalsForVertices( [ 1, 0, 0, - 1, 0, 0 ], assert );
  14864. for ( var i = 0; i < normals.length; i ++ ) {
  14865. assert.ok( ! normals[ i ], "normals can't be calculated which is good" );
  14866. }
  14867. } );
  14868. QUnit.test( "computeVertexNormals (indexed)", ( assert ) => {
  14869. var sqrt = 0.5 * Math.sqrt( 2 );
  14870. var normal = new BufferAttribute( new Float32Array( [
  14871. - 1, 0, 0, - 1, 0, 0, - 1, 0, 0,
  14872. sqrt, sqrt, 0, sqrt, sqrt, 0, sqrt, sqrt, 0,
  14873. - 1, 0, 0
  14874. ] ), 3 );
  14875. var position = new BufferAttribute( new Float32Array( [
  14876. 0.5, 0.5, 0.5, 0.5, 0.5, - 0.5, 0.5, - 0.5, 0.5,
  14877. 0.5, - 0.5, - 0.5, - 0.5, 0.5, - 0.5, - 0.5, 0.5, 0.5,
  14878. - 0.5, - 0.5, - 0.5
  14879. ] ), 3 );
  14880. var index = new BufferAttribute( new Uint16Array( [
  14881. 0, 2, 1, 2, 3, 1, 4, 6, 5, 6, 7, 5
  14882. ] ), 1 );
  14883. var a = new BufferGeometry();
  14884. a.addAttribute( "position", position );
  14885. a.computeVertexNormals();
  14886. assert.ok(
  14887. bufferAttributeEquals( normal, a.getAttribute( "normal" ) ),
  14888. "Regular geometry: first computed normals are correct"
  14889. );
  14890. // a second time to see if the existing normals get properly deleted
  14891. a.computeVertexNormals();
  14892. assert.ok(
  14893. bufferAttributeEquals( normal, a.getAttribute( "normal" ) ),
  14894. "Regular geometry: second computed normals are correct"
  14895. );
  14896. // indexed geometry
  14897. var a = new BufferGeometry();
  14898. a.addAttribute( "position", position );
  14899. a.setIndex( index );
  14900. a.computeVertexNormals();
  14901. assert.ok( bufferAttributeEquals( normal, a.getAttribute( "normal" ) ), "Indexed geometry: computed normals are correct" );
  14902. } );
  14903. QUnit.test( "merge", ( assert ) => {
  14904. var geometry1 = new BufferGeometry();
  14905. geometry1.addAttribute( "attrName", new BufferAttribute( new Float32Array( [ 1, 2, 3, 0, 0, 0 ] ), 3 ) );
  14906. var geometry2 = new BufferGeometry();
  14907. geometry2.addAttribute( "attrName", new BufferAttribute( new Float32Array( [ 4, 5, 6 ] ), 3 ) );
  14908. var attr = geometry1.attributes.attrName.array;
  14909. geometry1.merge( geometry2, 1 );
  14910. // merged array should be 1, 2, 3, 4, 5, 6
  14911. for ( var i = 0; i < attr.length; i ++ ) {
  14912. assert.ok( attr[ i ] === i + 1, "" );
  14913. }
  14914. geometry1.merge( geometry2 );
  14915. assert.ok( attr[ 0 ] === 4 && attr[ 1 ] === 5 && attr[ 2 ] === 6, "copied the 3 attributes without offset" );
  14916. } );
  14917. QUnit.test( "normalizeNormals", ( assert ) => {
  14918. assert.ok( false, "everything's gonna be alright" );
  14919. } );
  14920. QUnit.test( "toNonIndexed", ( assert ) => {
  14921. var geometry = new BufferGeometry();
  14922. var vertices = new Float32Array( [
  14923. 0.5, 0.5, 0.5, 0.5, 0.5, - 0.5, 0.5, - 0.5, 0.5, 0.5, - 0.5, - 0.5
  14924. ] );
  14925. var index = new BufferAttribute( new Uint16Array( [ 0, 2, 1, 2, 3, 1 ] ) );
  14926. var expected = new Float32Array( [
  14927. 0.5, 0.5, 0.5, 0.5, - 0.5, 0.5, 0.5, 0.5, - 0.5,
  14928. 0.5, - 0.5, 0.5, 0.5, - 0.5, - 0.5, 0.5, 0.5, - 0.5
  14929. ] );
  14930. geometry.addAttribute( 'position', new BufferAttribute( vertices, 3 ) );
  14931. geometry.setIndex( index );
  14932. var nonIndexed = geometry.toNonIndexed();
  14933. assert.deepEqual( nonIndexed.getAttribute( "position" ).array, expected, "Expected vertices" );
  14934. } );
  14935. QUnit.test( "toJSON", ( assert ) => {
  14936. var index = new BufferAttribute( new Uint16Array( [ 0, 1, 2, 3 ] ), 1 );
  14937. var attribute1 = new BufferAttribute( new Uint16Array( [ 1, 3, 5, 7 ] ), 1 );
  14938. var a = new BufferGeometry();
  14939. a.name = "JSONQUnit.test";
  14940. // a.parameters = { "placeholder": 0 };
  14941. a.addAttribute( "attribute1", attribute1 );
  14942. a.setIndex( index );
  14943. a.addGroup( 0, 1, 2 );
  14944. a.boundingSphere = new Sphere( new Vector3( x, y, z ), 0.5 );
  14945. var j = a.toJSON();
  14946. var gold = {
  14947. "metadata": {
  14948. "version": 4.5,
  14949. "type": "BufferGeometry",
  14950. "generator": "BufferGeometry.toJSON"
  14951. },
  14952. "uuid": a.uuid,
  14953. "type": "BufferGeometry",
  14954. "name": "JSONQUnit.test",
  14955. "data": {
  14956. "attributes": {
  14957. "attribute1": {
  14958. "itemSize": 1,
  14959. "type": "Uint16Array",
  14960. "array": [ 1, 3, 5, 7 ],
  14961. "normalized": false
  14962. }
  14963. },
  14964. "index": {
  14965. "type": "Uint16Array",
  14966. "array": [ 0, 1, 2, 3 ]
  14967. },
  14968. "groups": [
  14969. {
  14970. "start": 0,
  14971. "count": 1,
  14972. "materialIndex": 2
  14973. }
  14974. ],
  14975. "boundingSphere": {
  14976. "center": [ 2, 3, 4 ],
  14977. "radius": 0.5
  14978. }
  14979. }
  14980. };
  14981. assert.deepEqual( j, gold, "Generated JSON is as expected" );
  14982. } );
  14983. QUnit.test( "clone", ( assert ) => {
  14984. var a = new BufferGeometry();
  14985. a.addAttribute( "attribute1", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  14986. a.addAttribute( "attribute2", new BufferAttribute( new Float32Array( [ 0, 1, 3, 5, 6 ] ), 1 ) );
  14987. a.addGroup( 0, 1, 2 );
  14988. a.computeBoundingBox();
  14989. a.computeBoundingSphere();
  14990. a.setDrawRange( 0, 1 );
  14991. var b = a.clone();
  14992. assert.notEqual( a, b, "A new object was created" );
  14993. assert.notEqual( a.id, b.id, "New object has a different GUID" );
  14994. assert.strictEqual(
  14995. Object.keys( a.attributes ).count, Object.keys( b.attributes ).count,
  14996. "Both objects have the same amount of attributes"
  14997. );
  14998. assert.ok(
  14999. bufferAttributeEquals( a.getAttribute( "attribute1" ), b.getAttribute( "attribute1" ) ),
  15000. "First attributes buffer is identical"
  15001. );
  15002. assert.ok(
  15003. bufferAttributeEquals( a.getAttribute( "attribute2" ), b.getAttribute( "attribute2" ) ),
  15004. "Second attributes buffer is identical"
  15005. );
  15006. assert.deepEqual( a.groups, b.groups, "Groups are identical" );
  15007. assert.ok( a.boundingBox.equals( b.boundingBox ), "BoundingBoxes are equal" );
  15008. assert.ok( a.boundingSphere.equals( b.boundingSphere ), "BoundingSpheres are equal" );
  15009. assert.strictEqual( a.drawRange.start, b.drawRange.start, "DrawRange start is identical" );
  15010. assert.strictEqual( a.drawRange.count, b.drawRange.count, "DrawRange count is identical" );
  15011. } );
  15012. QUnit.test( "copy", ( assert ) => {
  15013. var geometry = new BufferGeometry();
  15014. geometry.addAttribute( "attrName", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  15015. geometry.addAttribute( "attrName2", new BufferAttribute( new Float32Array( [ 0, 1, 3, 5, 6 ] ), 1 ) );
  15016. var copy = new BufferGeometry().copy( geometry );
  15017. assert.ok( copy !== geometry && geometry.id !== copy.id, "new object was created" );
  15018. Object.keys( geometry.attributes ).forEach( function ( key ) {
  15019. var attribute = geometry.attributes[ key ];
  15020. assert.ok( attribute !== undefined, "all attributes where copied" );
  15021. for ( var i = 0; i < attribute.array.length; i ++ ) {
  15022. assert.ok( attribute.array[ i ] === copy.attributes[ key ].array[ i ], "values of the attribute are equal" );
  15023. }
  15024. } );
  15025. } );
  15026. QUnit.test( "dispose", ( assert ) => {
  15027. assert.ok( false, "everything's gonna be alright" );
  15028. } );
  15029. } );
  15030. } );
  15031. /**
  15032. * @author alteredq / http://alteredqualia.com/
  15033. */
  15034. function Clock( autoStart ) {
  15035. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  15036. this.startTime = 0;
  15037. this.oldTime = 0;
  15038. this.elapsedTime = 0;
  15039. this.running = false;
  15040. }
  15041. Object.assign( Clock.prototype, {
  15042. start: function () {
  15043. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  15044. this.oldTime = this.startTime;
  15045. this.elapsedTime = 0;
  15046. this.running = true;
  15047. },
  15048. stop: function () {
  15049. this.getElapsedTime();
  15050. this.running = false;
  15051. this.autoStart = false;
  15052. },
  15053. getElapsedTime: function () {
  15054. this.getDelta();
  15055. return this.elapsedTime;
  15056. },
  15057. getDelta: function () {
  15058. var diff = 0;
  15059. if ( this.autoStart && ! this.running ) {
  15060. this.start();
  15061. return 0;
  15062. }
  15063. if ( this.running ) {
  15064. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  15065. diff = ( newTime - this.oldTime ) / 1000;
  15066. this.oldTime = newTime;
  15067. this.elapsedTime += diff;
  15068. }
  15069. return diff;
  15070. }
  15071. } );
  15072. /**
  15073. * @author simonThiele / https://github.com/simonThiele
  15074. * @author TristanVALCKE / https://github.com/Itee
  15075. */
  15076. /* global QUnit */
  15077. QUnit.module( 'Core', () => {
  15078. QUnit.module.todo( 'Clock', () => {
  15079. function mockPerformance() {
  15080. self.performance = {
  15081. deltaTime: 0,
  15082. next: function ( delta ) {
  15083. this.deltaTime += delta;
  15084. },
  15085. now: function () {
  15086. return this.deltaTime;
  15087. }
  15088. };
  15089. }
  15090. // INSTANCING
  15091. QUnit.test( "Instancing", ( assert ) => {
  15092. assert.ok( false, "everything's gonna be alright" );
  15093. } );
  15094. // PUBLIC STUFF
  15095. QUnit.test( "start", ( assert ) => {
  15096. assert.ok( false, "everything's gonna be alright" );
  15097. } );
  15098. QUnit.test( "stop", ( assert ) => {
  15099. assert.ok( false, "everything's gonna be alright" );
  15100. } );
  15101. QUnit.test( "getElapsedTime", ( assert ) => {
  15102. assert.ok( false, "everything's gonna be alright" );
  15103. } );
  15104. QUnit.test( "getDelta", ( assert ) => {
  15105. assert.ok( false, "everything's gonna be alright" );
  15106. } );
  15107. // OTHERS
  15108. QUnit.test( "clock with performance", ( assert ) => {
  15109. mockPerformance();
  15110. var clock = new Clock( false );
  15111. clock.start();
  15112. self.performance.next( 123 );
  15113. assert.numEqual( clock.getElapsedTime(), 0.123, "okay" );
  15114. self.performance.next( 100 );
  15115. assert.numEqual( clock.getElapsedTime(), 0.223, "okay" );
  15116. clock.stop();
  15117. self.performance.next( 1000 );
  15118. assert.numEqual( clock.getElapsedTime(), 0.223, "don't update time if the clock was stopped" );
  15119. } );
  15120. } );
  15121. } );
  15122. /**
  15123. * @author moraxy / https://github.com/moraxy
  15124. * @author TristanVALCKE / https://github.com/Itee
  15125. */
  15126. /* global QUnit */
  15127. QUnit.module( 'Core', () => {
  15128. QUnit.module.todo( 'DirectGeometry', () => {
  15129. // INSTANCING
  15130. QUnit.test( "Instancing", ( assert ) => {
  15131. assert.ok( false, "everything's gonna be alright" );
  15132. } );
  15133. // PUBLIC STUFF
  15134. QUnit.test( "computeGroups", ( assert ) => {
  15135. var a = new DirectGeometry();
  15136. var b = new Geometry();
  15137. var expected = [
  15138. { start: 0, materialIndex: 0, count: 3 },
  15139. { start: 3, materialIndex: 1, count: 3 },
  15140. { start: 6, materialIndex: 2, count: 6 }
  15141. ];
  15142. // we only care for materialIndex
  15143. b.faces.push(
  15144. new Face3( 0, 0, 0, undefined, undefined, 0 ),
  15145. new Face3( 0, 0, 0, undefined, undefined, 1 ),
  15146. new Face3( 0, 0, 0, undefined, undefined, 2 ),
  15147. new Face3( 0, 0, 0, undefined, undefined, 2 )
  15148. );
  15149. a.computeGroups( b );
  15150. assert.deepEqual( a.groups, expected, "Groups are as expected" );
  15151. } );
  15152. QUnit.test( "fromGeometry", ( assert ) => {
  15153. var a = new DirectGeometry();
  15154. var asyncDone = assert.async(); // tell QUnit when we're done with async stuff
  15155. var loader = new JSONLoader();
  15156. loader.load( "../../examples/models/skinned/simple/simple.js", function ( geometry ) {
  15157. a.fromGeometry( geometry );
  15158. var tmp = new DirectGeometry();
  15159. tmp.computeGroups( geometry );
  15160. assert.deepEqual( a.groups, tmp.groups, "Check groups" );
  15161. var morphTargets = geometry.morphTargets;
  15162. var morphTargetsLength = morphTargets.length;
  15163. var morphTargetsPosition;
  15164. if ( morphTargetsLength > 0 ) {
  15165. morphTargetsPosition = [];
  15166. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  15167. morphTargetsPosition[ i ] = [];
  15168. }
  15169. morphTargets.position = morphTargetsPosition;
  15170. }
  15171. var morphNormals = geometry.morphNormals;
  15172. var morphNormalsLength = morphNormals.length;
  15173. var morphTargetsNormal;
  15174. if ( morphNormalsLength > 0 ) {
  15175. morphTargetsNormal = [];
  15176. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  15177. morphTargetsNormal[ i ] = [];
  15178. }
  15179. morphTargets.normal = morphTargetsNormal;
  15180. }
  15181. var vertices = [];
  15182. var normals = [];
  15183. var colors = [];
  15184. var uvs = [];
  15185. var uvs2 = [];
  15186. var skinIndices = [];
  15187. var skinWeights = [];
  15188. var hasFaceVertexUv = geometry.faceVertexUvs[ 0 ] && geometry.faceVertexUvs[ 0 ].length > 0;
  15189. var hasFaceVertexUv2 = geometry.faceVertexUvs[ 1 ] && geometry.faceVertexUvs[ 1 ].length > 0;
  15190. var hasSkinIndices = geometry.skinIndices.length === geometry.vertices.length;
  15191. var hasSkinWeights = geometry.skinWeights.length === geometry.vertices.length;
  15192. for ( var i = 0; i < geometry.faces.length; i ++ ) {
  15193. var face = geometry.faces[ i ];
  15194. vertices.push(
  15195. geometry.vertices[ face.a ],
  15196. geometry.vertices[ face.b ],
  15197. geometry.vertices[ face.c ]
  15198. );
  15199. var vertexNormals = face.vertexNormals;
  15200. if ( vertexNormals.length === 3 ) {
  15201. normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  15202. } else {
  15203. normals.push( face.normal, face.normal, face.normal );
  15204. }
  15205. var vertexColors = face.vertexColors;
  15206. if ( vertexColors.length === 3 ) {
  15207. colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  15208. } else {
  15209. colors.push( face.color, face.color, face.color );
  15210. }
  15211. if ( hasFaceVertexUv === true ) {
  15212. var vertexUvs = geometry.faceVertexUvs[ 0 ][ i ];
  15213. if ( vertexUvs !== undefined ) {
  15214. uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  15215. } else {
  15216. uvs.push( new Vector2(), new Vector2(), new Vector2() );
  15217. }
  15218. }
  15219. if ( hasFaceVertexUv2 === true ) {
  15220. var vertexUvs = geometry.faceVertexUvs[ 1 ][ i ];
  15221. if ( vertexUvs !== undefined ) {
  15222. uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  15223. } else {
  15224. uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  15225. }
  15226. }
  15227. // morphs
  15228. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  15229. var morphTarget = morphTargets[ j ].vertices;
  15230. morphTargetsPosition[ j ].push(
  15231. morphTarget[ face.a ],
  15232. morphTarget[ face.b ],
  15233. morphTarget[ face.c ]
  15234. );
  15235. }
  15236. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  15237. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  15238. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  15239. }
  15240. // skins
  15241. if ( hasSkinIndices ) {
  15242. skinIndices.push(
  15243. geometry.skinIndices[ face.a ],
  15244. geometry.skinIndices[ face.b ],
  15245. geometry.skinIndices[ face.c ]
  15246. );
  15247. }
  15248. if ( hasSkinWeights ) {
  15249. skinWeights.push(
  15250. geometry.skinWeights[ face.a ],
  15251. geometry.skinWeights[ face.b ],
  15252. geometry.skinWeights[ face.c ]
  15253. );
  15254. }
  15255. }
  15256. assert.deepEqual( a.vertices, vertices, "Vertices are identical" );
  15257. assert.deepEqual( a.normals, normals, "Normals are identical" );
  15258. assert.deepEqual( a.colors, colors, "Colors are identical" );
  15259. assert.deepEqual( a.uvs, uvs, "UV coordinates are identical" );
  15260. assert.deepEqual( a.uvs2, uvs2, "UV(2) coordinates are identical" );
  15261. assert.deepEqual( a.skinIndices, skinIndices, "SkinIndices are identical" );
  15262. assert.deepEqual( a.skinWeights, skinWeights, "SkinWeights are identical" );
  15263. assert.deepEqual( a.morphTargetsPosition, morphTargetsPosition, "MorphTargets (Position) are identical" );
  15264. assert.deepEqual( a.morphTargetsNormal, morphTargetsNormal, "MorphTargets (Normals) are identical" );
  15265. asyncDone();
  15266. } );
  15267. } );
  15268. } );
  15269. } );
  15270. /**
  15271. * @author simonThiele / https://github.com/simonThiele
  15272. * @author TristanVALCKE / https://github.com/Itee
  15273. */
  15274. /* global QUnit */
  15275. QUnit.module( 'Core', () => {
  15276. QUnit.module.todo( 'EventDispatcher', () => {
  15277. // INSTANCING
  15278. QUnit.test( "Instancing", ( assert ) => {
  15279. assert.ok( false, "everything's gonna be alright" );
  15280. } );
  15281. // PUBLIC STUFF
  15282. QUnit.test( "addEventListener", ( assert ) => {
  15283. var eventDispatcher = new EventDispatcher();
  15284. var listener = {};
  15285. eventDispatcher.addEventListener( 'anyType', listener );
  15286. assert.ok( eventDispatcher._listeners.anyType.length === 1, "listener with unknown type was added" );
  15287. assert.ok( eventDispatcher._listeners.anyType[ 0 ] === listener, "listener with unknown type was added" );
  15288. eventDispatcher.addEventListener( 'anyType', listener );
  15289. assert.ok( eventDispatcher._listeners.anyType.length === 1, "can't add one listener twice to same type" );
  15290. assert.ok( eventDispatcher._listeners.anyType[ 0 ] === listener, "listener is still there" );
  15291. } );
  15292. QUnit.test( "hasEventListener", ( assert ) => {
  15293. var eventDispatcher = new EventDispatcher();
  15294. var listener = {};
  15295. eventDispatcher.addEventListener( 'anyType', listener );
  15296. assert.ok( eventDispatcher.hasEventListener( 'anyType', listener ), "listener was found" );
  15297. assert.ok( ! eventDispatcher.hasEventListener( 'anotherType', listener ), "listener was not found which is good" );
  15298. } );
  15299. QUnit.test( "removeEventListener", ( assert ) => {
  15300. var eventDispatcher = new EventDispatcher();
  15301. var listener = {};
  15302. assert.ok( eventDispatcher._listeners === undefined, "there are no listeners by default" );
  15303. eventDispatcher.addEventListener( 'anyType', listener );
  15304. assert.ok( Object.keys( eventDispatcher._listeners ).length === 1 &&
  15305. eventDispatcher._listeners.anyType.length === 1, "if a listener was added, there is a new key" );
  15306. eventDispatcher.removeEventListener( 'anyType', listener );
  15307. assert.ok( eventDispatcher._listeners.anyType.length === 0, "listener was deleted" );
  15308. eventDispatcher.removeEventListener( 'unknownType', listener );
  15309. assert.ok( eventDispatcher._listeners.unknownType === undefined, "unknown types will be ignored" );
  15310. eventDispatcher.removeEventListener( 'anyType', undefined );
  15311. assert.ok( eventDispatcher._listeners.anyType.length === 0, "undefined listeners are ignored" );
  15312. } );
  15313. QUnit.test( "dispatchEvent", ( assert ) => {
  15314. var eventDispatcher = new EventDispatcher();
  15315. var callCount = 0;
  15316. var listener = function () {
  15317. callCount ++;
  15318. };
  15319. eventDispatcher.addEventListener( 'anyType', listener );
  15320. assert.ok( callCount === 0, "no event, no call" );
  15321. eventDispatcher.dispatchEvent( { type: 'anyType' } );
  15322. assert.ok( callCount === 1, "one event, one call" );
  15323. eventDispatcher.dispatchEvent( { type: 'anyType' } );
  15324. assert.ok( callCount === 2, "two events, two calls" );
  15325. } );
  15326. } );
  15327. } );
  15328. /**
  15329. * @author simonThiele / https://github.com/simonThiele
  15330. * @author TristanVALCKE / https://github.com/Itee
  15331. */
  15332. /* global QUnit */
  15333. QUnit.module( 'Core', () => {
  15334. QUnit.module.todo( 'Face3', () => {
  15335. // INSTANCING
  15336. QUnit.test( "Instancing", ( assert ) => {
  15337. assert.ok( false, "everything's gonna be alright" );
  15338. } );
  15339. // PUBLIC STUFF
  15340. QUnit.test( "copy", ( assert ) => {
  15341. var instance = new Face3( 0, 1, 2, new Vector3( 0, 1, 0 ), new Color( 0.25, 0.5, 0.75 ), 2 );
  15342. var copiedInstance = instance.copy( instance );
  15343. checkCopy( copiedInstance, assert );
  15344. checkVertexAndColors( copiedInstance, assert );
  15345. } );
  15346. QUnit.test( "copy (more)", ( assert ) => {
  15347. var instance = new Face3( 0, 1, 2,
  15348. [ new Vector3( 0, 1, 0 ), new Vector3( 1, 0, 1 ) ],
  15349. [ new Color( 0.25, 0.5, 0.75 ), new Color( 1, 0, 0.4 ) ],
  15350. 2 );
  15351. var copiedInstance = instance.copy( instance );
  15352. checkCopy( copiedInstance, assert );
  15353. checkVertexAndColorArrays( copiedInstance, assert );
  15354. } );
  15355. QUnit.test( "clone", ( assert ) => {
  15356. var instance = new Face3( 0, 1, 2, new Vector3( 0, 1, 0 ), new Color( 0.25, 0.5, 0.75 ), 2 );
  15357. var copiedInstance = instance.clone();
  15358. checkCopy( copiedInstance, assert );
  15359. checkVertexAndColors( copiedInstance, assert );
  15360. } );
  15361. function checkCopy( copiedInstance, assert ) {
  15362. assert.ok( copiedInstance instanceof Face3, "copy created the correct type" );
  15363. assert.ok(
  15364. copiedInstance.a === 0 &&
  15365. copiedInstance.b === 1 &&
  15366. copiedInstance.c === 2 &&
  15367. copiedInstance.materialIndex === 2
  15368. , "properties where copied" );
  15369. }
  15370. function checkVertexAndColors( copiedInstance, assert ) {
  15371. assert.ok(
  15372. copiedInstance.normal.x === 0 && copiedInstance.normal.y === 1 && copiedInstance.normal.z === 0 &&
  15373. copiedInstance.color.r === 0.25 && copiedInstance.color.g === 0.5 && copiedInstance.color.b === 0.75
  15374. , "properties where copied" );
  15375. }
  15376. function checkVertexAndColorArrays( copiedInstance, assert ) {
  15377. assert.ok(
  15378. copiedInstance.vertexNormals[ 0 ].x === 0 && copiedInstance.vertexNormals[ 0 ].y === 1 && copiedInstance.vertexNormals[ 0 ].z === 0 &&
  15379. copiedInstance.vertexNormals[ 1 ].x === 1 && copiedInstance.vertexNormals[ 1 ].y === 0 && copiedInstance.vertexNormals[ 1 ].z === 1 &&
  15380. copiedInstance.vertexColors[ 0 ].r === 0.25 && copiedInstance.vertexColors[ 0 ].g === 0.5 && copiedInstance.vertexColors[ 0 ].b === 0.75 &&
  15381. copiedInstance.vertexColors[ 1 ].r === 1 && copiedInstance.vertexColors[ 1 ].g === 0 && copiedInstance.vertexColors[ 1 ].b === 0.4
  15382. , "properties where copied" );
  15383. }
  15384. } );
  15385. } );
  15386. /**
  15387. * @author clockworkgeek / https://github.com/clockworkgeek
  15388. * @author timothypratley / https://github.com/timothypratley
  15389. * @author WestLangley / http://github.com/WestLangley
  15390. * @author Mugen87 / https://github.com/Mugen87
  15391. */
  15392. // PolyhedronGeometry
  15393. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  15394. Geometry.call( this );
  15395. this.type = 'PolyhedronGeometry';
  15396. this.parameters = {
  15397. vertices: vertices,
  15398. indices: indices,
  15399. radius: radius,
  15400. detail: detail
  15401. };
  15402. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  15403. this.mergeVertices();
  15404. }
  15405. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  15406. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  15407. // PolyhedronBufferGeometry
  15408. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  15409. BufferGeometry.call( this );
  15410. this.type = 'PolyhedronBufferGeometry';
  15411. this.parameters = {
  15412. vertices: vertices,
  15413. indices: indices,
  15414. radius: radius,
  15415. detail: detail
  15416. };
  15417. radius = radius || 1;
  15418. detail = detail || 0;
  15419. // default buffer data
  15420. var vertexBuffer = [];
  15421. var uvBuffer = [];
  15422. // the subdivision creates the vertex buffer data
  15423. subdivide( detail );
  15424. // all vertices should lie on a conceptual sphere with a given radius
  15425. appplyRadius( radius );
  15426. // finally, create the uv data
  15427. generateUVs();
  15428. // build non-indexed geometry
  15429. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  15430. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  15431. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  15432. if ( detail === 0 ) {
  15433. this.computeVertexNormals(); // flat normals
  15434. } else {
  15435. this.normalizeNormals(); // smooth normals
  15436. }
  15437. // helper functions
  15438. function subdivide( detail ) {
  15439. var a = new Vector3();
  15440. var b = new Vector3();
  15441. var c = new Vector3();
  15442. // iterate over all faces and apply a subdivison with the given detail value
  15443. for ( var i = 0; i < indices.length; i += 3 ) {
  15444. // get the vertices of the face
  15445. getVertexByIndex( indices[ i + 0 ], a );
  15446. getVertexByIndex( indices[ i + 1 ], b );
  15447. getVertexByIndex( indices[ i + 2 ], c );
  15448. // perform subdivision
  15449. subdivideFace( a, b, c, detail );
  15450. }
  15451. }
  15452. function subdivideFace( a, b, c, detail ) {
  15453. var cols = Math.pow( 2, detail );
  15454. // we use this multidimensional array as a data structure for creating the subdivision
  15455. var v = [];
  15456. var i, j;
  15457. // construct all of the vertices for this subdivision
  15458. for ( i = 0; i <= cols; i ++ ) {
  15459. v[ i ] = [];
  15460. var aj = a.clone().lerp( c, i / cols );
  15461. var bj = b.clone().lerp( c, i / cols );
  15462. var rows = cols - i;
  15463. for ( j = 0; j <= rows; j ++ ) {
  15464. if ( j === 0 && i === cols ) {
  15465. v[ i ][ j ] = aj;
  15466. } else {
  15467. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  15468. }
  15469. }
  15470. }
  15471. // construct all of the faces
  15472. for ( i = 0; i < cols; i ++ ) {
  15473. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  15474. var k = Math.floor( j / 2 );
  15475. if ( j % 2 === 0 ) {
  15476. pushVertex( v[ i ][ k + 1 ] );
  15477. pushVertex( v[ i + 1 ][ k ] );
  15478. pushVertex( v[ i ][ k ] );
  15479. } else {
  15480. pushVertex( v[ i ][ k + 1 ] );
  15481. pushVertex( v[ i + 1 ][ k + 1 ] );
  15482. pushVertex( v[ i + 1 ][ k ] );
  15483. }
  15484. }
  15485. }
  15486. }
  15487. function appplyRadius( radius ) {
  15488. var vertex = new Vector3();
  15489. // iterate over the entire buffer and apply the radius to each vertex
  15490. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  15491. vertex.x = vertexBuffer[ i + 0 ];
  15492. vertex.y = vertexBuffer[ i + 1 ];
  15493. vertex.z = vertexBuffer[ i + 2 ];
  15494. vertex.normalize().multiplyScalar( radius );
  15495. vertexBuffer[ i + 0 ] = vertex.x;
  15496. vertexBuffer[ i + 1 ] = vertex.y;
  15497. vertexBuffer[ i + 2 ] = vertex.z;
  15498. }
  15499. }
  15500. function generateUVs() {
  15501. var vertex = new Vector3();
  15502. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  15503. vertex.x = vertexBuffer[ i + 0 ];
  15504. vertex.y = vertexBuffer[ i + 1 ];
  15505. vertex.z = vertexBuffer[ i + 2 ];
  15506. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  15507. var v = inclination( vertex ) / Math.PI + 0.5;
  15508. uvBuffer.push( u, 1 - v );
  15509. }
  15510. correctUVs();
  15511. correctSeam();
  15512. }
  15513. function correctSeam() {
  15514. // handle case when face straddles the seam, see #3269
  15515. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  15516. // uv data of a single face
  15517. var x0 = uvBuffer[ i + 0 ];
  15518. var x1 = uvBuffer[ i + 2 ];
  15519. var x2 = uvBuffer[ i + 4 ];
  15520. var max = Math.max( x0, x1, x2 );
  15521. var min = Math.min( x0, x1, x2 );
  15522. // 0.9 is somewhat arbitrary
  15523. if ( max > 0.9 && min < 0.1 ) {
  15524. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  15525. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  15526. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  15527. }
  15528. }
  15529. }
  15530. function pushVertex( vertex ) {
  15531. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  15532. }
  15533. function getVertexByIndex( index, vertex ) {
  15534. var stride = index * 3;
  15535. vertex.x = vertices[ stride + 0 ];
  15536. vertex.y = vertices[ stride + 1 ];
  15537. vertex.z = vertices[ stride + 2 ];
  15538. }
  15539. function correctUVs() {
  15540. var a = new Vector3();
  15541. var b = new Vector3();
  15542. var c = new Vector3();
  15543. var centroid = new Vector3();
  15544. var uvA = new Vector2();
  15545. var uvB = new Vector2();
  15546. var uvC = new Vector2();
  15547. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  15548. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  15549. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  15550. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  15551. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  15552. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  15553. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  15554. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  15555. var azi = azimuth( centroid );
  15556. correctUV( uvA, j + 0, a, azi );
  15557. correctUV( uvB, j + 2, b, azi );
  15558. correctUV( uvC, j + 4, c, azi );
  15559. }
  15560. }
  15561. function correctUV( uv, stride, vector, azimuth ) {
  15562. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  15563. uvBuffer[ stride ] = uv.x - 1;
  15564. }
  15565. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  15566. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  15567. }
  15568. }
  15569. // Angle around the Y axis, counter-clockwise when looking from above.
  15570. function azimuth( vector ) {
  15571. return Math.atan2( vector.z, - vector.x );
  15572. }
  15573. // Angle above the XZ plane.
  15574. function inclination( vector ) {
  15575. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  15576. }
  15577. }
  15578. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15579. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  15580. /**
  15581. * @author Abe Pazos / https://hamoid.com
  15582. * @author Mugen87 / https://github.com/Mugen87
  15583. */
  15584. // DodecahedronGeometry
  15585. function DodecahedronGeometry( radius, detail ) {
  15586. Geometry.call( this );
  15587. this.type = 'DodecahedronGeometry';
  15588. this.parameters = {
  15589. radius: radius,
  15590. detail: detail
  15591. };
  15592. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  15593. this.mergeVertices();
  15594. }
  15595. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  15596. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  15597. // DodecahedronBufferGeometry
  15598. function DodecahedronBufferGeometry( radius, detail ) {
  15599. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  15600. var r = 1 / t;
  15601. var vertices = [
  15602. // (±1, ±1, ±1)
  15603. - 1, - 1, - 1, - 1, - 1, 1,
  15604. - 1, 1, - 1, - 1, 1, 1,
  15605. 1, - 1, - 1, 1, - 1, 1,
  15606. 1, 1, - 1, 1, 1, 1,
  15607. // (0, ±1/φ, ±φ)
  15608. 0, - r, - t, 0, - r, t,
  15609. 0, r, - t, 0, r, t,
  15610. // (±1/φ, ±φ, 0)
  15611. - r, - t, 0, - r, t, 0,
  15612. r, - t, 0, r, t, 0,
  15613. // (±φ, 0, ±1/φ)
  15614. - t, 0, - r, t, 0, - r,
  15615. - t, 0, r, t, 0, r
  15616. ];
  15617. var indices = [
  15618. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  15619. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  15620. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  15621. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  15622. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  15623. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  15624. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  15625. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  15626. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  15627. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  15628. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  15629. 1, 12, 14, 1, 14, 5, 1, 5, 9
  15630. ];
  15631. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15632. this.type = 'DodecahedronBufferGeometry';
  15633. this.parameters = {
  15634. radius: radius,
  15635. detail: detail
  15636. };
  15637. }
  15638. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15639. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  15640. /**
  15641. * @author simonThiele / https://github.com/simonThiele
  15642. */
  15643. /* global QUnit */
  15644. function getGeometryByParams( x1, y1, z1, x2, y2, z2, x3, y3, z3 ) {
  15645. var geometry = new Geometry();
  15646. // a triangle
  15647. geometry.vertices = [
  15648. new Vector3( x1, y1, z1 ),
  15649. new Vector3( x2, y2, z2 ),
  15650. new Vector3( x3, y3, z3 )
  15651. ];
  15652. return geometry;
  15653. }
  15654. function getGeometry() {
  15655. return getGeometryByParams( - 0.5, 0, 0, 0.5, 0, 0, 0, 1, 0 );
  15656. }
  15657. QUnit.module( 'Core', () => {
  15658. QUnit.module.todo( 'Geometry', () => {
  15659. // INHERITANCE
  15660. QUnit.test( "Extending", ( assert ) => {
  15661. assert.ok( false, "everything's gonna be alright" );
  15662. } );
  15663. // INSTANCING
  15664. QUnit.test( "Instancing", ( assert ) => {
  15665. assert.ok( false, "everything's gonna be alright" );
  15666. } );
  15667. // PUBLIC STUFF
  15668. QUnit.test( "isGeometry", ( assert ) => {
  15669. assert.ok( false, "everything's gonna be alright" );
  15670. } );
  15671. QUnit.test( "applyMatrix", ( assert ) => {
  15672. var geometry = getGeometry();
  15673. geometry.faces.push( new Face3( 0, 1, 2 ) );
  15674. var m = new Matrix4();
  15675. var expectedVerts = [
  15676. new Vector3( 1.5, 3, 4 ),
  15677. new Vector3( 2.5, 3, 4 ),
  15678. new Vector3( 2, 3, 5 )
  15679. ];
  15680. var v0, v1, v2;
  15681. m.makeRotationX( Math.PI / 2 );
  15682. m.setPosition( new Vector3( x, y, z ) );
  15683. geometry.applyMatrix( m );
  15684. v0 = geometry.vertices[ 0 ];
  15685. v1 = geometry.vertices[ 1 ];
  15686. v2 = geometry.vertices[ 2 ];
  15687. assert.ok(
  15688. Math.abs( v0.x - expectedVerts[ 0 ].x ) <= eps &&
  15689. Math.abs( v0.y - expectedVerts[ 0 ].y ) <= eps &&
  15690. Math.abs( v0.z - expectedVerts[ 0 ].z ) <= eps,
  15691. "First vertex is as expected"
  15692. );
  15693. assert.ok(
  15694. Math.abs( v1.x - expectedVerts[ 1 ].x ) <= eps &&
  15695. Math.abs( v1.y - expectedVerts[ 1 ].y ) <= eps &&
  15696. Math.abs( v1.z - expectedVerts[ 1 ].z ) <= eps,
  15697. "Second vertex is as expected"
  15698. );
  15699. assert.ok(
  15700. Math.abs( v2.x - expectedVerts[ 2 ].x ) <= eps &&
  15701. Math.abs( v2.y - expectedVerts[ 2 ].y ) <= eps &&
  15702. Math.abs( v2.z - expectedVerts[ 2 ].z ) <= eps,
  15703. "Third vertex is as expected"
  15704. );
  15705. } );
  15706. QUnit.test( "rotateX", ( assert ) => {
  15707. var geometry = getGeometry();
  15708. var matrix = new Matrix4();
  15709. matrix.makeRotationX( Math.PI / 2 ); // 90 degree
  15710. geometry.applyMatrix( matrix );
  15711. var v0 = geometry.vertices[ 0 ], v1 = geometry.vertices[ 1 ], v2 = geometry.vertices[ 2 ];
  15712. assert.ok( v0.x === - 0.5 && v0.y === 0 && v0.z === 0, "first vertex was rotated" );
  15713. assert.ok( v1.x === 0.5 && v1.y === 0 && v1.z === 0, "second vertex was rotated" );
  15714. assert.ok( v2.x === 0 && v2.y < Number.EPSILON && v2.z === 1, "third vertex was rotated" );
  15715. } );
  15716. QUnit.test( "rotateY", ( assert ) => {
  15717. var geometry = getGeometry();
  15718. var matrix = new Matrix4();
  15719. matrix.makeRotationY( Math.PI ); // 180 degrees
  15720. geometry.applyMatrix( matrix );
  15721. var v0 = geometry.vertices[ 0 ], v1 = geometry.vertices[ 1 ], v2 = geometry.vertices[ 2 ];
  15722. assert.ok( v0.x === 0.5 && v0.y === 0 && v0.z < Number.EPSILON, "first vertex was rotated" );
  15723. assert.ok( v1.x === - 0.5 && v1.y === 0 && v1.z < Number.EPSILON, "second vertex was rotated" );
  15724. assert.ok( v2.x === 0 && v2.y === 1 && v2.z === 0, "third vertex was rotated" );
  15725. } );
  15726. QUnit.test( "rotateZ", ( assert ) => {
  15727. var geometry = getGeometry();
  15728. var matrix = new Matrix4();
  15729. matrix.makeRotationZ( Math.PI / 2 * 3 ); // 270 degrees
  15730. geometry.applyMatrix( matrix );
  15731. var v0 = geometry.vertices[ 0 ], v1 = geometry.vertices[ 1 ], v2 = geometry.vertices[ 2 ];
  15732. assert.ok( v0.x < Number.EPSILON && v0.y === 0.5 && v0.z === 0, "first vertex was rotated" );
  15733. assert.ok( v1.x < Number.EPSILON && v1.y === - 0.5 && v1.z === 0, "second vertex was rotated" );
  15734. assert.ok( v2.x === 1 && v2.y < Number.EPSILON && v2.z === 0, "third vertex was rotated" );
  15735. } );
  15736. QUnit.test( "translate", ( assert ) => {
  15737. var a = getGeometry();
  15738. var expected = [
  15739. new Vector3( - 2.5, 3, - 4 ),
  15740. new Vector3( - 1.5, 3, - 4 ),
  15741. new Vector3( - 2, 4, - 4 )
  15742. ];
  15743. var v;
  15744. a.translate( - x, y, - z );
  15745. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15746. v = a.vertices[ i ];
  15747. assert.ok(
  15748. Math.abs( v.x - expected[ i ].x ) <= eps &&
  15749. Math.abs( v.y - expected[ i ].y ) <= eps &&
  15750. Math.abs( v.z - expected[ i ].z ) <= eps,
  15751. "Vertex #" + i + " was translated as expected"
  15752. );
  15753. }
  15754. } );
  15755. QUnit.test( "scale", ( assert ) => {
  15756. var a = getGeometry();
  15757. var expected = [
  15758. new Vector3( - 1, 0, 0 ),
  15759. new Vector3( 1, 0, 0 ),
  15760. new Vector3( 0, 3, 0 )
  15761. ];
  15762. var v;
  15763. a.scale( 2, 3, 4 );
  15764. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15765. v = a.vertices[ i ];
  15766. assert.ok(
  15767. Math.abs( v.x - expected[ i ].x ) <= eps &&
  15768. Math.abs( v.y - expected[ i ].y ) <= eps &&
  15769. Math.abs( v.z - expected[ i ].z ) <= eps,
  15770. "Vertex #" + i + " was scaled as expected"
  15771. );
  15772. }
  15773. } );
  15774. QUnit.test( "lookAt", ( assert ) => {
  15775. var a = getGeometry();
  15776. var expected = [
  15777. new Vector3( - 0.5, 0, 0 ),
  15778. new Vector3( 0.5, 0, 0 ),
  15779. new Vector3( 0, 0.5 * Math.sqrt( 2 ), 0.5 * Math.sqrt( 2 ) )
  15780. ];
  15781. a.lookAt( new Vector3( 0, - 1, 1 ) );
  15782. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15783. var v = a.vertices[ i ];
  15784. assert.ok(
  15785. Math.abs( v.x - expected[ i ].x ) <= eps &&
  15786. Math.abs( v.y - expected[ i ].y ) <= eps &&
  15787. Math.abs( v.z - expected[ i ].z ) <= eps,
  15788. "Vertex #" + i + " was adjusted as expected"
  15789. );
  15790. }
  15791. } );
  15792. QUnit.test( "fromBufferGeometry", ( assert ) => {
  15793. var bufferGeometry = new BufferGeometry();
  15794. bufferGeometry.addAttribute( 'position', new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ), 3 ) );
  15795. bufferGeometry.addAttribute( 'color', new BufferAttribute( new Float32Array( [ 0, 0, 0, 0.5, 0.5, 0.5, 1, 1, 1 ] ), 3 ) );
  15796. bufferGeometry.addAttribute( 'normal', new BufferAttribute( new Float32Array( [ 0, 1, 0, 1, 0, 1, 1, 1, 0 ] ), 3 ) );
  15797. bufferGeometry.addAttribute( 'uv', new BufferAttribute( new Float32Array( [ 0, 0, 0, 1, 1, 1 ] ), 2 ) );
  15798. bufferGeometry.addAttribute( 'uv2', new BufferAttribute( new Float32Array( [ 0, 0, 0, 1, 1, 1 ] ), 2 ) );
  15799. var geometry = new Geometry().fromBufferGeometry( bufferGeometry );
  15800. var colors = geometry.colors;
  15801. assert.ok(
  15802. colors[ 0 ].r === 0 && colors[ 0 ].g === 0 && colors[ 0 ].b === 0 &&
  15803. colors[ 1 ].r === 0.5 && colors[ 1 ].g === 0.5 && colors[ 1 ].b === 0.5 &&
  15804. colors[ 2 ].r === 1 && colors[ 2 ].g === 1 && colors[ 2 ].b === 1
  15805. , "colors were created well" );
  15806. var vertices = geometry.vertices;
  15807. assert.ok(
  15808. vertices[ 0 ].x === 1 && vertices[ 0 ].y === 2 && vertices[ 0 ].z === 3 &&
  15809. vertices[ 1 ].x === 4 && vertices[ 1 ].y === 5 && vertices[ 1 ].z === 6 &&
  15810. vertices[ 2 ].x === 7 && vertices[ 2 ].y === 8 && vertices[ 2 ].z === 9
  15811. , "vertices were created well" );
  15812. var vNormals = geometry.faces[ 0 ].vertexNormals;
  15813. assert.ok(
  15814. vNormals[ 0 ].x === 0 && vNormals[ 0 ].y === 1 && vNormals[ 0 ].z === 0 &&
  15815. vNormals[ 1 ].x === 1 && vNormals[ 1 ].y === 0 && vNormals[ 1 ].z === 1 &&
  15816. vNormals[ 2 ].x === 1 && vNormals[ 2 ].y === 1 && vNormals[ 2 ].z === 0
  15817. , "vertex normals were created well" );
  15818. } );
  15819. QUnit.test( "center", ( assert ) => {
  15820. assert.ok( false, "everything's gonna be alright" );
  15821. } );
  15822. QUnit.test( "normalize", ( assert ) => {
  15823. var geometry = getGeometry();
  15824. geometry.computeLineDistances();
  15825. var distances = geometry.lineDistances;
  15826. assert.ok( distances[ 0 ] === 0, "distance to the 1st point is 0" );
  15827. assert.ok( distances[ 1 ] === 1 + distances[ 0 ], "distance from the 1st to the 2nd is sqrt(2nd - 1st) + distance - 1" );
  15828. 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" );
  15829. } );
  15830. QUnit.test( "normalize (actual)", ( assert ) => {
  15831. var a = getGeometry();
  15832. var sqrt = 0.5 * Math.sqrt( 2 );
  15833. var expected = [
  15834. new Vector3( - sqrt, - sqrt, 0 ),
  15835. new Vector3( sqrt, - sqrt, 0 ),
  15836. new Vector3( 0, sqrt, 0 )
  15837. ];
  15838. var v;
  15839. a.normalize();
  15840. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15841. v = a.vertices[ i ];
  15842. assert.ok(
  15843. Math.abs( v.x - expected[ i ].x ) <= eps &&
  15844. Math.abs( v.y - expected[ i ].y ) <= eps &&
  15845. Math.abs( v.z - expected[ i ].z ) <= eps,
  15846. "Vertex #" + i + " was normalized as expected"
  15847. );
  15848. }
  15849. } );
  15850. QUnit.test( "computeFaceNormals", ( assert ) => {
  15851. assert.ok( false, "everything's gonna be alright" );
  15852. } );
  15853. QUnit.test( "computeVertexNormals", ( assert ) => {
  15854. assert.ok( false, "everything's gonna be alright" );
  15855. } );
  15856. QUnit.test( "computeFlatVertexNormals", ( assert ) => {
  15857. assert.ok( false, "everything's gonna be alright" );
  15858. } );
  15859. QUnit.test( "computeMorphNormals", ( assert ) => {
  15860. assert.ok( false, "everything's gonna be alright" );
  15861. } );
  15862. QUnit.test( "computeLineDistances", ( assert ) => {
  15863. assert.ok( false, "everything's gonna be alright" );
  15864. } );
  15865. QUnit.test( "computeBoundingBox", ( assert ) => {
  15866. var a = new DodecahedronGeometry();
  15867. a.computeBoundingBox();
  15868. assert.strictEqual( a.boundingBox.isEmpty(), false, "Bounding box isn't empty" );
  15869. var allIn = true;
  15870. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15871. if ( ! a.boundingBox.containsPoint( a.vertices[ i ] ) ) {
  15872. allIn = false;
  15873. }
  15874. }
  15875. assert.strictEqual( allIn, true, "All vertices are inside the box" );
  15876. } );
  15877. QUnit.test( "computeBoundingSphere", ( assert ) => {
  15878. var a = new DodecahedronGeometry();
  15879. a.computeBoundingSphere();
  15880. var allIn = true;
  15881. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15882. if ( ! a.boundingSphere.containsPoint( a.vertices[ i ] ) ) {
  15883. allIn = false;
  15884. }
  15885. }
  15886. assert.strictEqual( allIn, true, "All vertices are inside the bounding sphere" );
  15887. } );
  15888. QUnit.test( "merge", ( assert ) => {
  15889. assert.ok( false, "everything's gonna be alright" );
  15890. } );
  15891. QUnit.test( "mergeMesh", ( assert ) => {
  15892. assert.ok( false, "everything's gonna be alright" );
  15893. } );
  15894. QUnit.test( "mergeVertices", ( assert ) => {
  15895. var a = new Geometry();
  15896. var b = new BoxBufferGeometry( 1, 1, 1 );
  15897. var verts, faces, removed;
  15898. a.fromBufferGeometry( b );
  15899. removed = a.mergeVertices();
  15900. verts = a.vertices.length;
  15901. faces = a.faces.length;
  15902. assert.strictEqual( removed, 16, "Removed the expected number of vertices" );
  15903. assert.strictEqual( verts, 8, "Minimum number of vertices remaining" );
  15904. assert.strictEqual( faces, 12, "Minimum number of faces remaining" );
  15905. } );
  15906. QUnit.test( "sortFacesByMaterialIndex", ( assert ) => {
  15907. var box = new BoxBufferGeometry( 1, 1, 1 );
  15908. var a = new Geometry().fromBufferGeometry( box );
  15909. var expected = [ 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 ];
  15910. a.faces.reverse(); // a bit too simple probably, still missing stuff like checking new UVs
  15911. a.sortFacesByMaterialIndex();
  15912. var indices = [];
  15913. for ( var i = 0; i < a.faces.length; i ++ ) {
  15914. indices.push( a.faces[ i ].materialIndex );
  15915. }
  15916. assert.deepEqual( indices, expected, "Faces in correct order" );
  15917. } );
  15918. QUnit.test( "toJSON", ( assert ) => {
  15919. var a = getGeometry();
  15920. var gold = {
  15921. "metadata": {
  15922. "version": 4.5,
  15923. "type": "Geometry",
  15924. "generator": "Geometry.toJSON"
  15925. },
  15926. "uuid": null,
  15927. "type": "Geometry",
  15928. "data": {
  15929. "vertices": [ - 0.5, 0, 0, 0.5, 0, 0, 0, 1, 0 ],
  15930. "normals": [ 0, 0, 1 ],
  15931. "faces": [ 50, 0, 1, 2, 0, 0, 0, 0, 0 ]
  15932. }
  15933. };
  15934. var json;
  15935. a.faces.push( new Face3( 0, 1, 2 ) );
  15936. a.computeFaceNormals();
  15937. a.computeVertexNormals();
  15938. json = a.toJSON();
  15939. json.uuid = null;
  15940. assert.deepEqual( json, gold, "Generated JSON is as expected" );
  15941. } );
  15942. QUnit.test( "clone", ( assert ) => {
  15943. assert.ok( false, "everything's gonna be alright" );
  15944. } );
  15945. QUnit.test( "copy", ( assert ) => {
  15946. assert.ok( false, "everything's gonna be alright" );
  15947. } );
  15948. QUnit.test( "dispose", ( assert ) => {
  15949. assert.ok( false, "everything's gonna be alright" );
  15950. } );
  15951. } );
  15952. } );
  15953. /**
  15954. * @author benaadams / https://twitter.com/ben_a_adams
  15955. */
  15956. function InstancedBufferAttribute( array, itemSize, meshPerAttribute ) {
  15957. BufferAttribute.call( this, array, itemSize );
  15958. this.meshPerAttribute = meshPerAttribute || 1;
  15959. }
  15960. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  15961. constructor: InstancedBufferAttribute,
  15962. isInstancedBufferAttribute: true,
  15963. copy: function ( source ) {
  15964. BufferAttribute.prototype.copy.call( this, source );
  15965. this.meshPerAttribute = source.meshPerAttribute;
  15966. return this;
  15967. }
  15968. } );
  15969. /**
  15970. * @author simonThiele / https://github.com/simonThiele
  15971. */
  15972. /* global QUnit */
  15973. QUnit.module( 'Core', () => {
  15974. QUnit.module.todo( 'InstancedBufferAttribute', () => {
  15975. // INHERITANCE
  15976. QUnit.test( "Extending", ( assert ) => {
  15977. assert.ok( false, "everything's gonna be alright" );
  15978. } );
  15979. // INSTANCING
  15980. QUnit.test( "Instancing", ( assert ) => {
  15981. var instance = new InstancedBufferAttribute( new Float32Array( 10 ), 2 );
  15982. assert.ok( instance.meshPerAttribute === 1, "ok" );
  15983. var instance = new InstancedBufferAttribute( new Float32Array( 10 ), 2, 123 );
  15984. assert.ok( instance.meshPerAttribute === 123, "ok" );
  15985. } );
  15986. // PUBLIC STUFF
  15987. QUnit.test( "copy", ( assert ) => {
  15988. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  15989. var instance = new InstancedBufferAttribute( array, 2, 123 );
  15990. var copiedInstance = instance.copy( instance );
  15991. assert.ok( copiedInstance instanceof InstancedBufferAttribute, "the clone has the correct type" );
  15992. assert.ok( copiedInstance.itemSize === 2, "itemSize was copied" );
  15993. assert.ok( copiedInstance.meshPerAttribute === 123, "meshPerAttribute was copied" );
  15994. for ( var i = 0; i < array.length; i ++ ) {
  15995. assert.ok( copiedInstance.array[ i ] === array[ i ], "array was copied" );
  15996. }
  15997. } );
  15998. } );
  15999. } );
  16000. /**
  16001. * @author benaadams / https://twitter.com/ben_a_adams
  16002. */
  16003. function InstancedBufferGeometry() {
  16004. BufferGeometry.call( this );
  16005. this.type = 'InstancedBufferGeometry';
  16006. this.maxInstancedCount = undefined;
  16007. }
  16008. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  16009. constructor: InstancedBufferGeometry,
  16010. isInstancedBufferGeometry: true,
  16011. copy: function ( source ) {
  16012. BufferGeometry.prototype.copy.call( this, source );
  16013. this.maxInstancedCount = source.maxInstancedCount;
  16014. return this;
  16015. },
  16016. clone: function () {
  16017. return new this.constructor().copy( this );
  16018. }
  16019. } );
  16020. /**
  16021. * @author simonThiele / https://github.com/simonThiele
  16022. */
  16023. /* global QUnit */
  16024. QUnit.module( 'Core', () => {
  16025. QUnit.module.todo( 'InstancedBufferGeometry', () => {
  16026. function createClonableMock() {
  16027. return {
  16028. callCount: 0,
  16029. clone: function () {
  16030. this.callCount ++;
  16031. return this;
  16032. }
  16033. };
  16034. }
  16035. // INHERITANCE
  16036. QUnit.test( "Extending", ( assert ) => {
  16037. assert.ok( false, "everything's gonna be alright" );
  16038. } );
  16039. // INSTANCING
  16040. QUnit.test( "Instancing", ( assert ) => {
  16041. assert.ok( false, "everything's gonna be alright" );
  16042. } );
  16043. // PUBLIC STUFF
  16044. QUnit.test( "copy", ( assert ) => {
  16045. var instanceMock1 = {};
  16046. var instanceMock2 = {};
  16047. var indexMock = createClonableMock();
  16048. var defaultAttribute1 = new BufferAttribute( new Float32Array( [ 1 ] ) );
  16049. var defaultAttribute2 = new BufferAttribute( new Float32Array( [ 2 ] ) );
  16050. var instance = new InstancedBufferGeometry();
  16051. instance.addGroup( 0, 10, instanceMock1 );
  16052. instance.addGroup( 10, 5, instanceMock2 );
  16053. instance.setIndex( indexMock );
  16054. instance.addAttribute( 'defaultAttribute1', defaultAttribute1 );
  16055. instance.addAttribute( 'defaultAttribute2', defaultAttribute2 );
  16056. var copiedInstance = new InstancedBufferGeometry().copy( instance );
  16057. assert.ok( copiedInstance instanceof InstancedBufferGeometry, "the clone has the correct type" );
  16058. assert.equal( copiedInstance.index, indexMock, "index was copied" );
  16059. assert.equal( copiedInstance.index.callCount, 1, "index.clone was called once" );
  16060. assert.ok( copiedInstance.attributes[ 'defaultAttribute1' ] instanceof BufferAttribute, "attribute was created" );
  16061. assert.deepEqual( copiedInstance.attributes[ 'defaultAttribute1' ].array, defaultAttribute1.array, "attribute was copied" );
  16062. assert.deepEqual( copiedInstance.attributes[ 'defaultAttribute2' ].array, defaultAttribute2.array, "attribute was copied" );
  16063. assert.equal( copiedInstance.groups[ 0 ].start, 0, "group was copied" );
  16064. assert.equal( copiedInstance.groups[ 0 ].count, 10, "group was copied" );
  16065. assert.equal( copiedInstance.groups[ 0 ].materialIndex, instanceMock1, "group was copied" );
  16066. assert.equal( copiedInstance.groups[ 1 ].start, 10, "group was copied" );
  16067. assert.equal( copiedInstance.groups[ 1 ].count, 5, "group was copied" );
  16068. assert.equal( copiedInstance.groups[ 1 ].materialIndex, instanceMock2, "group was copied" );
  16069. } );
  16070. QUnit.test( "clone", ( assert ) => {
  16071. assert.ok( false, "everything's gonna be alright" );
  16072. } );
  16073. } );
  16074. } );
  16075. /**
  16076. * @author benaadams / https://twitter.com/ben_a_adams
  16077. */
  16078. function InterleavedBuffer( array, stride ) {
  16079. this.uuid = _Math.generateUUID();
  16080. this.array = array;
  16081. this.stride = stride;
  16082. this.count = array !== undefined ? array.length / stride : 0;
  16083. this.dynamic = false;
  16084. this.updateRange = { offset: 0, count: - 1 };
  16085. this.onUploadCallback = function () {};
  16086. this.version = 0;
  16087. }
  16088. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  16089. set: function ( value ) {
  16090. if ( value === true ) this.version ++;
  16091. }
  16092. } );
  16093. Object.assign( InterleavedBuffer.prototype, {
  16094. isInterleavedBuffer: true,
  16095. setArray: function ( array ) {
  16096. if ( Array.isArray( array ) ) {
  16097. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  16098. }
  16099. this.count = array !== undefined ? array.length / this.stride : 0;
  16100. this.array = array;
  16101. },
  16102. setDynamic: function ( value ) {
  16103. this.dynamic = value;
  16104. return this;
  16105. },
  16106. copy: function ( source ) {
  16107. this.array = new source.array.constructor( source.array );
  16108. this.count = source.count;
  16109. this.stride = source.stride;
  16110. this.dynamic = source.dynamic;
  16111. return this;
  16112. },
  16113. copyAt: function ( index1, attribute, index2 ) {
  16114. index1 *= this.stride;
  16115. index2 *= attribute.stride;
  16116. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  16117. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  16118. }
  16119. return this;
  16120. },
  16121. set: function ( value, offset ) {
  16122. if ( offset === undefined ) offset = 0;
  16123. this.array.set( value, offset );
  16124. return this;
  16125. },
  16126. clone: function () {
  16127. return new this.constructor().copy( this );
  16128. },
  16129. onUpload: function ( callback ) {
  16130. this.onUploadCallback = callback;
  16131. return this;
  16132. }
  16133. } );
  16134. /**
  16135. * @author benaadams / https://twitter.com/ben_a_adams
  16136. */
  16137. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  16138. InterleavedBuffer.call( this, array, stride );
  16139. this.meshPerAttribute = meshPerAttribute || 1;
  16140. }
  16141. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  16142. constructor: InstancedInterleavedBuffer,
  16143. isInstancedInterleavedBuffer: true,
  16144. copy: function ( source ) {
  16145. InterleavedBuffer.prototype.copy.call( this, source );
  16146. this.meshPerAttribute = source.meshPerAttribute;
  16147. return this;
  16148. }
  16149. } );
  16150. /**
  16151. * @author simonThiele / https://github.com/simonThiele
  16152. */
  16153. /* global QUnit */
  16154. QUnit.module( 'Core', () => {
  16155. QUnit.module.todo( 'InstancedInterleavedBuffer', () => {
  16156. // INHERITANCE
  16157. QUnit.test( "Extending", ( assert ) => {
  16158. assert.ok( false, "everything's gonna be alright" );
  16159. } );
  16160. // INSTANCING
  16161. QUnit.test( "Instancing", ( assert ) => {
  16162. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  16163. var instance = new InstancedInterleavedBuffer( array, 3 );
  16164. assert.ok( instance.meshPerAttribute === 1, "ok" );
  16165. } );
  16166. // PUBLIC STUFF
  16167. QUnit.test( "isInstancedInterleavedBuffer", ( assert ) => {
  16168. assert.ok( false, "everything's gonna be alright" );
  16169. } );
  16170. QUnit.test( "copy", ( assert ) => {
  16171. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  16172. var instance = new InstancedInterleavedBuffer( array, 3 );
  16173. var copiedInstance = instance.copy( instance );
  16174. assert.ok( copiedInstance.meshPerAttribute === 1, "additional attribute was copied" );
  16175. } );
  16176. } );
  16177. } );
  16178. /**
  16179. * @author simonThiele / https://github.com/simonThiele
  16180. */
  16181. /* global QUnit */
  16182. QUnit.module( 'Core', () => {
  16183. QUnit.module.todo( 'InterleavedBuffer', () => {
  16184. function checkInstanceAgainstCopy( instance, copiedInstance, assert ) {
  16185. assert.ok( copiedInstance instanceof InterleavedBuffer, "the clone has the correct type" );
  16186. for ( var i = 0; i < instance.array.length; i ++ ) {
  16187. assert.ok( copiedInstance.array[ i ] === instance.array[ i ], "array was copied" );
  16188. }
  16189. assert.ok( copiedInstance.stride === instance.stride, "stride was copied" );
  16190. assert.ok( copiedInstance.dynamic === true, "dynamic was copied" );
  16191. }
  16192. // INSTANCING
  16193. QUnit.test( "Instancing", ( assert ) => {
  16194. assert.ok( false, "everything's gonna be alright" );
  16195. } );
  16196. // PROPERTIES
  16197. QUnit.test( "needsUpdate", ( assert ) => {
  16198. var a = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 4 ], 2 ) );
  16199. a.needsUpdate = true;
  16200. assert.strictEqual( a.version, 1, "Check version increased" );
  16201. } );
  16202. // PUBLIC STUFF
  16203. QUnit.test( "isInterleavedBuffer", ( assert ) => {
  16204. assert.ok( false, "everything's gonna be alright" );
  16205. } );
  16206. QUnit.test( "setArray", ( assert ) => {
  16207. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  16208. var f32b = new Float32Array( [] );
  16209. var a = new InterleavedBuffer( f32a, 2, false );
  16210. a.setArray( f32a );
  16211. assert.strictEqual( a.count, 2, "Check item count for non-empty array" );
  16212. assert.strictEqual( a.array, f32a, "Check array itself" );
  16213. a.setArray( f32b );
  16214. assert.strictEqual( a.count, 0, "Check item count for empty array" );
  16215. assert.strictEqual( a.array, f32b, "Check array itself" );
  16216. assert.throws(
  16217. function () {
  16218. a.setArray( [ 1, 2, 3, 4 ] );
  16219. },
  16220. /array should be a Typed Array/,
  16221. "Calling setArray with a non-typed array throws Error"
  16222. );
  16223. } );
  16224. QUnit.test( "setDynamic", ( assert ) => {
  16225. assert.ok( false, "everything's gonna be alright" );
  16226. } );
  16227. QUnit.test( "copy", ( assert ) => {
  16228. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  16229. var instance = new InterleavedBuffer( array, 3 );
  16230. instance.setDynamic( true );
  16231. checkInstanceAgainstCopy( instance, instance.copy( instance ), assert );
  16232. } );
  16233. QUnit.test( "copyAt", ( assert ) => {
  16234. var a = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ), 3 );
  16235. var b = new InterleavedBuffer( new Float32Array( 9 ), 3 );
  16236. var expected = new Float32Array( [ 4, 5, 6, 7, 8, 9, 1, 2, 3 ] );
  16237. b.copyAt( 1, a, 2 );
  16238. b.copyAt( 0, a, 1 );
  16239. b.copyAt( 2, a, 0 );
  16240. assert.deepEqual( b.array, expected, "Check the right values were replaced" );
  16241. } );
  16242. QUnit.test( "set", ( assert ) => {
  16243. var instance = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  16244. instance.set( [ 0, - 1 ] );
  16245. assert.ok( instance.array[ 0 ] === 0 && instance.array[ 1 ] === - 1, "replace at first by default" );
  16246. } );
  16247. QUnit.test( "clone", ( assert ) => {
  16248. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  16249. var instance = new InterleavedBuffer( array, 3 );
  16250. instance.setDynamic( true );
  16251. checkInstanceAgainstCopy( instance, instance.clone(), assert );
  16252. } );
  16253. QUnit.test( "onUpload", ( assert ) => {
  16254. var a = new InterleavedBuffer();
  16255. var func = function () { };
  16256. a.onUpload( func );
  16257. assert.strictEqual( a.onUploadCallback, func, "Check callback was set properly" );
  16258. } );
  16259. // OTHERS
  16260. QUnit.test( "count", ( assert ) => {
  16261. var instance = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  16262. assert.equal( instance.count, 2, "count is calculated via array length / stride" );
  16263. } );
  16264. } );
  16265. } );
  16266. /**
  16267. * @author benaadams / https://twitter.com/ben_a_adams
  16268. */
  16269. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  16270. this.uuid = _Math.generateUUID();
  16271. this.data = interleavedBuffer;
  16272. this.itemSize = itemSize;
  16273. this.offset = offset;
  16274. this.normalized = normalized === true;
  16275. }
  16276. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  16277. count: {
  16278. get: function () {
  16279. return this.data.count;
  16280. }
  16281. },
  16282. array: {
  16283. get: function () {
  16284. return this.data.array;
  16285. }
  16286. }
  16287. } );
  16288. Object.assign( InterleavedBufferAttribute.prototype, {
  16289. isInterleavedBufferAttribute: true,
  16290. setX: function ( index, x ) {
  16291. this.data.array[ index * this.data.stride + this.offset ] = x;
  16292. return this;
  16293. },
  16294. setY: function ( index, y ) {
  16295. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  16296. return this;
  16297. },
  16298. setZ: function ( index, z ) {
  16299. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  16300. return this;
  16301. },
  16302. setW: function ( index, w ) {
  16303. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  16304. return this;
  16305. },
  16306. getX: function ( index ) {
  16307. return this.data.array[ index * this.data.stride + this.offset ];
  16308. },
  16309. getY: function ( index ) {
  16310. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  16311. },
  16312. getZ: function ( index ) {
  16313. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  16314. },
  16315. getW: function ( index ) {
  16316. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  16317. },
  16318. setXY: function ( index, x, y ) {
  16319. index = index * this.data.stride + this.offset;
  16320. this.data.array[ index + 0 ] = x;
  16321. this.data.array[ index + 1 ] = y;
  16322. return this;
  16323. },
  16324. setXYZ: function ( index, x, y, z ) {
  16325. index = index * this.data.stride + this.offset;
  16326. this.data.array[ index + 0 ] = x;
  16327. this.data.array[ index + 1 ] = y;
  16328. this.data.array[ index + 2 ] = z;
  16329. return this;
  16330. },
  16331. setXYZW: function ( index, x, y, z, w ) {
  16332. index = index * this.data.stride + this.offset;
  16333. this.data.array[ index + 0 ] = x;
  16334. this.data.array[ index + 1 ] = y;
  16335. this.data.array[ index + 2 ] = z;
  16336. this.data.array[ index + 3 ] = w;
  16337. return this;
  16338. }
  16339. } );
  16340. /**
  16341. * @author simonThiele / https://github.com/simonThiele
  16342. * @author TristanVALCKE / https://github.com/Itee
  16343. */
  16344. /* global QUnit */
  16345. QUnit.module( 'Core', () => {
  16346. QUnit.module.todo( 'InterleavedBufferAttribute', () => {
  16347. // INSTANCING
  16348. QUnit.test( "Instancing", ( assert ) => {
  16349. assert.ok( false, "everything's gonna be alright" );
  16350. } );
  16351. // PROPERTIES
  16352. QUnit.test( "count", ( assert ) => {
  16353. var buffer = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  16354. var instance = new InterleavedBufferAttribute( buffer, 2, 0 );
  16355. assert.ok( instance.count === 2, "count is calculated via array length / stride" );
  16356. } );
  16357. QUnit.test( "array", ( assert ) => {
  16358. assert.ok( false, "everything's gonna be alright" );
  16359. } );
  16360. // PUBLIC STUFF
  16361. // setY, setZ and setW are calculated in the same way so not QUnit.testing this
  16362. // TODO: ( you can't be sure that will be the case in future, or a mistake was introduce in one off them ! )
  16363. QUnit.test( "setX", ( assert ) => {
  16364. var buffer = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  16365. var instance = new InterleavedBufferAttribute( buffer, 2, 0 );
  16366. instance.setX( 0, 123 );
  16367. instance.setX( 1, 321 );
  16368. assert.ok( instance.data.array[ 0 ] === 123 &&
  16369. instance.data.array[ 3 ] === 321, "x was calculated correct based on index and default offset" );
  16370. var buffer = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  16371. var instance = new InterleavedBufferAttribute( buffer, 2, 1 );
  16372. instance.setX( 0, 123 );
  16373. instance.setX( 1, 321 );
  16374. // the offset was defined as 1, so go one step futher in the array
  16375. assert.ok( instance.data.array[ 1 ] === 123 &&
  16376. instance.data.array[ 4 ] === 321, "x was calculated correct based on index and default offset" );
  16377. } );
  16378. QUnit.test( "setY", ( assert ) => {
  16379. assert.ok( false, "everything's gonna be alright" );
  16380. } );
  16381. QUnit.test( "setZ", ( assert ) => {
  16382. assert.ok( false, "everything's gonna be alright" );
  16383. } );
  16384. QUnit.test( "setW", ( assert ) => {
  16385. assert.ok( false, "everything's gonna be alright" );
  16386. } );
  16387. QUnit.test( "getX", ( assert ) => {
  16388. assert.ok( false, "everything's gonna be alright" );
  16389. } );
  16390. QUnit.test( "getY", ( assert ) => {
  16391. assert.ok( false, "everything's gonna be alright" );
  16392. } );
  16393. QUnit.test( "getZ", ( assert ) => {
  16394. assert.ok( false, "everything's gonna be alright" );
  16395. } );
  16396. QUnit.test( "getW", ( assert ) => {
  16397. assert.ok( false, "everything's gonna be alright" );
  16398. } );
  16399. QUnit.test( "setXY", ( assert ) => {
  16400. assert.ok( false, "everything's gonna be alright" );
  16401. } );
  16402. QUnit.test( "setXYZ", ( assert ) => {
  16403. assert.ok( false, "everything's gonna be alright" );
  16404. } );
  16405. QUnit.test( "setXYZW", ( assert ) => {
  16406. assert.ok( false, "everything's gonna be alright" );
  16407. } );
  16408. } );
  16409. } );
  16410. /**
  16411. * @author moraxy / https://github.com/moraxy
  16412. */
  16413. /* global QUnit */
  16414. QUnit.module( 'Core', () => {
  16415. QUnit.module.todo( 'Layers', () => {
  16416. // INSTANCING
  16417. QUnit.test( "Instancing", ( assert ) => {
  16418. assert.ok( false, "everything's gonna be alright" );
  16419. } );
  16420. // PUBLIC STUFF
  16421. QUnit.test( "set", ( assert ) => {
  16422. var a = new Layers();
  16423. a.set( 0 );
  16424. assert.strictEqual( a.mask, 1, "Set channel 0" );
  16425. a.set( 1 );
  16426. assert.strictEqual( a.mask, 2, "Set channel 1" );
  16427. a.set( 2 );
  16428. assert.strictEqual( a.mask, 4, "Set channel 2" );
  16429. } );
  16430. QUnit.test( "enable", ( assert ) => {
  16431. var a = new Layers();
  16432. a.set( 0 );
  16433. a.enable( 0 );
  16434. assert.strictEqual( a.mask, 1, "Enable channel 0 with mask 0" );
  16435. a.set( 0 );
  16436. a.enable( 1 );
  16437. assert.strictEqual( a.mask, 3, "Enable channel 1 with mask 0" );
  16438. a.set( 1 );
  16439. a.enable( 0 );
  16440. assert.strictEqual( a.mask, 3, "Enable channel 0 with mask 1" );
  16441. a.set( 1 );
  16442. a.enable( 1 );
  16443. assert.strictEqual( a.mask, 2, "Enable channel 1 with mask 1" );
  16444. } );
  16445. QUnit.test( "toggle", ( assert ) => {
  16446. var a = new Layers();
  16447. a.set( 0 );
  16448. a.toggle( 0 );
  16449. assert.strictEqual( a.mask, 0, "Toggle channel 0 with mask 0" );
  16450. a.set( 0 );
  16451. a.toggle( 1 );
  16452. assert.strictEqual( a.mask, 3, "Toggle channel 1 with mask 0" );
  16453. a.set( 1 );
  16454. a.toggle( 0 );
  16455. assert.strictEqual( a.mask, 3, "Toggle channel 0 with mask 1" );
  16456. a.set( 1 );
  16457. a.toggle( 1 );
  16458. assert.strictEqual( a.mask, 0, "Toggle channel 1 with mask 1" );
  16459. } );
  16460. QUnit.test( "disable", ( assert ) => {
  16461. var a = new Layers();
  16462. a.set( 0 );
  16463. a.disable( 0 );
  16464. assert.strictEqual( a.mask, 0, "Disable channel 0 with mask 0" );
  16465. a.set( 0 );
  16466. a.disable( 1 );
  16467. assert.strictEqual( a.mask, 1, "Disable channel 1 with mask 0" );
  16468. a.set( 1 );
  16469. a.disable( 0 );
  16470. assert.strictEqual( a.mask, 2, "Disable channel 0 with mask 1" );
  16471. a.set( 1 );
  16472. a.disable( 1 );
  16473. assert.strictEqual( a.mask, 0, "Disable channel 1 with mask 1" );
  16474. } );
  16475. QUnit.test( "test", ( assert ) => {
  16476. var a = new Layers();
  16477. var b = new Layers();
  16478. assert.ok( a.test( b ), "Start out true" );
  16479. a.set( 1 );
  16480. assert.notOk( a.test( b ), "Set channel 1 in a and fail the QUnit.test" );
  16481. b.toggle( 1 );
  16482. assert.ok( a.test( b ), "Toggle channel 1 in b and pass again" );
  16483. } );
  16484. } );
  16485. } );
  16486. /**
  16487. * @author simonThiele / https://github.com/simonThiele
  16488. * @author TristanVALCKE / https://github.com/Itee
  16489. */
  16490. /* global QUnit */
  16491. QUnit.module( 'Core', () => {
  16492. QUnit.module.todo( 'Object3D', () => {
  16493. var RadToDeg = 180 / Math.PI;
  16494. var eulerEquals = function ( a, b, tolerance ) {
  16495. tolerance = tolerance || 0.0001;
  16496. if ( a.order != b.order ) {
  16497. return false;
  16498. }
  16499. return (
  16500. Math.abs( a.x - b.x ) <= tolerance &&
  16501. Math.abs( a.y - b.y ) <= tolerance &&
  16502. Math.abs( a.z - b.z ) <= tolerance
  16503. );
  16504. };
  16505. // INHERITANCE
  16506. QUnit.test( "Extending", ( assert ) => {
  16507. assert.ok( false, "everything's gonna be alright" );
  16508. } );
  16509. // INSTANCING
  16510. QUnit.test( "Instancing", ( assert ) => {
  16511. assert.ok( false, "everything's gonna be alright" );
  16512. } );
  16513. // STATIC STUFF
  16514. QUnit.test( "DefaultUp", ( assert ) => {
  16515. assert.ok( false, "everything's gonna be alright" );
  16516. } );
  16517. QUnit.test( "DefaultMatrixAutoUpdate", ( assert ) => {
  16518. assert.ok( false, "everything's gonna be alright" );
  16519. } );
  16520. // PUBLIC STUFF
  16521. QUnit.test( "isObject3D", ( assert ) => {
  16522. assert.ok( false, "everything's gonna be alright" );
  16523. } );
  16524. QUnit.test( "onBeforeRender", ( assert ) => {
  16525. assert.ok( false, "everything's gonna be alright" );
  16526. } );
  16527. QUnit.test( "onAfterRender", ( assert ) => {
  16528. assert.ok( false, "everything's gonna be alright" );
  16529. } );
  16530. QUnit.test( "applyMatrix", ( assert ) => {
  16531. var a = new Object3D();
  16532. var m = new Matrix4();
  16533. var expectedPos = new Vector3( x, y, z );
  16534. var expectedQuat = new Quaternion( 0.5 * Math.sqrt( 2 ), 0, 0, 0.5 * Math.sqrt( 2 ) );
  16535. m.makeRotationX( Math.PI / 2 );
  16536. m.setPosition( new Vector3( x, y, z ) );
  16537. a.applyMatrix( m );
  16538. assert.deepEqual( a.position, expectedPos, "Position has the expected values" );
  16539. assert.ok(
  16540. Math.abs( a.quaternion.x - expectedQuat.x ) <= eps &&
  16541. Math.abs( a.quaternion.y - expectedQuat.y ) <= eps &&
  16542. Math.abs( a.quaternion.z - expectedQuat.z ) <= eps,
  16543. "Quaternion has the expected values"
  16544. );
  16545. } );
  16546. QUnit.test( "applyQuaternion", ( assert ) => {
  16547. var a = new Object3D();
  16548. var sqrt = 0.5 * Math.sqrt( 2 );
  16549. var quat = new Quaternion( 0, sqrt, 0, sqrt );
  16550. var expected = new Quaternion( sqrt / 2, sqrt / 2, 0, 0 );
  16551. a.quaternion.set( 0.25, 0.25, 0.25, 0.25 );
  16552. a.applyQuaternion( quat );
  16553. assert.ok(
  16554. Math.abs( a.quaternion.x - expected.x ) <= eps &&
  16555. Math.abs( a.quaternion.y - expected.y ) <= eps &&
  16556. Math.abs( a.quaternion.z - expected.z ) <= eps,
  16557. "Quaternion has the expected values"
  16558. );
  16559. } );
  16560. QUnit.test( "setRotationFromAxisAngle", ( assert ) => {
  16561. var a = new Object3D();
  16562. var axis = new Vector3( 0, 1, 0 );
  16563. var angle = Math.PI;
  16564. var expected = new Euler( - Math.PI, 0, - Math.PI );
  16565. a.setRotationFromAxisAngle( axis, angle );
  16566. assert.ok( eulerEquals( a.getWorldRotation(), expected ), "Correct values after rotation" );
  16567. axis.set( 1, 0, 0 );
  16568. var angle = 0;
  16569. expected.set( 0, 0, 0 );
  16570. a.setRotationFromAxisAngle( axis, angle );
  16571. assert.ok( eulerEquals( a.getWorldRotation(), expected ), "Correct values after zeroing" );
  16572. } );
  16573. QUnit.test( "setRotationFromEuler", ( assert ) => {
  16574. var a = new Object3D();
  16575. var rotation = new Euler( ( 45 / RadToDeg ), 0, Math.PI );
  16576. var expected = rotation.clone(); // bit obvious
  16577. a.setRotationFromEuler( rotation );
  16578. assert.ok( eulerEquals( a.getWorldRotation(), expected ), "Correct values after rotation" );
  16579. } );
  16580. QUnit.test( "setRotationFromMatrix", ( assert ) => {
  16581. var a = new Object3D();
  16582. var m = new Matrix4();
  16583. var eye = new Vector3( 0, 0, 0 );
  16584. var target = new Vector3( 0, 1, - 1 );
  16585. var up = new Vector3( 0, 1, 0 );
  16586. m.lookAt( eye, target, up );
  16587. a.setRotationFromMatrix( m );
  16588. assert.numEqual( a.getWorldRotation().x * RadToDeg, 45, "Correct rotation angle" );
  16589. } );
  16590. QUnit.test( "setRotationFromQuaternion", ( assert ) => {
  16591. var a = new Object3D();
  16592. var rotation = new Quaternion().setFromEuler( new Euler( Math.PI, 0, - Math.PI ) );
  16593. var expected = new Euler( Math.PI, 0, - Math.PI );
  16594. a.setRotationFromQuaternion( rotation );
  16595. assert.ok( eulerEquals( a.getWorldRotation(), expected ), "Correct values after rotation" );
  16596. } );
  16597. QUnit.test( "rotateOnAxis", ( assert ) => {
  16598. assert.ok( false, "everything's gonna be alright" );
  16599. } );
  16600. QUnit.test( "rotateOnWorldAxis", ( assert ) => {
  16601. assert.ok( false, "everything's gonna be alright" );
  16602. } );
  16603. QUnit.test( "rotateX", ( assert ) => {
  16604. var obj = new Object3D();
  16605. var angleInRad = 1.562;
  16606. obj.rotateX( angleInRad );
  16607. assert.numEqual( obj.rotation.x, angleInRad, "x is equal" );
  16608. } );
  16609. QUnit.test( "rotateY", ( assert ) => {
  16610. var obj = new Object3D();
  16611. var angleInRad = - 0.346;
  16612. obj.rotateY( angleInRad );
  16613. assert.numEqual( obj.rotation.y, angleInRad, "y is equal" );
  16614. } );
  16615. QUnit.test( "rotateZ", ( assert ) => {
  16616. var obj = new Object3D();
  16617. var angleInRad = 1;
  16618. obj.rotateZ( angleInRad );
  16619. assert.numEqual( obj.rotation.z, angleInRad, "z is equal" );
  16620. } );
  16621. QUnit.test( "translateOnAxis", ( assert ) => {
  16622. var obj = new Object3D();
  16623. obj.translateOnAxis( new Vector3( 1, 0, 0 ), 1 );
  16624. obj.translateOnAxis( new Vector3( 0, 1, 0 ), 1.23 );
  16625. obj.translateOnAxis( new Vector3( 0, 0, 1 ), - 4.56 );
  16626. assert.propEqual( obj.position, {
  16627. x: 1,
  16628. y: 1.23,
  16629. z: - 4.56
  16630. } );
  16631. } );
  16632. QUnit.test( "translateX", ( assert ) => {
  16633. var obj = new Object3D();
  16634. obj.translateX( 1.234 );
  16635. assert.numEqual( obj.position.x, 1.234, "x is equal" );
  16636. } );
  16637. QUnit.test( "translateY", ( assert ) => {
  16638. var obj = new Object3D();
  16639. obj.translateY( 1.234 );
  16640. assert.numEqual( obj.position.y, 1.234, "y is equal" );
  16641. } );
  16642. QUnit.test( "translateZ", ( assert ) => {
  16643. var obj = new Object3D();
  16644. obj.translateZ( 1.234 );
  16645. assert.numEqual( obj.position.z, 1.234, "z is equal" );
  16646. } );
  16647. QUnit.test( "localToWorld", ( assert ) => {
  16648. assert.ok( false, "everything's gonna be alright" );
  16649. } );
  16650. QUnit.test( "worldToLocal", ( assert ) => {
  16651. assert.ok( false, "everything's gonna be alright" );
  16652. } );
  16653. QUnit.test( "lookAt", ( assert ) => {
  16654. var obj = new Object3D();
  16655. obj.lookAt( new Vector3( 0, - 1, 1 ) );
  16656. assert.numEqual( obj.rotation.x * RadToDeg, 45, "x is equal" );
  16657. } );
  16658. QUnit.test( "add/remove", ( assert ) => {
  16659. var a = new Object3D();
  16660. var child1 = new Object3D();
  16661. var child2 = new Object3D();
  16662. assert.strictEqual( a.children.length, 0, "Starts with no children" );
  16663. a.add( child1 );
  16664. assert.strictEqual( a.children.length, 1, "The first child was added" );
  16665. assert.strictEqual( a.children[ 0 ], child1, "It's the right one" );
  16666. a.add( child2 );
  16667. assert.strictEqual( a.children.length, 2, "The second child was added" );
  16668. assert.strictEqual( a.children[ 1 ], child2, "It's the right one" );
  16669. assert.strictEqual( a.children[ 0 ], child1, "The first one is still there" );
  16670. a.remove( child1 );
  16671. assert.strictEqual( a.children.length, 1, "The first child was removed" );
  16672. assert.strictEqual( a.children[ 0 ], child2, "The second one is still there" );
  16673. a.add( child1 );
  16674. a.remove( child1, child2 );
  16675. assert.strictEqual( a.children.length, 0, "Both children were removed at once" );
  16676. child1.add( child2 );
  16677. assert.strictEqual( child1.children.length, 1, "The second child was added to the first one" );
  16678. a.add( child2 );
  16679. assert.strictEqual( a.children.length, 1, "The second one was added to the parent (no remove)" );
  16680. assert.strictEqual( a.children[ 0 ], child2, "The second one is now the parent's child again" );
  16681. assert.strictEqual( child1.children.length, 0, "The first one no longer has any children" );
  16682. } );
  16683. QUnit.test( "getObjectById/getObjectByName/getObjectByProperty", ( assert ) => {
  16684. var parent = new Object3D();
  16685. var childName = new Object3D();
  16686. var childId = new Object3D(); // id = parent.id + 2
  16687. var childNothing = new Object3D();
  16688. parent.prop = true;
  16689. childName.name = "foo";
  16690. parent.add( childName, childId, childNothing );
  16691. assert.strictEqual( parent.getObjectByProperty( 'prop', true ), parent, "Get parent by its own property" );
  16692. assert.strictEqual( parent.getObjectByName( "foo" ), childName, "Get child by name" );
  16693. assert.strictEqual( parent.getObjectById( parent.id + 2 ), childId, "Get child by Id" );
  16694. assert.strictEqual(
  16695. parent.getObjectByProperty( 'no-property', 'no-value' ), undefined,
  16696. "Unknown property results in undefined"
  16697. );
  16698. } );
  16699. QUnit.test( "getWorldPosition", ( assert ) => {
  16700. var a = new Object3D();
  16701. var b = new Object3D();
  16702. var expectedSingle = new Vector3( x, y, z );
  16703. var expectedParent = new Vector3( x, y, 0 );
  16704. var expectedChild = new Vector3( x, y, 7 + ( z - z ) );
  16705. a.translateX( x );
  16706. a.translateY( y );
  16707. a.translateZ( z );
  16708. assert.deepEqual(
  16709. a.getWorldPosition(), expectedSingle,
  16710. "WorldPosition as expected for single object"
  16711. );
  16712. // translate child and then parent
  16713. b.translateZ( 7 );
  16714. a.add( b );
  16715. a.translateZ( - z );
  16716. assert.deepEqual( a.getWorldPosition(), expectedParent, "WorldPosition as expected for parent" );
  16717. assert.deepEqual( b.getWorldPosition(), expectedChild, "WorldPosition as expected for child" );
  16718. } );
  16719. QUnit.test( "getWorldQuaternion", ( assert ) => {
  16720. assert.ok( false, "everything's gonna be alright" );
  16721. } );
  16722. QUnit.test( "getWorldRotation", ( assert ) => {
  16723. var obj = new Object3D();
  16724. obj.lookAt( new Vector3( 0, - 1, 1 ) );
  16725. assert.numEqual( obj.getWorldRotation().x * RadToDeg, 45, "x is equal" );
  16726. obj.lookAt( new Vector3( 1, 0, 0 ) );
  16727. assert.numEqual( obj.getWorldRotation().y * RadToDeg, 90, "y is equal" );
  16728. } );
  16729. QUnit.test( "getWorldScale", ( assert ) => {
  16730. var a = new Object3D();
  16731. var m = new Matrix4().makeScale( x, y, z );
  16732. var expected = new Vector3( x, y, z );
  16733. a.applyMatrix( m );
  16734. assert.deepEqual( a.getWorldScale(), expected, "WorldScale as expected" );
  16735. } );
  16736. QUnit.test( "getWorldDirection", ( assert ) => {
  16737. var a = new Object3D();
  16738. var expected = new Vector3( 0, - 0.5 * Math.sqrt( 2 ), 0.5 * Math.sqrt( 2 ) );
  16739. var dir;
  16740. a.lookAt( new Vector3( 0, - 1, 1 ) );
  16741. dir = a.getWorldDirection();
  16742. assert.ok(
  16743. Math.abs( dir.x - expected.x ) <= eps &&
  16744. Math.abs( dir.y - expected.y ) <= eps &&
  16745. Math.abs( dir.z - expected.z ) <= eps,
  16746. "Direction has the expected values"
  16747. );
  16748. } );
  16749. QUnit.test( "raycast", ( assert ) => {
  16750. assert.ok( false, "everything's gonna be alright" );
  16751. } );
  16752. QUnit.test( "traverse/traverseVisible/traverseAncestors", ( assert ) => {
  16753. var a = new Object3D();
  16754. var b = new Object3D();
  16755. var c = new Object3D();
  16756. var d = new Object3D();
  16757. var names = [];
  16758. var expectedNormal = [ "parent", "child", "childchild 1", "childchild 2" ];
  16759. var expectedVisible = [ "parent", "child", "childchild 2" ];
  16760. var expectedAncestors = [ "child", "parent" ];
  16761. a.name = "parent";
  16762. b.name = "child";
  16763. c.name = "childchild 1";
  16764. c.visible = false;
  16765. d.name = "childchild 2";
  16766. b.add( c );
  16767. b.add( d );
  16768. a.add( b );
  16769. a.traverse( function ( obj ) {
  16770. names.push( obj.name );
  16771. } );
  16772. assert.deepEqual( names, expectedNormal, "Traversed objects in expected order" );
  16773. var names = [];
  16774. a.traverseVisible( function ( obj ) {
  16775. names.push( obj.name );
  16776. } );
  16777. assert.deepEqual( names, expectedVisible, "Traversed visible objects in expected order" );
  16778. var names = [];
  16779. c.traverseAncestors( function ( obj ) {
  16780. names.push( obj.name );
  16781. } );
  16782. assert.deepEqual( names, expectedAncestors, "Traversed ancestors in expected order" );
  16783. } );
  16784. QUnit.test( "updateMatrix", ( assert ) => {
  16785. assert.ok( false, "everything's gonna be alright" );
  16786. } );
  16787. QUnit.test( "updateMatrixWorld", ( assert ) => {
  16788. assert.ok( false, "everything's gonna be alright" );
  16789. } );
  16790. QUnit.test( "toJSON", ( assert ) => {
  16791. var a = new Object3D();
  16792. var child = new Object3D();
  16793. var childChild = new Object3D();
  16794. a.name = "a's name";
  16795. a.matrix.set( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 );
  16796. a.visible = false;
  16797. a.castShadow = true;
  16798. a.receiveShadow = true;
  16799. a.userData[ "foo" ] = "bar";
  16800. child.uuid = "5D4E9AE8-DA61-4912-A575-71A5BE3D72CD";
  16801. childChild.uuid = "B43854B3-E970-4E85-BD41-AAF8D7BFA189";
  16802. child.add( childChild );
  16803. a.add( child );
  16804. var gold = {
  16805. "metadata": {
  16806. "version": 4.5,
  16807. "type": "Object",
  16808. "generator": "Object3D.toJSON"
  16809. },
  16810. "object": {
  16811. "uuid": "0A1E4F43-CB5B-4097-8F82-DC2969C0B8C2",
  16812. "type": "Object3D",
  16813. "name": "a's name",
  16814. "castShadow": true,
  16815. "receiveShadow": true,
  16816. "visible": false,
  16817. "userData": { "foo": "bar" },
  16818. "matrix": [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ],
  16819. "children": [
  16820. {
  16821. "uuid": "5D4E9AE8-DA61-4912-A575-71A5BE3D72CD",
  16822. "type": "Object3D",
  16823. "matrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  16824. "children": [
  16825. {
  16826. "uuid": "B43854B3-E970-4E85-BD41-AAF8D7BFA189",
  16827. "type": "Object3D",
  16828. "matrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
  16829. }
  16830. ]
  16831. }
  16832. ]
  16833. }
  16834. };
  16835. // hacks
  16836. var out = a.toJSON();
  16837. out.object.uuid = "0A1E4F43-CB5B-4097-8F82-DC2969C0B8C2";
  16838. assert.deepEqual( out, gold, "JSON is as expected" );
  16839. } );
  16840. QUnit.test( "clone", ( assert ) => {
  16841. var a;
  16842. var b = new Object3D();
  16843. assert.strictEqual( a, undefined, "Undefined pre-clone()" );
  16844. a = b.clone();
  16845. assert.notStrictEqual( a, b, "Defined but seperate instances post-clone()" );
  16846. a.uuid = b.uuid;
  16847. assert.deepEqual( a, b, "But identical properties" );
  16848. } );
  16849. QUnit.test( "copy", ( assert ) => {
  16850. var a = new Object3D();
  16851. var b = new Object3D();
  16852. var child = new Object3D();
  16853. var childChild = new Object3D();
  16854. a.name = "original";
  16855. b.name = "to-be-copied";
  16856. b.position.set( x, y, z );
  16857. b.quaternion.set( x, y, z, w );
  16858. b.scale.set( 2, 3, 4 );
  16859. // bogus QUnit.test values
  16860. b.matrix.set( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 );
  16861. b.matrixWorld.set( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 );
  16862. b.matrixAutoUpdate = false;
  16863. b.matrixWorldNeedsUpdate = true;
  16864. b.layers.mask = 2;
  16865. b.visible = false;
  16866. b.castShadow = true;
  16867. b.receiveShadow = true;
  16868. b.frustumCulled = false;
  16869. b.renderOrder = 1;
  16870. b.userData[ "foo" ] = "bar";
  16871. child.add( childChild );
  16872. b.add( child );
  16873. assert.notDeepEqual( a, b, "Objects are not equal pre-copy()" );
  16874. a.copy( b, true );
  16875. // check they're all unique instances
  16876. assert.ok(
  16877. a.uuid !== b.uuid &&
  16878. a.children[ 0 ].uuid !== b.children[ 0 ].uuid &&
  16879. a.children[ 0 ].children[ 0 ].uuid !== b.children[ 0 ].children[ 0 ].uuid,
  16880. "UUIDs are all different"
  16881. );
  16882. // and now fix that
  16883. a.uuid = b.uuid;
  16884. a.children[ 0 ].uuid = b.children[ 0 ].uuid;
  16885. a.children[ 0 ].children[ 0 ].uuid = b.children[ 0 ].children[ 0 ].uuid;
  16886. assert.deepEqual( a, b, "Objects are equal post-copy()" );
  16887. } );
  16888. } );
  16889. } );
  16890. /**
  16891. * @author mrdoob / http://mrdoob.com/
  16892. * @author bhouston / http://clara.io/
  16893. * @author stephomi / http://stephaneginier.com/
  16894. */
  16895. function Raycaster( origin, direction, near, far ) {
  16896. this.ray = new Ray( origin, direction );
  16897. // direction is assumed to be normalized (for accurate distance calculations)
  16898. this.near = near || 0;
  16899. this.far = far || Infinity;
  16900. this.params = {
  16901. Mesh: {},
  16902. Line: {},
  16903. LOD: {},
  16904. Points: { threshold: 1 },
  16905. Sprite: {}
  16906. };
  16907. Object.defineProperties( this.params, {
  16908. PointCloud: {
  16909. get: function () {
  16910. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  16911. return this.Points;
  16912. }
  16913. }
  16914. } );
  16915. }
  16916. function ascSort( a, b ) {
  16917. return a.distance - b.distance;
  16918. }
  16919. function intersectObject( object, raycaster, intersects, recursive ) {
  16920. if ( object.visible === false ) return;
  16921. object.raycast( raycaster, intersects );
  16922. if ( recursive === true ) {
  16923. var children = object.children;
  16924. for ( var i = 0, l = children.length; i < l; i ++ ) {
  16925. intersectObject( children[ i ], raycaster, intersects, true );
  16926. }
  16927. }
  16928. }
  16929. Object.assign( Raycaster.prototype, {
  16930. linePrecision: 1,
  16931. set: function ( origin, direction ) {
  16932. // direction is assumed to be normalized (for accurate distance calculations)
  16933. this.ray.set( origin, direction );
  16934. },
  16935. setFromCamera: function ( coords, camera ) {
  16936. if ( ( camera && camera.isPerspectiveCamera ) ) {
  16937. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  16938. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  16939. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  16940. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  16941. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  16942. } else {
  16943. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  16944. }
  16945. },
  16946. intersectObject: function ( object, recursive ) {
  16947. var intersects = [];
  16948. intersectObject( object, this, intersects, recursive );
  16949. intersects.sort( ascSort );
  16950. return intersects;
  16951. },
  16952. intersectObjects: function ( objects, recursive ) {
  16953. var intersects = [];
  16954. if ( Array.isArray( objects ) === false ) {
  16955. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  16956. return intersects;
  16957. }
  16958. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  16959. intersectObject( objects[ i ], this, intersects, recursive );
  16960. }
  16961. intersects.sort( ascSort );
  16962. return intersects;
  16963. }
  16964. } );
  16965. /**
  16966. * @author mrdoob / http://mrdoob.com/
  16967. * @author benaadams / https://twitter.com/ben_a_adams
  16968. * @author Mugen87 / https://github.com/Mugen87
  16969. */
  16970. // SphereGeometry
  16971. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16972. Geometry.call( this );
  16973. this.type = 'SphereGeometry';
  16974. this.parameters = {
  16975. radius: radius,
  16976. widthSegments: widthSegments,
  16977. heightSegments: heightSegments,
  16978. phiStart: phiStart,
  16979. phiLength: phiLength,
  16980. thetaStart: thetaStart,
  16981. thetaLength: thetaLength
  16982. };
  16983. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  16984. this.mergeVertices();
  16985. }
  16986. SphereGeometry.prototype = Object.create( Geometry.prototype );
  16987. SphereGeometry.prototype.constructor = SphereGeometry;
  16988. // SphereBufferGeometry
  16989. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16990. BufferGeometry.call( this );
  16991. this.type = 'SphereBufferGeometry';
  16992. this.parameters = {
  16993. radius: radius,
  16994. widthSegments: widthSegments,
  16995. heightSegments: heightSegments,
  16996. phiStart: phiStart,
  16997. phiLength: phiLength,
  16998. thetaStart: thetaStart,
  16999. thetaLength: thetaLength
  17000. };
  17001. radius = radius || 1;
  17002. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  17003. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  17004. phiStart = phiStart !== undefined ? phiStart : 0;
  17005. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  17006. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17007. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  17008. var thetaEnd = thetaStart + thetaLength;
  17009. var ix, iy;
  17010. var index = 0;
  17011. var grid = [];
  17012. var vertex = new Vector3();
  17013. var normal = new Vector3();
  17014. // buffers
  17015. var indices = [];
  17016. var vertices = [];
  17017. var normals = [];
  17018. var uvs = [];
  17019. // generate vertices, normals and uvs
  17020. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  17021. var verticesRow = [];
  17022. var v = iy / heightSegments;
  17023. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  17024. var u = ix / widthSegments;
  17025. // vertex
  17026. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  17027. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  17028. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  17029. vertices.push( vertex.x, vertex.y, vertex.z );
  17030. // normal
  17031. normal.set( vertex.x, vertex.y, vertex.z ).normalize();
  17032. normals.push( normal.x, normal.y, normal.z );
  17033. // uv
  17034. uvs.push( u, 1 - v );
  17035. verticesRow.push( index ++ );
  17036. }
  17037. grid.push( verticesRow );
  17038. }
  17039. // indices
  17040. for ( iy = 0; iy < heightSegments; iy ++ ) {
  17041. for ( ix = 0; ix < widthSegments; ix ++ ) {
  17042. var a = grid[ iy ][ ix + 1 ];
  17043. var b = grid[ iy ][ ix ];
  17044. var c = grid[ iy + 1 ][ ix ];
  17045. var d = grid[ iy + 1 ][ ix + 1 ];
  17046. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  17047. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  17048. }
  17049. }
  17050. // build geometry
  17051. this.setIndex( indices );
  17052. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17053. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17054. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17055. }
  17056. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17057. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  17058. /**
  17059. * @author simonThiele / https://github.com/simonThiele
  17060. */
  17061. /* global QUnit */
  17062. function checkRayDirectionAgainstReferenceVector( rayDirection, refVector, assert ) {
  17063. assert.ok( refVector.x - rayDirection.x <= Number.EPSILON && refVector.y - rayDirection.y <= Number.EPSILON && refVector.z - rayDirection.z <= Number.EPSILON, "camera is pointing to" +
  17064. " the same direction as expected" );
  17065. }
  17066. function getRaycaster() {
  17067. return new Raycaster(
  17068. new Vector3( 0, 0, 0 ),
  17069. new Vector3( 0, 0, - 1 ),
  17070. 1,
  17071. 100
  17072. );
  17073. }
  17074. function getObjectsToCheck() {
  17075. var objects = [];
  17076. var sphere1 = getSphere();
  17077. sphere1.position.set( 0, 0, - 10 );
  17078. sphere1.name = 1;
  17079. objects.push( sphere1 );
  17080. var sphere11 = getSphere();
  17081. sphere11.position.set( 0, 0, 1 );
  17082. sphere11.name = 11;
  17083. sphere1.add( sphere11 );
  17084. var sphere12 = getSphere();
  17085. sphere12.position.set( 0, 0, - 1 );
  17086. sphere12.name = 12;
  17087. sphere1.add( sphere12 );
  17088. var sphere2 = getSphere();
  17089. sphere2.position.set( - 5, 0, - 5 );
  17090. sphere2.name = 2;
  17091. objects.push( sphere2 );
  17092. for ( var i = 0; i < objects.length; i ++ ) {
  17093. objects[ i ].updateMatrixWorld();
  17094. }
  17095. return objects;
  17096. }
  17097. function getSphere() {
  17098. return new Mesh( new SphereGeometry( 1, 100, 100 ) );
  17099. }
  17100. QUnit.module( 'Core', () => {
  17101. QUnit.module.todo( 'Raycaster', () => {
  17102. // INSTANCING
  17103. QUnit.test( "Instancing", ( assert ) => {
  17104. assert.ok( false, "everything's gonna be alright" );
  17105. } );
  17106. // PUBLIC STUFF
  17107. QUnit.test( "linePrecision", ( assert ) => {
  17108. assert.ok( false, "everything's gonna be alright" );
  17109. } );
  17110. QUnit.test( "set", ( assert ) => {
  17111. var origin = new Vector3( 0, 0, 0 );
  17112. var direction = new Vector3( 0, 0, - 1 );
  17113. var a = new Raycaster( origin.clone(), direction.clone() );
  17114. assert.deepEqual( a.ray.origin, origin, "Origin is correct" );
  17115. assert.deepEqual( a.ray.direction, direction, "Direction is correct" );
  17116. origin.set( 1, 1, 1 );
  17117. direction.set( - 1, 0, 0 );
  17118. a.set( origin, direction );
  17119. assert.deepEqual( a.ray.origin, origin, "Origin was set correctly" );
  17120. assert.deepEqual( a.ray.direction, direction, "Direction was set correctly" );
  17121. } );
  17122. QUnit.test( "setFromCamera (Perspective)", ( assert ) => {
  17123. var raycaster = new Raycaster();
  17124. var rayDirection = raycaster.ray.direction;
  17125. var camera = new PerspectiveCamera( 90, 1, 1, 1000 );
  17126. raycaster.setFromCamera( {
  17127. x: 0,
  17128. y: 0
  17129. }, camera );
  17130. assert.ok( rayDirection.x === 0, rayDirection.y === 0, rayDirection.z === - 1,
  17131. "camera is looking straight to -z and so does the ray in the middle of the screen" );
  17132. var step = 0.1;
  17133. for ( var x = - 1; x <= 1; x += step ) {
  17134. for ( var y = - 1; y <= 1; y += step ) {
  17135. raycaster.setFromCamera( {
  17136. x,
  17137. y
  17138. }, camera );
  17139. var refVector = new Vector3( x, y, - 1 ).normalize();
  17140. checkRayDirectionAgainstReferenceVector( rayDirection, refVector, assert );
  17141. }
  17142. }
  17143. } );
  17144. QUnit.test( "setFromCamera (Orthographic)", ( assert ) => {
  17145. var raycaster = new Raycaster();
  17146. var rayOrigin = raycaster.ray.origin;
  17147. var rayDirection = raycaster.ray.direction;
  17148. var camera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1000 );
  17149. var expectedOrigin = new Vector3( 0, 0, 0 );
  17150. var expectedDirection = new Vector3( 0, 0, - 1 );
  17151. raycaster.setFromCamera( {
  17152. x: 0,
  17153. y: 0
  17154. }, camera );
  17155. assert.deepEqual( rayOrigin, expectedOrigin, "Ray origin has the right coordinates" );
  17156. assert.deepEqual( rayDirection, expectedDirection, "Camera and Ray are pointing towards -z" );
  17157. } );
  17158. QUnit.test( "intersectObject", ( assert ) => {
  17159. var raycaster = getRaycaster();
  17160. var objectsToCheck = getObjectsToCheck();
  17161. assert.ok( raycaster.intersectObject( objectsToCheck[ 0 ] ).length === 1,
  17162. "no recursive search should lead to one hit" );
  17163. assert.ok( raycaster.intersectObject( objectsToCheck[ 0 ], true ).length === 3,
  17164. "recursive search should lead to three hits" );
  17165. var intersections = raycaster.intersectObject( objectsToCheck[ 0 ], true );
  17166. for ( var i = 0; i < intersections.length - 1; i ++ ) {
  17167. assert.ok( intersections[ i ].distance <= intersections[ i + 1 ].distance, "intersections are sorted" );
  17168. }
  17169. } );
  17170. QUnit.test( "intersectObjects", ( assert ) => {
  17171. var raycaster = getRaycaster();
  17172. var objectsToCheck = getObjectsToCheck();
  17173. assert.ok( raycaster.intersectObjects( objectsToCheck ).length === 1,
  17174. "no recursive search should lead to one hit" );
  17175. assert.ok( raycaster.intersectObjects( objectsToCheck, true ).length === 3,
  17176. "recursive search should lead to three hits" );
  17177. var intersections = raycaster.intersectObjects( objectsToCheck, true );
  17178. for ( var i = 0; i < intersections.length - 1; i ++ ) {
  17179. assert.ok( intersections[ i ].distance <= intersections[ i + 1 ].distance, "intersections are sorted" );
  17180. }
  17181. } );
  17182. } );
  17183. } );
  17184. /**
  17185. * @author mrdoob / http://mrdoob.com/
  17186. */
  17187. function Uniform( value ) {
  17188. if ( typeof value === 'string' ) {
  17189. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  17190. value = arguments[ 1 ];
  17191. }
  17192. this.value = value;
  17193. }
  17194. Uniform.prototype.clone = function () {
  17195. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  17196. };
  17197. /**
  17198. * @author moraxy / https://github.com/moraxy
  17199. */
  17200. /* global QUnit */
  17201. QUnit.module( 'Core', () => {
  17202. QUnit.module.todo( 'Uniform', () => {
  17203. // INSTANCING
  17204. QUnit.test( "Instancing", ( assert ) => {
  17205. var a;
  17206. var b = new Vector3( x, y, z );
  17207. a = new Uniform( 5 );
  17208. assert.strictEqual( a.value, 5, "New constructor works with simple values" );
  17209. a = new Uniform( b );
  17210. assert.ok( a.value.equals( b ), "New constructor works with complex values" );
  17211. } );
  17212. // PUBLIC STUFF
  17213. QUnit.test( "clone", ( assert ) => {
  17214. var a = new Uniform( 23 );
  17215. var b = a.clone();
  17216. assert.strictEqual( b.value, a.value, "clone() with simple values works" );
  17217. var a = new Uniform( new Vector3( 1, 2, 3 ) );
  17218. var b = a.clone();
  17219. assert.ok( b.value.equals( a.value ), "clone() with complex values works" );
  17220. } );
  17221. } );
  17222. } );
  17223. /**
  17224. * @author mrdoob / http://mrdoob.com/
  17225. */
  17226. function Group() {
  17227. Object3D.call( this );
  17228. this.type = 'Group';
  17229. }
  17230. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  17231. constructor: Group
  17232. } );
  17233. /**
  17234. * @author TristanVALCKE / https://github.com/Itee
  17235. */
  17236. /* global QUnit */
  17237. QUnit.module.todo( 'Extras', () => {
  17238. QUnit.module.todo( 'SceneUtils', () => {
  17239. // PUBLIC STUFF
  17240. QUnit.test( "createMultiMaterialObject", ( assert ) => {
  17241. assert.ok( false, "everything's gonna be alright" );
  17242. } );
  17243. QUnit.test( "detach", ( assert ) => {
  17244. assert.ok( false, "everything's gonna be alright" );
  17245. } );
  17246. QUnit.test( "attach", ( assert ) => {
  17247. assert.ok( false, "everything's gonna be alright" );
  17248. } );
  17249. } );
  17250. } );
  17251. /**
  17252. * @author zz85 / http://www.lab4games.net/zz85/blog
  17253. */
  17254. var ShapeUtils = {
  17255. // calculate area of the contour polygon
  17256. area: function ( contour ) {
  17257. var n = contour.length;
  17258. var a = 0.0;
  17259. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17260. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17261. }
  17262. return a * 0.5;
  17263. },
  17264. triangulate: ( function () {
  17265. /**
  17266. * This code is a quick port of code written in C++ which was submitted to
  17267. * flipcode.com by John W. Ratcliff // July 22, 2000
  17268. * See original code and more information here:
  17269. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  17270. *
  17271. * ported to actionscript by Zevan Rosser
  17272. * www.actionsnippet.com
  17273. *
  17274. * ported to javascript by Joshua Koo
  17275. * http://www.lab4games.net/zz85/blog
  17276. *
  17277. */
  17278. function snip( contour, u, v, w, n, verts ) {
  17279. var p;
  17280. var ax, ay, bx, by;
  17281. var cx, cy, px, py;
  17282. ax = contour[ verts[ u ] ].x;
  17283. ay = contour[ verts[ u ] ].y;
  17284. bx = contour[ verts[ v ] ].x;
  17285. by = contour[ verts[ v ] ].y;
  17286. cx = contour[ verts[ w ] ].x;
  17287. cy = contour[ verts[ w ] ].y;
  17288. if ( ( bx - ax ) * ( cy - ay ) - ( by - ay ) * ( cx - ax ) <= 0 ) return false;
  17289. var aX, aY, bX, bY, cX, cY;
  17290. var apx, apy, bpx, bpy, cpx, cpy;
  17291. var cCROSSap, bCROSScp, aCROSSbp;
  17292. aX = cx - bx; aY = cy - by;
  17293. bX = ax - cx; bY = ay - cy;
  17294. cX = bx - ax; cY = by - ay;
  17295. for ( p = 0; p < n; p ++ ) {
  17296. px = contour[ verts[ p ] ].x;
  17297. py = contour[ verts[ p ] ].y;
  17298. if ( ( ( px === ax ) && ( py === ay ) ) ||
  17299. ( ( px === bx ) && ( py === by ) ) ||
  17300. ( ( px === cx ) && ( py === cy ) ) ) continue;
  17301. apx = px - ax; apy = py - ay;
  17302. bpx = px - bx; bpy = py - by;
  17303. cpx = px - cx; cpy = py - cy;
  17304. // see if p is inside triangle abc
  17305. aCROSSbp = aX * bpy - aY * bpx;
  17306. cCROSSap = cX * apy - cY * apx;
  17307. bCROSScp = bX * cpy - bY * cpx;
  17308. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  17309. }
  17310. return true;
  17311. }
  17312. // takes in an contour array and returns
  17313. return function triangulate( contour, indices ) {
  17314. var n = contour.length;
  17315. if ( n < 3 ) return null;
  17316. var result = [],
  17317. verts = [],
  17318. vertIndices = [];
  17319. /* we want a counter-clockwise polygon in verts */
  17320. var u, v, w;
  17321. if ( ShapeUtils.area( contour ) > 0.0 ) {
  17322. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  17323. } else {
  17324. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  17325. }
  17326. var nv = n;
  17327. /* remove nv - 2 vertices, creating 1 triangle every time */
  17328. var count = 2 * nv; /* error detection */
  17329. for ( v = nv - 1; nv > 2; ) {
  17330. /* if we loop, it is probably a non-simple polygon */
  17331. if ( ( count -- ) <= 0 ) {
  17332. //** Triangulate: ERROR - probable bad polygon!
  17333. //throw ( "Warning, unable to triangulate polygon!" );
  17334. //return null;
  17335. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  17336. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  17337. if ( indices ) return vertIndices;
  17338. return result;
  17339. }
  17340. /* three consecutive vertices in current polygon, <u,v,w> */
  17341. u = v; if ( nv <= u ) u = 0; /* previous */
  17342. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  17343. w = v + 1; if ( nv <= w ) w = 0; /* next */
  17344. if ( snip( contour, u, v, w, nv, verts ) ) {
  17345. var a, b, c, s, t;
  17346. /* true names of the vertices */
  17347. a = verts[ u ];
  17348. b = verts[ v ];
  17349. c = verts[ w ];
  17350. /* output Triangle */
  17351. result.push( [ contour[ a ],
  17352. contour[ b ],
  17353. contour[ c ] ] );
  17354. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  17355. /* remove v from the remaining polygon */
  17356. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  17357. verts[ s ] = verts[ t ];
  17358. }
  17359. nv --;
  17360. /* reset error detection counter */
  17361. count = 2 * nv;
  17362. }
  17363. }
  17364. if ( indices ) return vertIndices;
  17365. return result;
  17366. };
  17367. } )(),
  17368. triangulateShape: function ( contour, holes ) {
  17369. function removeDupEndPts( points ) {
  17370. var l = points.length;
  17371. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17372. points.pop();
  17373. }
  17374. }
  17375. removeDupEndPts( contour );
  17376. holes.forEach( removeDupEndPts );
  17377. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  17378. // inOtherPt needs to be collinear to the inSegment
  17379. if ( inSegPt1.x !== inSegPt2.x ) {
  17380. if ( inSegPt1.x < inSegPt2.x ) {
  17381. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  17382. } else {
  17383. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  17384. }
  17385. } else {
  17386. if ( inSegPt1.y < inSegPt2.y ) {
  17387. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  17388. } else {
  17389. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  17390. }
  17391. }
  17392. }
  17393. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  17394. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  17395. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  17396. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  17397. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  17398. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  17399. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  17400. if ( Math.abs( limit ) > Number.EPSILON ) {
  17401. // not parallel
  17402. var perpSeg2;
  17403. if ( limit > 0 ) {
  17404. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  17405. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17406. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  17407. } else {
  17408. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  17409. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17410. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  17411. }
  17412. // i.e. to reduce rounding errors
  17413. // intersection at endpoint of segment#1?
  17414. if ( perpSeg2 === 0 ) {
  17415. if ( ( inExcludeAdjacentSegs ) &&
  17416. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17417. return [ inSeg1Pt1 ];
  17418. }
  17419. if ( perpSeg2 === limit ) {
  17420. if ( ( inExcludeAdjacentSegs ) &&
  17421. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17422. return [ inSeg1Pt2 ];
  17423. }
  17424. // intersection at endpoint of segment#2?
  17425. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  17426. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  17427. // return real intersection point
  17428. var factorSeg1 = perpSeg2 / limit;
  17429. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx, y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  17430. } else {
  17431. // parallel or collinear
  17432. if ( ( perpSeg1 !== 0 ) ||
  17433. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  17434. // they are collinear or degenerate
  17435. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  17436. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  17437. // both segments are points
  17438. if ( seg1Pt && seg2Pt ) {
  17439. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  17440. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  17441. return [ inSeg1Pt1 ]; // they are the same point
  17442. }
  17443. // segment#1 is a single point
  17444. if ( seg1Pt ) {
  17445. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  17446. return [ inSeg1Pt1 ];
  17447. }
  17448. // segment#2 is a single point
  17449. if ( seg2Pt ) {
  17450. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  17451. return [ inSeg2Pt1 ];
  17452. }
  17453. // they are collinear segments, which might overlap
  17454. var seg1min, seg1max, seg1minVal, seg1maxVal;
  17455. var seg2min, seg2max, seg2minVal, seg2maxVal;
  17456. if ( seg1dx !== 0 ) {
  17457. // the segments are NOT on a vertical line
  17458. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  17459. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  17460. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  17461. } else {
  17462. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  17463. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  17464. }
  17465. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  17466. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  17467. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  17468. } else {
  17469. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  17470. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  17471. }
  17472. } else {
  17473. // the segments are on a vertical line
  17474. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  17475. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  17476. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  17477. } else {
  17478. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  17479. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  17480. }
  17481. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  17482. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  17483. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  17484. } else {
  17485. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  17486. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  17487. }
  17488. }
  17489. if ( seg1minVal <= seg2minVal ) {
  17490. if ( seg1maxVal < seg2minVal ) return [];
  17491. if ( seg1maxVal === seg2minVal ) {
  17492. if ( inExcludeAdjacentSegs ) return [];
  17493. return [ seg2min ];
  17494. }
  17495. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  17496. return [ seg2min, seg2max ];
  17497. } else {
  17498. if ( seg1minVal > seg2maxVal ) return [];
  17499. if ( seg1minVal === seg2maxVal ) {
  17500. if ( inExcludeAdjacentSegs ) return [];
  17501. return [ seg1min ];
  17502. }
  17503. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  17504. return [ seg1min, seg2max ];
  17505. }
  17506. }
  17507. }
  17508. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  17509. // The order of legs is important
  17510. // translation of all points, so that Vertex is at (0,0)
  17511. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  17512. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  17513. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  17514. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  17515. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  17516. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  17517. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  17518. // angle != 180 deg.
  17519. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  17520. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  17521. if ( from2toAngle > 0 ) {
  17522. // main angle < 180 deg.
  17523. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  17524. } else {
  17525. // main angle > 180 deg.
  17526. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  17527. }
  17528. } else {
  17529. // angle == 180 deg.
  17530. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  17531. return ( from2otherAngle > 0 );
  17532. }
  17533. }
  17534. function removeHoles( contour, holes ) {
  17535. var shape = contour.concat(); // work on this shape
  17536. var hole;
  17537. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  17538. // Check if hole point lies within angle around shape point
  17539. var lastShapeIdx = shape.length - 1;
  17540. var prevShapeIdx = inShapeIdx - 1;
  17541. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  17542. var nextShapeIdx = inShapeIdx + 1;
  17543. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  17544. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  17545. if ( ! insideAngle ) {
  17546. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  17547. return false;
  17548. }
  17549. // Check if shape point lies within angle around hole point
  17550. var lastHoleIdx = hole.length - 1;
  17551. var prevHoleIdx = inHoleIdx - 1;
  17552. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  17553. var nextHoleIdx = inHoleIdx + 1;
  17554. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  17555. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  17556. if ( ! insideAngle ) {
  17557. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  17558. return false;
  17559. }
  17560. return true;
  17561. }
  17562. function intersectsShapeEdge( inShapePt, inHolePt ) {
  17563. // checks for intersections with shape edges
  17564. var sIdx, nextIdx, intersection;
  17565. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  17566. nextIdx = sIdx + 1; nextIdx %= shape.length;
  17567. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  17568. if ( intersection.length > 0 ) return true;
  17569. }
  17570. return false;
  17571. }
  17572. var indepHoles = [];
  17573. function intersectsHoleEdge( inShapePt, inHolePt ) {
  17574. // checks for intersections with hole edges
  17575. var ihIdx, chkHole,
  17576. hIdx, nextIdx, intersection;
  17577. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  17578. chkHole = holes[ indepHoles[ ihIdx ] ];
  17579. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  17580. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  17581. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  17582. if ( intersection.length > 0 ) return true;
  17583. }
  17584. }
  17585. return false;
  17586. }
  17587. var holeIndex, shapeIndex,
  17588. shapePt, holePt,
  17589. holeIdx, cutKey, failedCuts = [],
  17590. tmpShape1, tmpShape2,
  17591. tmpHole1, tmpHole2;
  17592. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17593. indepHoles.push( h );
  17594. }
  17595. var minShapeIndex = 0;
  17596. var counter = indepHoles.length * 2;
  17597. while ( indepHoles.length > 0 ) {
  17598. counter --;
  17599. if ( counter < 0 ) {
  17600. console.log( 'THREE.ShapeUtils: Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!' );
  17601. break;
  17602. }
  17603. // search for shape-vertex and hole-vertex,
  17604. // which can be connected without intersections
  17605. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  17606. shapePt = shape[ shapeIndex ];
  17607. holeIndex = - 1;
  17608. // search for hole which can be reached without intersections
  17609. for ( var h = 0; h < indepHoles.length; h ++ ) {
  17610. holeIdx = indepHoles[ h ];
  17611. // prevent multiple checks
  17612. cutKey = shapePt.x + ':' + shapePt.y + ':' + holeIdx;
  17613. if ( failedCuts[ cutKey ] !== undefined ) continue;
  17614. hole = holes[ holeIdx ];
  17615. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  17616. holePt = hole[ h2 ];
  17617. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  17618. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  17619. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  17620. holeIndex = h2;
  17621. indepHoles.splice( h, 1 );
  17622. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  17623. tmpShape2 = shape.slice( shapeIndex );
  17624. tmpHole1 = hole.slice( holeIndex );
  17625. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  17626. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  17627. minShapeIndex = shapeIndex;
  17628. // Debug only, to show the selected cuts
  17629. // glob_CutLines.push( [ shapePt, holePt ] );
  17630. break;
  17631. }
  17632. if ( holeIndex >= 0 ) break; // hole-vertex found
  17633. failedCuts[ cutKey ] = true; // remember failure
  17634. }
  17635. if ( holeIndex >= 0 ) break; // hole-vertex found
  17636. }
  17637. }
  17638. return shape; /* shape with no holes */
  17639. }
  17640. var i, il, f, face,
  17641. key, index,
  17642. allPointsMap = {};
  17643. // 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.
  17644. var allpoints = contour.concat();
  17645. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17646. Array.prototype.push.apply( allpoints, holes[ h ] );
  17647. }
  17648. //console.log( "allpoints",allpoints, allpoints.length );
  17649. // prepare all points map
  17650. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  17651. key = allpoints[ i ].x + ':' + allpoints[ i ].y;
  17652. if ( allPointsMap[ key ] !== undefined ) {
  17653. console.warn( 'THREE.ShapeUtils: Duplicate point', key, i );
  17654. }
  17655. allPointsMap[ key ] = i;
  17656. }
  17657. // remove holes by cutting paths to holes and adding them to the shape
  17658. var shapeWithoutHoles = removeHoles( contour, holes );
  17659. var triangles = ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  17660. //console.log( "triangles",triangles, triangles.length );
  17661. // check all face vertices against all points map
  17662. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  17663. face = triangles[ i ];
  17664. for ( f = 0; f < 3; f ++ ) {
  17665. key = face[ f ].x + ':' + face[ f ].y;
  17666. index = allPointsMap[ key ];
  17667. if ( index !== undefined ) {
  17668. face[ f ] = index;
  17669. }
  17670. }
  17671. }
  17672. return triangles.concat();
  17673. },
  17674. isClockWise: function ( pts ) {
  17675. return ShapeUtils.area( pts ) < 0;
  17676. }
  17677. };
  17678. /**
  17679. * @author TristanVALCKE / https://github.com/Itee
  17680. */
  17681. /* global QUnit */
  17682. QUnit.module( 'Extras', () => {
  17683. QUnit.module.todo( 'ShapeUtils', () => {
  17684. // PUBLIC STUFF
  17685. QUnit.test( "area", ( assert ) => {
  17686. assert.ok( false, "everything's gonna be alright" );
  17687. } );
  17688. QUnit.test( "triangulate", ( assert ) => {
  17689. assert.ok( false, "everything's gonna be alright" );
  17690. } );
  17691. QUnit.test( "triangulateShape", ( assert ) => {
  17692. assert.ok( false, "everything's gonna be alright" );
  17693. } );
  17694. QUnit.test( "isClockWise", ( assert ) => {
  17695. assert.ok( false, "everything's gonna be alright" );
  17696. } );
  17697. } );
  17698. } );
  17699. /**
  17700. * @author zz85 / http://www.lab4games.net/zz85/blog
  17701. * Extensible curve object
  17702. *
  17703. * Some common of curve methods:
  17704. * .getPoint( t, optionalTarget ), .getTangent( t )
  17705. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  17706. * .getPoints(), .getSpacedPoints()
  17707. * .getLength()
  17708. * .updateArcLengths()
  17709. *
  17710. * This following curves inherit from THREE.Curve:
  17711. *
  17712. * -- 2D curves --
  17713. * THREE.ArcCurve
  17714. * THREE.CubicBezierCurve
  17715. * THREE.EllipseCurve
  17716. * THREE.LineCurve
  17717. * THREE.QuadraticBezierCurve
  17718. * THREE.SplineCurve
  17719. *
  17720. * -- 3D curves --
  17721. * THREE.CatmullRomCurve3
  17722. * THREE.CubicBezierCurve3
  17723. * THREE.LineCurve3
  17724. * THREE.QuadraticBezierCurve3
  17725. *
  17726. * A series of curves can be represented as a THREE.CurvePath.
  17727. *
  17728. **/
  17729. /**************************************************************
  17730. * Abstract Curve base class
  17731. **************************************************************/
  17732. function Curve() {
  17733. this.type = 'Curve';
  17734. this.arcLengthDivisions = 200;
  17735. }
  17736. Object.assign( Curve.prototype, {
  17737. // Virtual base class method to overwrite and implement in subclasses
  17738. // - t [0 .. 1]
  17739. getPoint: function ( /* t, optionalTarget */ ) {
  17740. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  17741. return null;
  17742. },
  17743. // Get point at relative position in curve according to arc length
  17744. // - u [0 .. 1]
  17745. getPointAt: function ( u, optionalTarget ) {
  17746. var t = this.getUtoTmapping( u );
  17747. return this.getPoint( t, optionalTarget );
  17748. },
  17749. // Get sequence of points using getPoint( t )
  17750. getPoints: function ( divisions ) {
  17751. if ( divisions === undefined ) divisions = 5;
  17752. var points = [];
  17753. for ( var d = 0; d <= divisions; d ++ ) {
  17754. points.push( this.getPoint( d / divisions ) );
  17755. }
  17756. return points;
  17757. },
  17758. // Get sequence of points using getPointAt( u )
  17759. getSpacedPoints: function ( divisions ) {
  17760. if ( divisions === undefined ) divisions = 5;
  17761. var points = [];
  17762. for ( var d = 0; d <= divisions; d ++ ) {
  17763. points.push( this.getPointAt( d / divisions ) );
  17764. }
  17765. return points;
  17766. },
  17767. // Get total curve arc length
  17768. getLength: function () {
  17769. var lengths = this.getLengths();
  17770. return lengths[ lengths.length - 1 ];
  17771. },
  17772. // Get list of cumulative segment lengths
  17773. getLengths: function ( divisions ) {
  17774. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  17775. if ( this.cacheArcLengths &&
  17776. ( this.cacheArcLengths.length === divisions + 1 ) &&
  17777. ! this.needsUpdate ) {
  17778. return this.cacheArcLengths;
  17779. }
  17780. this.needsUpdate = false;
  17781. var cache = [];
  17782. var current, last = this.getPoint( 0 );
  17783. var p, sum = 0;
  17784. cache.push( 0 );
  17785. for ( p = 1; p <= divisions; p ++ ) {
  17786. current = this.getPoint( p / divisions );
  17787. sum += current.distanceTo( last );
  17788. cache.push( sum );
  17789. last = current;
  17790. }
  17791. this.cacheArcLengths = cache;
  17792. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  17793. },
  17794. updateArcLengths: function () {
  17795. this.needsUpdate = true;
  17796. this.getLengths();
  17797. },
  17798. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  17799. getUtoTmapping: function ( u, distance ) {
  17800. var arcLengths = this.getLengths();
  17801. var i = 0, il = arcLengths.length;
  17802. var targetArcLength; // The targeted u distance value to get
  17803. if ( distance ) {
  17804. targetArcLength = distance;
  17805. } else {
  17806. targetArcLength = u * arcLengths[ il - 1 ];
  17807. }
  17808. // binary search for the index with largest value smaller than target u distance
  17809. var low = 0, high = il - 1, comparison;
  17810. while ( low <= high ) {
  17811. 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
  17812. comparison = arcLengths[ i ] - targetArcLength;
  17813. if ( comparison < 0 ) {
  17814. low = i + 1;
  17815. } else if ( comparison > 0 ) {
  17816. high = i - 1;
  17817. } else {
  17818. high = i;
  17819. break;
  17820. // DONE
  17821. }
  17822. }
  17823. i = high;
  17824. if ( arcLengths[ i ] === targetArcLength ) {
  17825. return i / ( il - 1 );
  17826. }
  17827. // we could get finer grain at lengths, or use simple interpolation between two points
  17828. var lengthBefore = arcLengths[ i ];
  17829. var lengthAfter = arcLengths[ i + 1 ];
  17830. var segmentLength = lengthAfter - lengthBefore;
  17831. // determine where we are between the 'before' and 'after' points
  17832. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  17833. // add that fractional amount to t
  17834. var t = ( i + segmentFraction ) / ( il - 1 );
  17835. return t;
  17836. },
  17837. // Returns a unit vector tangent at t
  17838. // In case any sub curve does not implement its tangent derivation,
  17839. // 2 points a small delta apart will be used to find its gradient
  17840. // which seems to give a reasonable approximation
  17841. getTangent: function ( t ) {
  17842. var delta = 0.0001;
  17843. var t1 = t - delta;
  17844. var t2 = t + delta;
  17845. // Capping in case of danger
  17846. if ( t1 < 0 ) t1 = 0;
  17847. if ( t2 > 1 ) t2 = 1;
  17848. var pt1 = this.getPoint( t1 );
  17849. var pt2 = this.getPoint( t2 );
  17850. var vec = pt2.clone().sub( pt1 );
  17851. return vec.normalize();
  17852. },
  17853. getTangentAt: function ( u ) {
  17854. var t = this.getUtoTmapping( u );
  17855. return this.getTangent( t );
  17856. },
  17857. computeFrenetFrames: function ( segments, closed ) {
  17858. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  17859. var normal = new Vector3();
  17860. var tangents = [];
  17861. var normals = [];
  17862. var binormals = [];
  17863. var vec = new Vector3();
  17864. var mat = new Matrix4();
  17865. var i, u, theta;
  17866. // compute the tangent vectors for each segment on the curve
  17867. for ( i = 0; i <= segments; i ++ ) {
  17868. u = i / segments;
  17869. tangents[ i ] = this.getTangentAt( u );
  17870. tangents[ i ].normalize();
  17871. }
  17872. // select an initial normal vector perpendicular to the first tangent vector,
  17873. // and in the direction of the minimum tangent xyz component
  17874. normals[ 0 ] = new Vector3();
  17875. binormals[ 0 ] = new Vector3();
  17876. var min = Number.MAX_VALUE;
  17877. var tx = Math.abs( tangents[ 0 ].x );
  17878. var ty = Math.abs( tangents[ 0 ].y );
  17879. var tz = Math.abs( tangents[ 0 ].z );
  17880. if ( tx <= min ) {
  17881. min = tx;
  17882. normal.set( 1, 0, 0 );
  17883. }
  17884. if ( ty <= min ) {
  17885. min = ty;
  17886. normal.set( 0, 1, 0 );
  17887. }
  17888. if ( tz <= min ) {
  17889. normal.set( 0, 0, 1 );
  17890. }
  17891. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  17892. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  17893. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  17894. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  17895. for ( i = 1; i <= segments; i ++ ) {
  17896. normals[ i ] = normals[ i - 1 ].clone();
  17897. binormals[ i ] = binormals[ i - 1 ].clone();
  17898. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  17899. if ( vec.length() > Number.EPSILON ) {
  17900. vec.normalize();
  17901. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  17902. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  17903. }
  17904. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  17905. }
  17906. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  17907. if ( closed === true ) {
  17908. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  17909. theta /= segments;
  17910. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  17911. theta = - theta;
  17912. }
  17913. for ( i = 1; i <= segments; i ++ ) {
  17914. // twist a little...
  17915. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  17916. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  17917. }
  17918. }
  17919. return {
  17920. tangents: tangents,
  17921. normals: normals,
  17922. binormals: binormals
  17923. };
  17924. },
  17925. clone: function () {
  17926. return new this.constructor().copy( this );
  17927. },
  17928. copy: function ( source ) {
  17929. this.arcLengthDivisions = source.arcLengthDivisions;
  17930. return this;
  17931. }
  17932. } );
  17933. /**
  17934. * @author TristanVALCKE / https://github.com/Itee
  17935. */
  17936. /* global QUnit */
  17937. QUnit.module( 'Extras', () => {
  17938. QUnit.module( 'Core', () => {
  17939. QUnit.module.todo( 'Curve', () => {
  17940. // INSTANCING
  17941. QUnit.test( "Instancing", ( assert ) => {
  17942. assert.ok( false, "everything's gonna be alright" );
  17943. } );
  17944. // PUBLIC STUFF
  17945. QUnit.test( "getPoint", ( assert ) => {
  17946. assert.ok( false, "everything's gonna be alright" );
  17947. } );
  17948. QUnit.test( "getPointAt", ( assert ) => {
  17949. assert.ok( false, "everything's gonna be alright" );
  17950. } );
  17951. QUnit.test( "getPoints", ( assert ) => {
  17952. assert.ok( false, "everything's gonna be alright" );
  17953. } );
  17954. QUnit.test( "getSpacedPoints", ( assert ) => {
  17955. assert.ok( false, "everything's gonna be alright" );
  17956. } );
  17957. QUnit.test( "getLength", ( assert ) => {
  17958. assert.ok( false, "everything's gonna be alright" );
  17959. } );
  17960. QUnit.test( "getLengths", ( assert ) => {
  17961. assert.ok( false, "everything's gonna be alright" );
  17962. } );
  17963. QUnit.test( "updateArcLengths", ( assert ) => {
  17964. assert.ok( false, "everything's gonna be alright" );
  17965. } );
  17966. QUnit.test( "getUtoTmapping", ( assert ) => {
  17967. assert.ok( false, "everything's gonna be alright" );
  17968. } );
  17969. QUnit.test( "getTangent", ( assert ) => {
  17970. assert.ok( false, "everything's gonna be alright" );
  17971. } );
  17972. QUnit.test( "getTangentAt", ( assert ) => {
  17973. assert.ok( false, "everything's gonna be alright" );
  17974. } );
  17975. QUnit.test( "computeFrenetFrames", ( assert ) => {
  17976. assert.ok( false, "everything's gonna be alright" );
  17977. } );
  17978. } );
  17979. } );
  17980. } );
  17981. function LineCurve( v1, v2 ) {
  17982. Curve.call( this );
  17983. this.type = 'LineCurve';
  17984. this.v1 = v1 || new Vector2();
  17985. this.v2 = v2 || new Vector2();
  17986. }
  17987. LineCurve.prototype = Object.create( Curve.prototype );
  17988. LineCurve.prototype.constructor = LineCurve;
  17989. LineCurve.prototype.isLineCurve = true;
  17990. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  17991. var point = optionalTarget || new Vector2();
  17992. if ( t === 1 ) {
  17993. point.copy( this.v2 );
  17994. } else {
  17995. point.copy( this.v2 ).sub( this.v1 );
  17996. point.multiplyScalar( t ).add( this.v1 );
  17997. }
  17998. return point;
  17999. };
  18000. // Line curve is linear, so we can overwrite default getPointAt
  18001. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  18002. return this.getPoint( u, optionalTarget );
  18003. };
  18004. LineCurve.prototype.getTangent = function ( /* t */ ) {
  18005. var tangent = this.v2.clone().sub( this.v1 );
  18006. return tangent.normalize();
  18007. };
  18008. LineCurve.prototype.copy = function ( source ) {
  18009. Curve.prototype.copy.call( this, source );
  18010. this.v1.copy( source.v1 );
  18011. this.v2.copy( source.v2 );
  18012. return this;
  18013. };
  18014. /**
  18015. * @author zz85 / http://www.lab4games.net/zz85/blog
  18016. *
  18017. **/
  18018. /**************************************************************
  18019. * Curved Path - a curve path is simply a array of connected
  18020. * curves, but retains the api of a curve
  18021. **************************************************************/
  18022. function CurvePath() {
  18023. Curve.call( this );
  18024. this.type = 'CurvePath';
  18025. this.curves = [];
  18026. this.autoClose = false; // Automatically closes the path
  18027. }
  18028. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  18029. constructor: CurvePath,
  18030. add: function ( curve ) {
  18031. this.curves.push( curve );
  18032. },
  18033. closePath: function () {
  18034. // Add a line curve if start and end of lines are not connected
  18035. var startPoint = this.curves[ 0 ].getPoint( 0 );
  18036. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  18037. if ( ! startPoint.equals( endPoint ) ) {
  18038. this.curves.push( new LineCurve( endPoint, startPoint ) );
  18039. }
  18040. },
  18041. // To get accurate point with reference to
  18042. // entire path distance at time t,
  18043. // following has to be done:
  18044. // 1. Length of each sub path have to be known
  18045. // 2. Locate and identify type of curve
  18046. // 3. Get t for the curve
  18047. // 4. Return curve.getPointAt(t')
  18048. getPoint: function ( t ) {
  18049. var d = t * this.getLength();
  18050. var curveLengths = this.getCurveLengths();
  18051. var i = 0;
  18052. // To think about boundaries points.
  18053. while ( i < curveLengths.length ) {
  18054. if ( curveLengths[ i ] >= d ) {
  18055. var diff = curveLengths[ i ] - d;
  18056. var curve = this.curves[ i ];
  18057. var segmentLength = curve.getLength();
  18058. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  18059. return curve.getPointAt( u );
  18060. }
  18061. i ++;
  18062. }
  18063. return null;
  18064. // loop where sum != 0, sum > d , sum+1 <d
  18065. },
  18066. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  18067. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  18068. // getPoint() depends on getLength
  18069. getLength: function () {
  18070. var lens = this.getCurveLengths();
  18071. return lens[ lens.length - 1 ];
  18072. },
  18073. // cacheLengths must be recalculated.
  18074. updateArcLengths: function () {
  18075. this.needsUpdate = true;
  18076. this.cacheLengths = null;
  18077. this.getCurveLengths();
  18078. },
  18079. // Compute lengths and cache them
  18080. // We cannot overwrite getLengths() because UtoT mapping uses it.
  18081. getCurveLengths: function () {
  18082. // We use cache values if curves and cache array are same length
  18083. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  18084. return this.cacheLengths;
  18085. }
  18086. // Get length of sub-curve
  18087. // Push sums into cached array
  18088. var lengths = [], sums = 0;
  18089. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  18090. sums += this.curves[ i ].getLength();
  18091. lengths.push( sums );
  18092. }
  18093. this.cacheLengths = lengths;
  18094. return lengths;
  18095. },
  18096. getSpacedPoints: function ( divisions ) {
  18097. if ( divisions === undefined ) divisions = 40;
  18098. var points = [];
  18099. for ( var i = 0; i <= divisions; i ++ ) {
  18100. points.push( this.getPoint( i / divisions ) );
  18101. }
  18102. if ( this.autoClose ) {
  18103. points.push( points[ 0 ] );
  18104. }
  18105. return points;
  18106. },
  18107. getPoints: function ( divisions ) {
  18108. divisions = divisions || 12;
  18109. var points = [], last;
  18110. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  18111. var curve = curves[ i ];
  18112. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  18113. : ( curve && curve.isLineCurve ) ? 1
  18114. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  18115. : divisions;
  18116. var pts = curve.getPoints( resolution );
  18117. for ( var j = 0; j < pts.length; j ++ ) {
  18118. var point = pts[ j ];
  18119. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  18120. points.push( point );
  18121. last = point;
  18122. }
  18123. }
  18124. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  18125. points.push( points[ 0 ] );
  18126. }
  18127. return points;
  18128. }
  18129. } );
  18130. /**
  18131. * @author TristanVALCKE / https://github.com/Itee
  18132. */
  18133. /* global QUnit */
  18134. QUnit.module( 'Extras', () => {
  18135. QUnit.module( 'Core', () => {
  18136. QUnit.module.todo( 'CurvePath', () => {
  18137. // INHERITANCE
  18138. QUnit.test( "Extending", ( assert ) => {
  18139. assert.ok( false, "everything's gonna be alright" );
  18140. } );
  18141. // INSTANCING
  18142. QUnit.test( "Instancing", ( assert ) => {
  18143. assert.ok( false, "everything's gonna be alright" );
  18144. } );
  18145. // PUBLIC STUFF
  18146. QUnit.test( "add", ( assert ) => {
  18147. assert.ok( false, "everything's gonna be alright" );
  18148. } );
  18149. QUnit.test( "closePath", ( assert ) => {
  18150. assert.ok( false, "everything's gonna be alright" );
  18151. } );
  18152. QUnit.test( "getPoint", ( assert ) => {
  18153. assert.ok( false, "everything's gonna be alright" );
  18154. } );
  18155. QUnit.test( "getLength", ( assert ) => {
  18156. assert.ok( false, "everything's gonna be alright" );
  18157. } );
  18158. QUnit.test( "updateArcLengths", ( assert ) => {
  18159. assert.ok( false, "everything's gonna be alright" );
  18160. } );
  18161. QUnit.test( "getCurveLengths", ( assert ) => {
  18162. assert.ok( false, "everything's gonna be alright" );
  18163. } );
  18164. QUnit.test( "getSpacedPoints", ( assert ) => {
  18165. assert.ok( false, "everything's gonna be alright" );
  18166. } );
  18167. QUnit.test( "getPoints", ( assert ) => {
  18168. assert.ok( false, "everything's gonna be alright" );
  18169. } );
  18170. QUnit.test( "createPointsGeometry", ( assert ) => {
  18171. assert.ok( false, "everything's gonna be alright" );
  18172. } );
  18173. QUnit.test( "createSpacedPointsGeometry", ( assert ) => {
  18174. assert.ok( false, "everything's gonna be alright" );
  18175. } );
  18176. QUnit.test( "createGeometry", ( assert ) => {
  18177. assert.ok( false, "everything's gonna be alright" );
  18178. } );
  18179. } );
  18180. } );
  18181. } );
  18182. /**
  18183. * @author zz85 / http://www.lab4games.net/zz85/blog
  18184. *
  18185. * Bezier Curves formulas obtained from
  18186. * http://en.wikipedia.org/wiki/Bézier_curve
  18187. */
  18188. function CatmullRom( t, p0, p1, p2, p3 ) {
  18189. var v0 = ( p2 - p0 ) * 0.5;
  18190. var v1 = ( p3 - p1 ) * 0.5;
  18191. var t2 = t * t;
  18192. var t3 = t * t2;
  18193. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  18194. }
  18195. //
  18196. function QuadraticBezierP0( t, p ) {
  18197. var k = 1 - t;
  18198. return k * k * p;
  18199. }
  18200. function QuadraticBezierP1( t, p ) {
  18201. return 2 * ( 1 - t ) * t * p;
  18202. }
  18203. function QuadraticBezierP2( t, p ) {
  18204. return t * t * p;
  18205. }
  18206. function QuadraticBezier( t, p0, p1, p2 ) {
  18207. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  18208. QuadraticBezierP2( t, p2 );
  18209. }
  18210. //
  18211. function CubicBezierP0( t, p ) {
  18212. var k = 1 - t;
  18213. return k * k * k * p;
  18214. }
  18215. function CubicBezierP1( t, p ) {
  18216. var k = 1 - t;
  18217. return 3 * k * k * t * p;
  18218. }
  18219. function CubicBezierP2( t, p ) {
  18220. return 3 * ( 1 - t ) * t * t * p;
  18221. }
  18222. function CubicBezierP3( t, p ) {
  18223. return t * t * t * p;
  18224. }
  18225. function CubicBezier( t, p0, p1, p2, p3 ) {
  18226. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  18227. CubicBezierP3( t, p3 );
  18228. }
  18229. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  18230. Curve.call( this );
  18231. this.type = 'EllipseCurve';
  18232. this.aX = aX || 0;
  18233. this.aY = aY || 0;
  18234. this.xRadius = xRadius || 1;
  18235. this.yRadius = yRadius || 1;
  18236. this.aStartAngle = aStartAngle || 0;
  18237. this.aEndAngle = aEndAngle || 2 * Math.PI;
  18238. this.aClockwise = aClockwise || false;
  18239. this.aRotation = aRotation || 0;
  18240. }
  18241. EllipseCurve.prototype = Object.create( Curve.prototype );
  18242. EllipseCurve.prototype.constructor = EllipseCurve;
  18243. EllipseCurve.prototype.isEllipseCurve = true;
  18244. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  18245. var point = optionalTarget || new Vector2();
  18246. var twoPi = Math.PI * 2;
  18247. var deltaAngle = this.aEndAngle - this.aStartAngle;
  18248. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  18249. // ensures that deltaAngle is 0 .. 2 PI
  18250. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  18251. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  18252. if ( deltaAngle < Number.EPSILON ) {
  18253. if ( samePoints ) {
  18254. deltaAngle = 0;
  18255. } else {
  18256. deltaAngle = twoPi;
  18257. }
  18258. }
  18259. if ( this.aClockwise === true && ! samePoints ) {
  18260. if ( deltaAngle === twoPi ) {
  18261. deltaAngle = - twoPi;
  18262. } else {
  18263. deltaAngle = deltaAngle - twoPi;
  18264. }
  18265. }
  18266. var angle = this.aStartAngle + t * deltaAngle;
  18267. var x = this.aX + this.xRadius * Math.cos( angle );
  18268. var y = this.aY + this.yRadius * Math.sin( angle );
  18269. if ( this.aRotation !== 0 ) {
  18270. var cos = Math.cos( this.aRotation );
  18271. var sin = Math.sin( this.aRotation );
  18272. var tx = x - this.aX;
  18273. var ty = y - this.aY;
  18274. // Rotate the point about the center of the ellipse.
  18275. x = tx * cos - ty * sin + this.aX;
  18276. y = tx * sin + ty * cos + this.aY;
  18277. }
  18278. return point.set( x, y );
  18279. };
  18280. EllipseCurve.prototype.copy = function ( source ) {
  18281. Curve.prototype.copy.call( this, source );
  18282. this.aX = source.aX;
  18283. this.aY = source.aY;
  18284. this.xRadius = source.xRadius;
  18285. this.yRadius = source.yRadius;
  18286. this.aStartAngle = source.aStartAngle;
  18287. this.aEndAngle = source.aEndAngle;
  18288. this.aClockwise = source.aClockwise;
  18289. this.aRotation = source.aRotation;
  18290. return this;
  18291. };
  18292. function SplineCurve( points /* array of Vector2 */ ) {
  18293. Curve.call( this );
  18294. this.type = 'SplineCurve';
  18295. this.points = points || [];
  18296. }
  18297. SplineCurve.prototype = Object.create( Curve.prototype );
  18298. SplineCurve.prototype.constructor = SplineCurve;
  18299. SplineCurve.prototype.isSplineCurve = true;
  18300. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  18301. var point = optionalTarget || new Vector2();
  18302. var points = this.points;
  18303. var p = ( points.length - 1 ) * t;
  18304. var intPoint = Math.floor( p );
  18305. var weight = p - intPoint;
  18306. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  18307. var p1 = points[ intPoint ];
  18308. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  18309. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  18310. point.set(
  18311. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  18312. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  18313. );
  18314. return point;
  18315. };
  18316. SplineCurve.prototype.copy = function ( source ) {
  18317. Curve.prototype.copy.call( this, source );
  18318. this.points = [];
  18319. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  18320. var point = source.points[ i ];
  18321. this.points.push( point.clone() );
  18322. }
  18323. return this;
  18324. };
  18325. function CubicBezierCurve( v0, v1, v2, v3 ) {
  18326. Curve.call( this );
  18327. this.type = 'CubicBezierCurve';
  18328. this.v0 = v0 || new Vector2();
  18329. this.v1 = v1 || new Vector2();
  18330. this.v2 = v2 || new Vector2();
  18331. this.v3 = v3 || new Vector2();
  18332. }
  18333. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  18334. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  18335. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  18336. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  18337. var point = optionalTarget || new Vector2();
  18338. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  18339. point.set(
  18340. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  18341. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  18342. );
  18343. return point;
  18344. };
  18345. CubicBezierCurve.prototype.copy = function ( source ) {
  18346. Curve.prototype.copy.call( this, source );
  18347. this.v0.copy( source.v0 );
  18348. this.v1.copy( source.v1 );
  18349. this.v2.copy( source.v2 );
  18350. this.v3.copy( source.v3 );
  18351. return this;
  18352. };
  18353. function QuadraticBezierCurve( v0, v1, v2 ) {
  18354. Curve.call( this );
  18355. this.type = 'QuadraticBezierCurve';
  18356. this.v0 = v0 || new Vector2();
  18357. this.v1 = v1 || new Vector2();
  18358. this.v2 = v2 || new Vector2();
  18359. }
  18360. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  18361. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  18362. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  18363. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  18364. var point = optionalTarget || new Vector2();
  18365. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  18366. point.set(
  18367. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  18368. QuadraticBezier( t, v0.y, v1.y, v2.y )
  18369. );
  18370. return point;
  18371. };
  18372. QuadraticBezierCurve.prototype.copy = function ( source ) {
  18373. Curve.prototype.copy.call( this, source );
  18374. this.v0.copy( source.v0 );
  18375. this.v1.copy( source.v1 );
  18376. this.v2.copy( source.v2 );
  18377. return this;
  18378. };
  18379. var PathPrototype = Object.assign( Object.create( CurvePath.prototype ), {
  18380. fromPoints: function ( vectors ) {
  18381. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  18382. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  18383. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  18384. }
  18385. },
  18386. moveTo: function ( x, y ) {
  18387. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  18388. },
  18389. lineTo: function ( x, y ) {
  18390. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  18391. this.curves.push( curve );
  18392. this.currentPoint.set( x, y );
  18393. },
  18394. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  18395. var curve = new QuadraticBezierCurve(
  18396. this.currentPoint.clone(),
  18397. new Vector2( aCPx, aCPy ),
  18398. new Vector2( aX, aY )
  18399. );
  18400. this.curves.push( curve );
  18401. this.currentPoint.set( aX, aY );
  18402. },
  18403. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  18404. var curve = new CubicBezierCurve(
  18405. this.currentPoint.clone(),
  18406. new Vector2( aCP1x, aCP1y ),
  18407. new Vector2( aCP2x, aCP2y ),
  18408. new Vector2( aX, aY )
  18409. );
  18410. this.curves.push( curve );
  18411. this.currentPoint.set( aX, aY );
  18412. },
  18413. splineThru: function ( pts /*Array of Vector*/ ) {
  18414. var npts = [ this.currentPoint.clone() ].concat( pts );
  18415. var curve = new SplineCurve( npts );
  18416. this.curves.push( curve );
  18417. this.currentPoint.copy( pts[ pts.length - 1 ] );
  18418. },
  18419. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  18420. var x0 = this.currentPoint.x;
  18421. var y0 = this.currentPoint.y;
  18422. this.absarc( aX + x0, aY + y0, aRadius,
  18423. aStartAngle, aEndAngle, aClockwise );
  18424. },
  18425. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  18426. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  18427. },
  18428. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  18429. var x0 = this.currentPoint.x;
  18430. var y0 = this.currentPoint.y;
  18431. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  18432. },
  18433. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  18434. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  18435. if ( this.curves.length > 0 ) {
  18436. // if a previous curve is present, attempt to join
  18437. var firstPoint = curve.getPoint( 0 );
  18438. if ( ! firstPoint.equals( this.currentPoint ) ) {
  18439. this.lineTo( firstPoint.x, firstPoint.y );
  18440. }
  18441. }
  18442. this.curves.push( curve );
  18443. var lastPoint = curve.getPoint( 1 );
  18444. this.currentPoint.copy( lastPoint );
  18445. }
  18446. } );
  18447. /**
  18448. * @author zz85 / http://www.lab4games.net/zz85/blog
  18449. * Creates free form 2d path using series of points, lines or curves.
  18450. **/
  18451. function Path( points ) {
  18452. CurvePath.call( this );
  18453. this.type = 'Path';
  18454. this.currentPoint = new Vector2();
  18455. if ( points ) {
  18456. this.fromPoints( points );
  18457. }
  18458. }
  18459. Path.prototype = PathPrototype;
  18460. PathPrototype.constructor = Path;
  18461. /**
  18462. * @author zz85 / http://www.lab4games.net/zz85/blog
  18463. * Defines a 2d shape plane using paths.
  18464. **/
  18465. // STEP 1 Create a path.
  18466. // STEP 2 Turn path into shape.
  18467. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  18468. // STEP 3a - Extract points from each shape, turn to vertices
  18469. // STEP 3b - Triangulate each shape, add faces.
  18470. function Shape() {
  18471. Path.apply( this, arguments );
  18472. this.type = 'Shape';
  18473. this.holes = [];
  18474. }
  18475. Shape.prototype = Object.assign( Object.create( PathPrototype ), {
  18476. constructor: Shape,
  18477. getPointsHoles: function ( divisions ) {
  18478. var holesPts = [];
  18479. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  18480. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  18481. }
  18482. return holesPts;
  18483. },
  18484. // Get points of shape and holes (keypoints based on segments parameter)
  18485. extractAllPoints: function ( divisions ) {
  18486. return {
  18487. shape: this.getPoints( divisions ),
  18488. holes: this.getPointsHoles( divisions )
  18489. };
  18490. },
  18491. extractPoints: function ( divisions ) {
  18492. return this.extractAllPoints( divisions );
  18493. }
  18494. } );
  18495. /**
  18496. * @author zz85 / http://www.lab4games.net/zz85/blog
  18497. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  18498. **/
  18499. function ShapePath() {
  18500. this.type = 'ShapePath';
  18501. this.subPaths = [];
  18502. this.currentPath = null;
  18503. }
  18504. Object.assign( ShapePath.prototype, {
  18505. moveTo: function ( x, y ) {
  18506. this.currentPath = new Path();
  18507. this.subPaths.push( this.currentPath );
  18508. this.currentPath.moveTo( x, y );
  18509. },
  18510. lineTo: function ( x, y ) {
  18511. this.currentPath.lineTo( x, y );
  18512. },
  18513. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  18514. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  18515. },
  18516. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  18517. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  18518. },
  18519. splineThru: function ( pts ) {
  18520. this.currentPath.splineThru( pts );
  18521. },
  18522. toShapes: function ( isCCW, noHoles ) {
  18523. function toShapesNoHoles( inSubpaths ) {
  18524. var shapes = [];
  18525. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  18526. var tmpPath = inSubpaths[ i ];
  18527. var tmpShape = new Shape();
  18528. tmpShape.curves = tmpPath.curves;
  18529. shapes.push( tmpShape );
  18530. }
  18531. return shapes;
  18532. }
  18533. function isPointInsidePolygon( inPt, inPolygon ) {
  18534. var polyLen = inPolygon.length;
  18535. // inPt on polygon contour => immediate success or
  18536. // toggling of inside/outside at every single! intersection point of an edge
  18537. // with the horizontal line through inPt, left of inPt
  18538. // not counting lowerY endpoints of edges and whole edges on that line
  18539. var inside = false;
  18540. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  18541. var edgeLowPt = inPolygon[ p ];
  18542. var edgeHighPt = inPolygon[ q ];
  18543. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  18544. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  18545. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  18546. // not parallel
  18547. if ( edgeDy < 0 ) {
  18548. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  18549. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  18550. }
  18551. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  18552. if ( inPt.y === edgeLowPt.y ) {
  18553. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  18554. // continue; // no intersection or edgeLowPt => doesn't count !!!
  18555. } else {
  18556. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  18557. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  18558. if ( perpEdge < 0 ) continue;
  18559. inside = ! inside; // true intersection left of inPt
  18560. }
  18561. } else {
  18562. // parallel or collinear
  18563. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  18564. // edge lies on the same horizontal line as inPt
  18565. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  18566. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  18567. // continue;
  18568. }
  18569. }
  18570. return inside;
  18571. }
  18572. var isClockWise = ShapeUtils.isClockWise;
  18573. var subPaths = this.subPaths;
  18574. if ( subPaths.length === 0 ) return [];
  18575. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  18576. var solid, tmpPath, tmpShape, shapes = [];
  18577. if ( subPaths.length === 1 ) {
  18578. tmpPath = subPaths[ 0 ];
  18579. tmpShape = new Shape();
  18580. tmpShape.curves = tmpPath.curves;
  18581. shapes.push( tmpShape );
  18582. return shapes;
  18583. }
  18584. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  18585. holesFirst = isCCW ? ! holesFirst : holesFirst;
  18586. // console.log("Holes first", holesFirst);
  18587. var betterShapeHoles = [];
  18588. var newShapes = [];
  18589. var newShapeHoles = [];
  18590. var mainIdx = 0;
  18591. var tmpPoints;
  18592. newShapes[ mainIdx ] = undefined;
  18593. newShapeHoles[ mainIdx ] = [];
  18594. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  18595. tmpPath = subPaths[ i ];
  18596. tmpPoints = tmpPath.getPoints();
  18597. solid = isClockWise( tmpPoints );
  18598. solid = isCCW ? ! solid : solid;
  18599. if ( solid ) {
  18600. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  18601. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  18602. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  18603. if ( holesFirst ) mainIdx ++;
  18604. newShapeHoles[ mainIdx ] = [];
  18605. //console.log('cw', i);
  18606. } else {
  18607. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  18608. //console.log('ccw', i);
  18609. }
  18610. }
  18611. // only Holes? -> probably all Shapes with wrong orientation
  18612. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  18613. if ( newShapes.length > 1 ) {
  18614. var ambiguous = false;
  18615. var toChange = [];
  18616. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18617. betterShapeHoles[ sIdx ] = [];
  18618. }
  18619. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18620. var sho = newShapeHoles[ sIdx ];
  18621. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  18622. var ho = sho[ hIdx ];
  18623. var hole_unassigned = true;
  18624. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  18625. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  18626. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  18627. if ( hole_unassigned ) {
  18628. hole_unassigned = false;
  18629. betterShapeHoles[ s2Idx ].push( ho );
  18630. } else {
  18631. ambiguous = true;
  18632. }
  18633. }
  18634. }
  18635. if ( hole_unassigned ) {
  18636. betterShapeHoles[ sIdx ].push( ho );
  18637. }
  18638. }
  18639. }
  18640. // console.log("ambiguous: ", ambiguous);
  18641. if ( toChange.length > 0 ) {
  18642. // console.log("to change: ", toChange);
  18643. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  18644. }
  18645. }
  18646. var tmpHoles;
  18647. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  18648. tmpShape = newShapes[ i ].s;
  18649. shapes.push( tmpShape );
  18650. tmpHoles = newShapeHoles[ i ];
  18651. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  18652. tmpShape.holes.push( tmpHoles[ j ].h );
  18653. }
  18654. }
  18655. //console.log("shape", shapes);
  18656. return shapes;
  18657. }
  18658. } );
  18659. /**
  18660. * @author zz85 / http://www.lab4games.net/zz85/blog
  18661. * @author mrdoob / http://mrdoob.com/
  18662. */
  18663. function Font( data ) {
  18664. this.type = 'Font';
  18665. this.data = data;
  18666. }
  18667. Object.assign( Font.prototype, {
  18668. isFont: true,
  18669. generateShapes: function ( text, size, divisions ) {
  18670. function createPaths( text ) {
  18671. var chars = String( text ).split( '' );
  18672. var scale = size / data.resolution;
  18673. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  18674. var offsetX = 0, offsetY = 0;
  18675. var paths = [];
  18676. for ( var i = 0; i < chars.length; i ++ ) {
  18677. var char = chars[ i ];
  18678. if ( char === '\n' ) {
  18679. offsetX = 0;
  18680. offsetY -= line_height;
  18681. } else {
  18682. var ret = createPath( char, scale, offsetX, offsetY );
  18683. offsetX += ret.offsetX;
  18684. paths.push( ret.path );
  18685. }
  18686. }
  18687. return paths;
  18688. }
  18689. function createPath( c, scale, offsetX, offsetY ) {
  18690. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  18691. if ( ! glyph ) return;
  18692. var path = new ShapePath();
  18693. var pts = [];
  18694. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  18695. if ( glyph.o ) {
  18696. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  18697. for ( var i = 0, l = outline.length; i < l; ) {
  18698. var action = outline[ i ++ ];
  18699. switch ( action ) {
  18700. case 'm': // moveTo
  18701. x = outline[ i ++ ] * scale + offsetX;
  18702. y = outline[ i ++ ] * scale + offsetY;
  18703. path.moveTo( x, y );
  18704. break;
  18705. case 'l': // lineTo
  18706. x = outline[ i ++ ] * scale + offsetX;
  18707. y = outline[ i ++ ] * scale + offsetY;
  18708. path.lineTo( x, y );
  18709. break;
  18710. case 'q': // quadraticCurveTo
  18711. cpx = outline[ i ++ ] * scale + offsetX;
  18712. cpy = outline[ i ++ ] * scale + offsetY;
  18713. cpx1 = outline[ i ++ ] * scale + offsetX;
  18714. cpy1 = outline[ i ++ ] * scale + offsetY;
  18715. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  18716. laste = pts[ pts.length - 1 ];
  18717. if ( laste ) {
  18718. cpx0 = laste.x;
  18719. cpy0 = laste.y;
  18720. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  18721. var t = i2 / divisions;
  18722. QuadraticBezier( t, cpx0, cpx1, cpx );
  18723. QuadraticBezier( t, cpy0, cpy1, cpy );
  18724. }
  18725. }
  18726. break;
  18727. case 'b': // bezierCurveTo
  18728. cpx = outline[ i ++ ] * scale + offsetX;
  18729. cpy = outline[ i ++ ] * scale + offsetY;
  18730. cpx1 = outline[ i ++ ] * scale + offsetX;
  18731. cpy1 = outline[ i ++ ] * scale + offsetY;
  18732. cpx2 = outline[ i ++ ] * scale + offsetX;
  18733. cpy2 = outline[ i ++ ] * scale + offsetY;
  18734. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  18735. laste = pts[ pts.length - 1 ];
  18736. if ( laste ) {
  18737. cpx0 = laste.x;
  18738. cpy0 = laste.y;
  18739. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  18740. var t = i2 / divisions;
  18741. CubicBezier( t, cpx0, cpx1, cpx2, cpx );
  18742. CubicBezier( t, cpy0, cpy1, cpy2, cpy );
  18743. }
  18744. }
  18745. break;
  18746. }
  18747. }
  18748. }
  18749. return { offsetX: glyph.ha * scale, path: path };
  18750. }
  18751. //
  18752. if ( size === undefined ) size = 100;
  18753. if ( divisions === undefined ) divisions = 4;
  18754. var data = this.data;
  18755. var paths = createPaths( text );
  18756. var shapes = [];
  18757. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  18758. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  18759. }
  18760. return shapes;
  18761. }
  18762. } );
  18763. /**
  18764. * @author TristanVALCKE / https://github.com/Itee
  18765. */
  18766. /* global QUnit */
  18767. QUnit.module( 'Extras', () => {
  18768. QUnit.module( 'Core', () => {
  18769. QUnit.module.todo( 'Font', () => {
  18770. // INSTANCING
  18771. QUnit.test( "Instancing", ( assert ) => {
  18772. assert.ok( false, "everything's gonna be alright" );
  18773. } );
  18774. // PUBLIC STUFF
  18775. QUnit.test( "isFont", ( assert ) => {
  18776. assert.ok( false, "everything's gonna be alright" );
  18777. } );
  18778. QUnit.test( "generateShapes", ( assert ) => {
  18779. assert.ok( false, "everything's gonna be alright" );
  18780. } );
  18781. } );
  18782. } );
  18783. } );
  18784. /**
  18785. * @author TristanVALCKE / https://github.com/Itee
  18786. */
  18787. /* global QUnit */
  18788. QUnit.module( 'Extras', () => {
  18789. QUnit.module( 'Core', () => {
  18790. QUnit.module.todo( 'Interpolations', () => {
  18791. // PUBLIC STUFF
  18792. QUnit.test( "CatmullRom", ( assert ) => {
  18793. assert.ok( false, "everything's gonna be alright" );
  18794. } );
  18795. QUnit.test( "QuadraticBezier", ( assert ) => {
  18796. assert.ok( false, "everything's gonna be alright" );
  18797. } );
  18798. QUnit.test( "CubicBezier", ( assert ) => {
  18799. assert.ok( false, "everything's gonna be alright" );
  18800. } );
  18801. } );
  18802. } );
  18803. } );
  18804. /**
  18805. * @author TristanVALCKE / https://github.com/Itee
  18806. */
  18807. /* global QUnit */
  18808. QUnit.module( 'Extras', () => {
  18809. QUnit.module( 'Core', () => {
  18810. QUnit.module.todo( 'Path', () => {
  18811. // INSTANCING
  18812. QUnit.test( "Instancing", ( assert ) => {
  18813. assert.ok( false, "everything's gonna be alright" );
  18814. } );
  18815. } );
  18816. } );
  18817. } );
  18818. /**
  18819. * @author TristanVALCKE / https://github.com/Itee
  18820. */
  18821. /* global QUnit */
  18822. QUnit.module( 'Extras', () => {
  18823. QUnit.module( 'Core', () => {
  18824. QUnit.module.todo( 'PathPrototype', () => {
  18825. // INHERITANCE
  18826. QUnit.test( "Extending", ( assert ) => {
  18827. assert.ok( false, "everything's gonna be alright" );
  18828. } );
  18829. // PUBLIC STUFF
  18830. QUnit.test( "fromPoints", ( assert ) => {
  18831. assert.ok( false, "everything's gonna be alright" );
  18832. } );
  18833. QUnit.test( "moveTo", ( assert ) => {
  18834. assert.ok( false, "everything's gonna be alright" );
  18835. } );
  18836. QUnit.test( "lineTo", ( assert ) => {
  18837. assert.ok( false, "everything's gonna be alright" );
  18838. } );
  18839. QUnit.test( "quadraticCurveTo", ( assert ) => {
  18840. assert.ok( false, "everything's gonna be alright" );
  18841. } );
  18842. QUnit.test( "bezierCurveTo", ( assert ) => {
  18843. assert.ok( false, "everything's gonna be alright" );
  18844. } );
  18845. QUnit.test( "splineThru", ( assert ) => {
  18846. assert.ok( false, "everything's gonna be alright" );
  18847. } );
  18848. QUnit.test( "arc", ( assert ) => {
  18849. assert.ok( false, "everything's gonna be alright" );
  18850. } );
  18851. QUnit.test( "absarc", ( assert ) => {
  18852. assert.ok( false, "everything's gonna be alright" );
  18853. } );
  18854. QUnit.test( "ellipse", ( assert ) => {
  18855. assert.ok( false, "everything's gonna be alright" );
  18856. } );
  18857. QUnit.test( "absellipse", ( assert ) => {
  18858. assert.ok( false, "everything's gonna be alright" );
  18859. } );
  18860. } );
  18861. } );
  18862. } );
  18863. /**
  18864. * @author TristanVALCKE / https://github.com/Itee
  18865. */
  18866. /* global QUnit */
  18867. QUnit.module( 'Extras', () => {
  18868. QUnit.module( 'Core', () => {
  18869. QUnit.module.todo( 'Shape', () => {
  18870. // INHERITANCE
  18871. QUnit.test( "Extending", ( assert ) => {
  18872. assert.ok( false, "everything's gonna be alright" );
  18873. } );
  18874. // INSTANCING
  18875. QUnit.test( "Instancing", ( assert ) => {
  18876. assert.ok( false, "everything's gonna be alright" );
  18877. } );
  18878. // PUBLIC STUFF
  18879. QUnit.test( "getPointsHoles", ( assert ) => {
  18880. assert.ok( false, "everything's gonna be alright" );
  18881. } );
  18882. QUnit.test( "extractAllPoints", ( assert ) => {
  18883. assert.ok( false, "everything's gonna be alright" );
  18884. } );
  18885. QUnit.test( "extractPoints", ( assert ) => {
  18886. assert.ok( false, "everything's gonna be alright" );
  18887. } );
  18888. } );
  18889. } );
  18890. } );
  18891. /**
  18892. * @author TristanVALCKE / https://github.com/Itee
  18893. */
  18894. /* global QUnit */
  18895. QUnit.module( 'Extras', () => {
  18896. QUnit.module( 'Core', () => {
  18897. QUnit.module.todo( 'ShapePath', () => {
  18898. // INSTANCING
  18899. QUnit.test( "Instancing", ( assert ) => {
  18900. assert.ok( false, "everything's gonna be alright" );
  18901. } );
  18902. // PUBLIC STUFF
  18903. QUnit.test( "moveTo", ( assert ) => {
  18904. assert.ok( false, "everything's gonna be alright" );
  18905. } );
  18906. QUnit.test( "lineTo", ( assert ) => {
  18907. assert.ok( false, "everything's gonna be alright" );
  18908. } );
  18909. QUnit.test( "quadraticCurveTo", ( assert ) => {
  18910. assert.ok( false, "everything's gonna be alright" );
  18911. } );
  18912. QUnit.test( "bezierCurveTo", ( assert ) => {
  18913. assert.ok( false, "everything's gonna be alright" );
  18914. } );
  18915. QUnit.test( "splineThru", ( assert ) => {
  18916. assert.ok( false, "everything's gonna be alright" );
  18917. } );
  18918. QUnit.test( "toShapes", ( assert ) => {
  18919. assert.ok( false, "everything's gonna be alright" );
  18920. } );
  18921. } );
  18922. } );
  18923. } );
  18924. /**
  18925. * @author TristanVALCKE / https://github.com/Itee
  18926. */
  18927. /* global QUnit */
  18928. QUnit.module( 'Extras', () => {
  18929. QUnit.module( 'Curves', () => {
  18930. QUnit.module.todo( 'ArcCurve', () => {
  18931. // INHERITANCE
  18932. QUnit.test( "Extending", ( assert ) => {
  18933. assert.ok( false, "everything's gonna be alright" );
  18934. } );
  18935. // INSTANCING
  18936. QUnit.test( "Instancing", ( assert ) => {
  18937. assert.ok( false, "everything's gonna be alright" );
  18938. } );
  18939. // PUBLIC STUFF
  18940. QUnit.test( "isArcCurve", ( assert ) => {
  18941. assert.ok( false, "everything's gonna be alright" );
  18942. } );
  18943. } );
  18944. } );
  18945. } );
  18946. /**
  18947. * @author zz85 https://github.com/zz85
  18948. *
  18949. * Centripetal CatmullRom Curve - which is useful for avoiding
  18950. * cusps and self-intersections in non-uniform catmull rom curves.
  18951. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  18952. *
  18953. * curve.type accepts centripetal(default), chordal and catmullrom
  18954. * curve.tension is used for catmullrom which defaults to 0.5
  18955. */
  18956. /*
  18957. Based on an optimized c++ solution in
  18958. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  18959. - http://ideone.com/NoEbVM
  18960. This CubicPoly class could be used for reusing some variables and calculations,
  18961. but for three.js curve use, it could be possible inlined and flatten into a single function call
  18962. which can be placed in CurveUtils.
  18963. */
  18964. function CubicPoly() {
  18965. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  18966. /*
  18967. * Compute coefficients for a cubic polynomial
  18968. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  18969. * such that
  18970. * p(0) = x0, p(1) = x1
  18971. * and
  18972. * p'(0) = t0, p'(1) = t1.
  18973. */
  18974. function init( x0, x1, t0, t1 ) {
  18975. c0 = x0;
  18976. c1 = t0;
  18977. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  18978. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  18979. }
  18980. return {
  18981. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  18982. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  18983. },
  18984. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  18985. // compute tangents when parameterized in [t1,t2]
  18986. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  18987. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  18988. // rescale tangents for parametrization in [0,1]
  18989. t1 *= dt1;
  18990. t2 *= dt1;
  18991. init( x1, x2, t1, t2 );
  18992. },
  18993. calc: function ( t ) {
  18994. var t2 = t * t;
  18995. var t3 = t2 * t;
  18996. return c0 + c1 * t + c2 * t2 + c3 * t3;
  18997. }
  18998. };
  18999. }
  19000. //
  19001. var tmp = new Vector3();
  19002. var px = new CubicPoly();
  19003. var py = new CubicPoly();
  19004. var pz = new CubicPoly();
  19005. function CatmullRomCurve3( points, closed, curveType, tension ) {
  19006. Curve.call( this );
  19007. this.type = 'CatmullRomCurve3';
  19008. this.points = points || [];
  19009. this.closed = closed || false;
  19010. this.curveType = curveType || 'centripetal';
  19011. this.tension = tension || 0.5;
  19012. }
  19013. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  19014. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  19015. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  19016. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19017. var point = optionalTarget || new Vector3();
  19018. var points = this.points;
  19019. var l = points.length;
  19020. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  19021. var intPoint = Math.floor( p );
  19022. var weight = p - intPoint;
  19023. if ( this.closed ) {
  19024. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  19025. } else if ( weight === 0 && intPoint === l - 1 ) {
  19026. intPoint = l - 2;
  19027. weight = 1;
  19028. }
  19029. var p0, p1, p2, p3; // 4 points
  19030. if ( this.closed || intPoint > 0 ) {
  19031. p0 = points[ ( intPoint - 1 ) % l ];
  19032. } else {
  19033. // extrapolate first point
  19034. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  19035. p0 = tmp;
  19036. }
  19037. p1 = points[ intPoint % l ];
  19038. p2 = points[ ( intPoint + 1 ) % l ];
  19039. if ( this.closed || intPoint + 2 < l ) {
  19040. p3 = points[ ( intPoint + 2 ) % l ];
  19041. } else {
  19042. // extrapolate last point
  19043. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  19044. p3 = tmp;
  19045. }
  19046. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  19047. // init Centripetal / Chordal Catmull-Rom
  19048. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  19049. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  19050. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  19051. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  19052. // safety check for repeated points
  19053. if ( dt1 < 1e-4 ) dt1 = 1.0;
  19054. if ( dt0 < 1e-4 ) dt0 = dt1;
  19055. if ( dt2 < 1e-4 ) dt2 = dt1;
  19056. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  19057. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  19058. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  19059. } else if ( this.curveType === 'catmullrom' ) {
  19060. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  19061. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  19062. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  19063. }
  19064. point.set(
  19065. px.calc( weight ),
  19066. py.calc( weight ),
  19067. pz.calc( weight )
  19068. );
  19069. return point;
  19070. };
  19071. CatmullRomCurve3.prototype.copy = function ( source ) {
  19072. Curve.prototype.copy.call( this, source );
  19073. this.points = [];
  19074. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  19075. var point = source.points[ i ];
  19076. this.points.push( point.clone() );
  19077. }
  19078. this.closed = source.closed;
  19079. this.curveType = source.curveType;
  19080. this.tension = source.tension;
  19081. return this;
  19082. };
  19083. /**
  19084. * @author zz85 / http://joshuakoo.com
  19085. * @author TristanVALCKE / https://github.com/Itee
  19086. */
  19087. /* global QUnit */
  19088. QUnit.module( 'Extras', () => {
  19089. QUnit.module( 'Curves', () => {
  19090. QUnit.module.todo( 'CatmullRomCurve3', () => {
  19091. /* eslint-disable */
  19092. var positions = [
  19093. new Vector3( - 60, - 100, 60 ),
  19094. new Vector3( - 60, 20, 60 ),
  19095. new Vector3( - 60, 120, 60 ),
  19096. new Vector3( 60, 20, - 60 ),
  19097. new Vector3( 60, - 100, - 60 )
  19098. ];
  19099. /* eslint-enable */
  19100. // INHERITANCE
  19101. QUnit.test( "Extending", ( assert ) => {
  19102. assert.ok( false, "everything's gonna be alright" );
  19103. } );
  19104. // INSTANCING
  19105. QUnit.test( "Instancing", ( assert ) => {
  19106. assert.ok( false, "everything's gonna be alright" );
  19107. } );
  19108. // PUBLIC STUFF
  19109. QUnit.test( "isCatmullRomCurve3", ( assert ) => {
  19110. assert.ok( false, "everything's gonna be alright" );
  19111. } );
  19112. QUnit.test( "getPoint", ( assert ) => {
  19113. assert.ok( false, "everything's gonna be alright" );
  19114. } );
  19115. // OTHERS
  19116. QUnit.test( "catmullrom check", ( assert ) => {
  19117. var curve = new CatmullRomCurve3( positions );
  19118. curve.type = 'catmullrom';
  19119. var expectedPoints = [
  19120. new Vector3( - 60, - 100, 60 ),
  19121. new Vector3( - 60, - 51.04, 60 ),
  19122. new Vector3( - 60, - 2.7199999999999998, 60 ),
  19123. new Vector3( - 61.92, 44.48, 61.92 ),
  19124. new Vector3( - 68.64, 95.36000000000001, 68.64 ),
  19125. new Vector3( - 60, 120, 60 ),
  19126. new Vector3( - 14.880000000000017, 95.36000000000001, 14.880000000000017 ),
  19127. new Vector3( 41.75999999999997, 44.48000000000003, - 41.75999999999997 ),
  19128. new Vector3( 67.68, - 2.720000000000023, - 67.68 ),
  19129. new Vector3( 65.75999999999999, - 51.04000000000001, - 65.75999999999999 ),
  19130. new Vector3( 60, - 100, - 60 )
  19131. ];
  19132. var points = curve.getPoints( 10 );
  19133. assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
  19134. points.forEach( function ( point, i ) {
  19135. assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
  19136. assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
  19137. assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
  19138. } );
  19139. } );
  19140. QUnit.test( "chordal basic check", ( assert ) => {
  19141. var curve = new CatmullRomCurve3( positions );
  19142. curve.type = 'chordal';
  19143. var expectedPoints = [
  19144. new Vector3( - 60, - 100, 60 ),
  19145. new Vector3( - 60, - 52, 60 ),
  19146. new Vector3( - 60, - 4, 60 ),
  19147. new Vector3( - 60.656435889910924, 41.62455386421379, 60.656435889910924 ),
  19148. new Vector3( - 62.95396150459915, 87.31049238896205, 62.95396150459915 ),
  19149. new Vector3( - 60, 120, 60 ),
  19150. new Vector3( - 16.302568199486444, 114.1500463116312, 16.302568199486444 ),
  19151. new Vector3( 42.998098664956586, 54.017050116427455, - 42.998098664956586 ),
  19152. new Vector3( 63.542500175682434, - 1.137153397546383, - 63.542500175682434 ),
  19153. new Vector3( 62.65687513176183, - 49.85286504815978, - 62.65687513176183 ),
  19154. new Vector3( 60.00000000000001, - 100, - 60.00000000000001 )
  19155. ];
  19156. var points = curve.getPoints( 10 );
  19157. assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
  19158. points.forEach( function ( point, i ) {
  19159. assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
  19160. assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
  19161. assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
  19162. } );
  19163. } );
  19164. QUnit.test( "centripetal basic check", ( assert ) => {
  19165. var curve = new CatmullRomCurve3( positions );
  19166. curve.type = 'centripetal';
  19167. var expectedPoints = [
  19168. new Vector3( - 60, - 100, 60 ),
  19169. new Vector3( - 60, - 51.47527724919028, 60 ),
  19170. new Vector3( - 60, - 3.300369665587032, 60 ),
  19171. new Vector3( - 61.13836565863938, 42.86306307781241, 61.13836565863938 ),
  19172. new Vector3( - 65.1226454638772, 90.69743905511538, 65.1226454638772 ),
  19173. new Vector3( - 60, 120, 60 ),
  19174. new Vector3( - 15.620412575504497, 103.10790870179872, 15.620412575504497 ),
  19175. new Vector3( 42.384384731047874, 48.35477686933143, - 42.384384731047874 ),
  19176. new Vector3( 65.25545512241153, - 1.646250966068339, - 65.25545512241153 ),
  19177. new Vector3( 63.94159134180865, - 50.234688224551256, - 63.94159134180865 ),
  19178. new Vector3( 59.99999999999999, - 100, - 59.99999999999999 ),
  19179. ];
  19180. var points = curve.getPoints( 10 );
  19181. assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
  19182. points.forEach( function ( point, i ) {
  19183. assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
  19184. assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
  19185. assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
  19186. } );
  19187. } );
  19188. QUnit.test( "closed catmullrom basic check", ( assert ) => {
  19189. var curve = new CatmullRomCurve3( positions );
  19190. curve.type = 'catmullrom';
  19191. curve.closed = true;
  19192. var expectedPoints = [
  19193. new Vector3( - 60, - 100, 60 ),
  19194. new Vector3( - 67.5, - 46.25, 67.5 ),
  19195. new Vector3( - 60, 20, 60 ),
  19196. new Vector3( - 67.5, 83.75, 67.5 ),
  19197. new Vector3( - 60, 120, 60 ),
  19198. new Vector3( 0, 83.75, 0 ),
  19199. new Vector3( 60, 20, - 60 ),
  19200. new Vector3( 75, - 46.25, - 75 ),
  19201. new Vector3( 60, - 100, - 60 ),
  19202. new Vector3( 0, - 115, 0 ),
  19203. new Vector3( - 60, - 100, 60 ),
  19204. ];
  19205. var points = curve.getPoints( 10 );
  19206. assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
  19207. points.forEach( function ( point, i ) {
  19208. assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
  19209. assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
  19210. assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
  19211. } );
  19212. } );
  19213. //
  19214. // curve.type = 'catmullrom'; only from here on
  19215. //
  19216. QUnit.test( "getLength/getLengths", ( assert ) => {
  19217. var curve = new THREE.CatmullRomCurve3( positions );
  19218. curve.type = 'catmullrom';
  19219. var length = curve.getLength();
  19220. var expectedLength = 551.549686276872;
  19221. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19222. var expectedLengths = [
  19223. 0,
  19224. 120,
  19225. 220,
  19226. 416.9771560359221,
  19227. 536.9771560359221
  19228. ];
  19229. var lengths = curve.getLengths( expectedLengths.length - 1 );
  19230. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19231. lengths.forEach( function ( segment, i ) {
  19232. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19233. } );
  19234. } );
  19235. QUnit.test( "getPointAt", ( assert ) => {
  19236. var curve = new THREE.CatmullRomCurve3( positions );
  19237. curve.type = 'catmullrom';
  19238. var expectedPoints = [
  19239. new THREE.Vector3( - 60, - 100, 60 ),
  19240. new THREE.Vector3( - 64.84177333183106, 64.86956465359813, 64.84177333183106 ),
  19241. new THREE.Vector3( - 28.288507045700854, 104.83101184518996, 28.288507045700854 ),
  19242. new THREE.Vector3( 60, - 100, - 60 )
  19243. ];
  19244. var points = [
  19245. curve.getPointAt( 0 ),
  19246. curve.getPointAt( 0.3 ),
  19247. curve.getPointAt( 0.5 ),
  19248. curve.getPointAt( 1 )
  19249. ];
  19250. assert.deepEqual( points, expectedPoints, "Correct points" );
  19251. } );
  19252. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  19253. var curve = new THREE.CatmullRomCurve3( positions );
  19254. curve.type = 'catmullrom';
  19255. var expectedTangents = [
  19256. new THREE.Vector3( 0, 1, 0 ),
  19257. new THREE.Vector3( - 0.0001090274561657922, 0.9999999881130137, 0.0001090274561657922 ),
  19258. new THREE.Vector3( 0.7071067811865475, - 2.0930381713877622e-13, - 0.7071067811865475 ),
  19259. new THREE.Vector3( 0.43189437062802816, - 0.7917919583070032, - 0.43189437062802816 ),
  19260. new THREE.Vector3( - 0.00019991333100812723, - 0.9999999600346592, 0.00019991333100812723 )
  19261. ];
  19262. var tangents = [
  19263. curve.getTangent( 0 ),
  19264. curve.getTangent( 0.25 ),
  19265. curve.getTangent( 0.5 ),
  19266. curve.getTangent( 0.75 ),
  19267. curve.getTangent( 1 )
  19268. ];
  19269. expectedTangents.forEach( function ( exp, i ) {
  19270. var tangent = tangents[ i ];
  19271. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  19272. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  19273. } );
  19274. //
  19275. var expectedTangents = [
  19276. new THREE.Vector3( 0, 1, 0 ),
  19277. new THREE.Vector3( - 0.10709018822205997, 0.9884651653817284, 0.10709018822205997 ),
  19278. new THREE.Vector3( 0.6396363672964268, - 0.4262987629159402, - 0.6396363672964268 ),
  19279. new THREE.Vector3( 0.5077298411616501, - 0.6960034603275557, - 0.5077298411616501 ),
  19280. new THREE.Vector3( - 0.00019991333100812723, - 0.9999999600346592, 0.00019991333100812723 )
  19281. ];
  19282. var tangents = [
  19283. curve.getTangentAt( 0 ),
  19284. curve.getTangentAt( 0.25 ),
  19285. curve.getTangentAt( 0.5 ),
  19286. curve.getTangentAt( 0.75 ),
  19287. curve.getTangentAt( 1 )
  19288. ];
  19289. expectedTangents.forEach( function ( exp, i ) {
  19290. var tangent = tangents[ i ];
  19291. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  19292. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  19293. } );
  19294. } );
  19295. QUnit.test( "computeFrenetFrames", ( assert ) => {
  19296. var curve = new THREE.CatmullRomCurve3( positions );
  19297. curve.type = 'catmullrom';
  19298. var expected = {
  19299. binormals: [
  19300. new THREE.Vector3( - 1, 0, 0 ),
  19301. new THREE.Vector3( - 0.28685061854203, 0.6396363672964267, - 0.7131493814579701 ),
  19302. new THREE.Vector3( - 1.9982670528160395e-8, - 0.0001999133310081272, - 0.9999999800173295 )
  19303. ],
  19304. normals: [
  19305. new THREE.Vector3( 0, 0, - 1 ),
  19306. new THREE.Vector3( - 0.7131493814579699, - 0.6396363672964268, - 0.2868506185420297 ),
  19307. new THREE.Vector3( - 0.9999999800173294, 0.00019991333100810582, - 1.99826701852146e-8 )
  19308. ],
  19309. tangents: [
  19310. new THREE.Vector3( 0, 1, 0 ),
  19311. new THREE.Vector3( 0.6396363672964269, - 0.4262987629159403, - 0.6396363672964269 ),
  19312. new THREE.Vector3( - 0.0001999133310081273, - 0.9999999600346594, 0.0001999133310081273 )
  19313. ]
  19314. };
  19315. var frames = curve.computeFrenetFrames( 2, false );
  19316. Object.keys( expected ).forEach( function ( group, i ) {
  19317. expected[ group ].forEach( function ( vec, j ) {
  19318. assert.numEqual( frames[ group ][ j ].x, vec.x, "Frenet frames [" + i + ", " + j + "].x correct" );
  19319. assert.numEqual( frames[ group ][ j ].y, vec.y, "Frenet frames [" + i + ", " + j + "].y correct" );
  19320. assert.numEqual( frames[ group ][ j ].z, vec.z, "Frenet frames [" + i + ", " + j + "].z correct" );
  19321. } );
  19322. } );
  19323. } );
  19324. QUnit.test( "getUtoTmapping", ( assert ) => {
  19325. var curve = new THREE.CatmullRomCurve3( positions );
  19326. curve.type = 'catmullrom';
  19327. var start = curve.getUtoTmapping( 0, 0 );
  19328. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19329. var somewhere = curve.getUtoTmapping( 0.5, 500 );
  19330. var expectedSomewhere = 0.8964116382083199;
  19331. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19332. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19333. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 500 ) is correct" );
  19334. } );
  19335. QUnit.test( "getSpacedPoints", ( assert ) => {
  19336. var curve = new THREE.CatmullRomCurve3( positions );
  19337. curve.type = 'catmullrom';
  19338. var expectedPoints = [
  19339. new THREE.Vector3( - 60, - 100, 60 ),
  19340. new THREE.Vector3( - 60, 10.311489426555056, 60 ),
  19341. new THREE.Vector3( - 65.05889864636504, 117.99691802595966, 65.05889864636504 ),
  19342. new THREE.Vector3( 6.054276900088592, 78.7153118386369, - 6.054276900088592 ),
  19343. new THREE.Vector3( 64.9991491385602, 8.386980812799566, - 64.9991491385602 ),
  19344. new THREE.Vector3( 60, - 100, - 60 )
  19345. ];
  19346. var points = curve.getSpacedPoints();
  19347. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19348. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19349. } );
  19350. } );
  19351. } );
  19352. } );
  19353. /**
  19354. * @author TristanVALCKE / https://github.com/Itee
  19355. * @author moraxy / https://github.com/moraxy
  19356. */
  19357. /* global QUnit */
  19358. QUnit.module( 'Extras', () => {
  19359. QUnit.module( 'Curves', () => {
  19360. QUnit.module.todo( 'CubicBezierCurve', ( hooks ) => {
  19361. let curve = undefined;
  19362. hooks.before( function () {
  19363. curve = new CubicBezierCurve(
  19364. new Vector2( - 10, 0 ),
  19365. new Vector2( - 5, 15 ),
  19366. new Vector2( 20, 15 ),
  19367. new Vector2( 10, 0 )
  19368. );
  19369. } );
  19370. // INHERITANCE
  19371. QUnit.test( "Extending", ( assert ) => {
  19372. assert.ok( false, "everything's gonna be alright" );
  19373. } );
  19374. // INSTANCING
  19375. QUnit.test( "Instancing", ( assert ) => {
  19376. assert.ok( false, "everything's gonna be alright" );
  19377. } );
  19378. // PUBLIC STUFF
  19379. QUnit.test( "isCubicBezierCurve", ( assert ) => {
  19380. assert.ok( false, "everything's gonna be alright" );
  19381. } );
  19382. QUnit.test( "getPoint", ( assert ) => {
  19383. assert.ok( false, "everything's gonna be alright" );
  19384. } );
  19385. // OTHERS
  19386. QUnit.test( "Simple curve", ( assert ) => {
  19387. var expectedPoints = [
  19388. new Vector2( - 10, 0 ),
  19389. new Vector2( - 3.359375, 8.4375 ),
  19390. new Vector2( 5.625, 11.25 ),
  19391. new Vector2( 11.796875, 8.4375 ),
  19392. new Vector2( 10, 0 )
  19393. ];
  19394. var points = curve.getPoints( expectedPoints.length - 1 );
  19395. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19396. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19397. // symmetry
  19398. var curveRev = new CubicBezierCurve(
  19399. curve.v3, curve.v2, curve.v1, curve.v0
  19400. );
  19401. var points = curveRev.getPoints( expectedPoints.length - 1 );
  19402. assert.strictEqual( points.length, expectedPoints.length, "Reversed: Correct number of points" );
  19403. assert.deepEqual( points, expectedPoints.reverse(), "Reversed: Correct points curve" );
  19404. } );
  19405. QUnit.test( "getLength/getLengths", ( assert ) => {
  19406. var length = curve.getLength();
  19407. var expectedLength = 36.64630888504102;
  19408. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19409. var expectedLengths = [
  19410. 0,
  19411. 10.737285813492393,
  19412. 20.15159143794633,
  19413. 26.93408340370825,
  19414. 35.56079575637337
  19415. ];
  19416. var lengths = curve.getLengths( expectedLengths.length - 1 );
  19417. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19418. lengths.forEach( function ( segment, i ) {
  19419. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19420. } );
  19421. } );
  19422. QUnit.test( "getPointAt", ( assert ) => {
  19423. var expectedPoints = [
  19424. new Vector2( - 10, 0 ),
  19425. new Vector2( - 3.3188282598022596, 8.463722639089221 ),
  19426. new Vector2( 3.4718554735926617, 11.07899406116314 ),
  19427. new Vector2( 10, 0 )
  19428. ];
  19429. var points = [
  19430. curve.getPointAt( 0 ),
  19431. curve.getPointAt( 0.3 ),
  19432. curve.getPointAt( 0.5 ),
  19433. curve.getPointAt( 1 )
  19434. ];
  19435. assert.deepEqual( points, expectedPoints, "Correct points" );
  19436. } );
  19437. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  19438. var expectedTangents = [
  19439. new Vector2( 0.316370061632252, 0.9486358543207215 ),
  19440. new Vector2( 0.838961283088303, 0.5441911111721949 ),
  19441. new Vector2( 1, 0 ),
  19442. new Vector2( 0.47628313192245453, - 0.8792919755383518 ),
  19443. new Vector2( - 0.5546041767829665, - 0.8321142992972107 )
  19444. ];
  19445. var tangents = [
  19446. curve.getTangent( 0 ),
  19447. curve.getTangent( 0.25 ),
  19448. curve.getTangent( 0.5 ),
  19449. curve.getTangent( 0.75 ),
  19450. curve.getTangent( 1 )
  19451. ];
  19452. expectedTangents.forEach( function ( exp, i ) {
  19453. var tangent = tangents[ i ];
  19454. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  19455. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  19456. } );
  19457. //
  19458. var expectedTangents = [
  19459. new Vector2( 0.316370061632252, 0.9486358543207215 ),
  19460. new Vector2( 0.7794223085548987, 0.6264988945935596 ),
  19461. new Vector2( 0.988266153082452, 0.15274164681452052 ),
  19462. new Vector2( 0.5004110404199416, - 0.8657879593906534 ),
  19463. new Vector2( - 0.5546041767829665, - 0.8321142992972107 )
  19464. ];
  19465. var tangents = [
  19466. curve.getTangentAt( 0 ),
  19467. curve.getTangentAt( 0.25 ),
  19468. curve.getTangentAt( 0.5 ),
  19469. curve.getTangentAt( 0.75 ),
  19470. curve.getTangentAt( 1 )
  19471. ];
  19472. expectedTangents.forEach( function ( exp, i ) {
  19473. var tangent = tangents[ i ];
  19474. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  19475. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  19476. } );
  19477. } );
  19478. QUnit.test( "getUtoTmapping", ( assert ) => {
  19479. var start = curve.getUtoTmapping( 0, 0 );
  19480. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19481. var somewhere = curve.getUtoTmapping( 0.5, 1 );
  19482. var expectedSomewhere = 0.02130029182257093;
  19483. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19484. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19485. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 1 ) is correct" );
  19486. } );
  19487. QUnit.test( "getSpacedPoints", ( assert ) => {
  19488. var expectedPoints = [
  19489. new Vector2( - 10, 0 ),
  19490. new Vector2( - 6.16826457740703, 6.17025727295411 ),
  19491. new Vector2( - 0.058874033259857184, 10.1240558653185 ),
  19492. new Vector2( 7.123523032625162, 11.154913869041575 ),
  19493. new Vector2( 12.301846885754463, 6.808865855469985 ),
  19494. new Vector2( 10, 0 )
  19495. ];
  19496. var points = curve.getSpacedPoints();
  19497. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19498. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19499. } );
  19500. } );
  19501. } );
  19502. } );
  19503. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  19504. Curve.call( this );
  19505. this.type = 'CubicBezierCurve3';
  19506. this.v0 = v0 || new Vector3();
  19507. this.v1 = v1 || new Vector3();
  19508. this.v2 = v2 || new Vector3();
  19509. this.v3 = v3 || new Vector3();
  19510. }
  19511. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  19512. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  19513. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  19514. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19515. var point = optionalTarget || new Vector3();
  19516. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  19517. point.set(
  19518. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  19519. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  19520. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  19521. );
  19522. return point;
  19523. };
  19524. CubicBezierCurve3.prototype.copy = function ( source ) {
  19525. Curve.prototype.copy.call( this, source );
  19526. this.v0.copy( source.v0 );
  19527. this.v1.copy( source.v1 );
  19528. this.v2.copy( source.v2 );
  19529. this.v3.copy( source.v3 );
  19530. return this;
  19531. };
  19532. /**
  19533. * @author TristanVALCKE / https://github.com/Itee
  19534. * @author moraxy / https://github.com/moraxy
  19535. */
  19536. /* global QUnit */
  19537. QUnit.module( 'Extras', () => {
  19538. QUnit.module( 'Curves', () => {
  19539. QUnit.module.todo( 'CubicBezierCurve3', ( hooks ) => {
  19540. let curve = undefined;
  19541. hooks.before( function () {
  19542. curve = new CubicBezierCurve3(
  19543. new Vector3( - 10, 0, 2 ),
  19544. new Vector3( - 5, 15, 4 ),
  19545. new Vector3( 20, 15, - 5 ),
  19546. new Vector3( 10, 0, 10 )
  19547. );
  19548. } );
  19549. // INHERITANCE
  19550. QUnit.test( "Extending", ( assert ) => {
  19551. assert.ok( false, "everything's gonna be alright" );
  19552. } );
  19553. // INSTANCING
  19554. QUnit.test( "Instancing", ( assert ) => {
  19555. assert.ok( false, "everything's gonna be alright" );
  19556. } );
  19557. // PUBLIC STUFF
  19558. QUnit.test( "isCubicBezierCurve3", ( assert ) => {
  19559. assert.ok( false, "everything's gonna be alright" );
  19560. } );
  19561. QUnit.test( "getPoint", ( assert ) => {
  19562. assert.ok( false, "everything's gonna be alright" );
  19563. } );
  19564. // OTHERS
  19565. QUnit.test( "Simple curve", ( assert ) => {
  19566. var expectedPoints = [
  19567. new Vector3( - 10, 0, 2 ),
  19568. new Vector3( - 3.359375, 8.4375, 1.984375 ),
  19569. new Vector3( 5.625, 11.25, 1.125 ),
  19570. new Vector3( 11.796875, 8.4375, 2.703125 ),
  19571. new Vector3( 10, 0, 10 )
  19572. ];
  19573. var points = curve.getPoints( expectedPoints.length - 1 );
  19574. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19575. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19576. // symmetry
  19577. var curveRev = new CubicBezierCurve3(
  19578. curve.v3, curve.v2, curve.v1, curve.v0
  19579. );
  19580. points = curveRev.getPoints( expectedPoints.length - 1 );
  19581. assert.strictEqual( points.length, expectedPoints.length, "Reversed: Correct number of points" );
  19582. assert.deepEqual( points, expectedPoints.reverse(), "Reversed: Correct points curve" );
  19583. } );
  19584. QUnit.test( "getLength/getLengths", ( assert ) => {
  19585. var length = curve.getLength();
  19586. var expectedLength = 39.58103024989427;
  19587. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19588. var expectedLengths = [
  19589. 0,
  19590. 10.73729718231036,
  19591. 20.19074500737662,
  19592. 27.154413277853756,
  19593. 38.453287150114214
  19594. ];
  19595. var lengths = curve.getLengths( expectedLengths.length - 1 );
  19596. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19597. lengths.forEach( function ( segment, i ) {
  19598. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19599. } );
  19600. } );
  19601. QUnit.test( "getPointAt", ( assert ) => {
  19602. var expectedPoints = [
  19603. new Vector3( - 10, 0, 2 ),
  19604. new Vector3( - 2.591880240484318, 8.908333501170798, 1.8953420625251136 ),
  19605. new Vector3( 4.866251460832755, 11.22787914038507, 1.150832855206874 ),
  19606. new Vector3( 10, 0, 10 )
  19607. ];
  19608. var points = [
  19609. curve.getPointAt( 0 ),
  19610. curve.getPointAt( 0.3 ),
  19611. curve.getPointAt( 0.5 ),
  19612. curve.getPointAt( 1 )
  19613. ];
  19614. assert.deepEqual( points, expectedPoints, "Correct points" );
  19615. } );
  19616. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  19617. var expectedTangents = [
  19618. new Vector3( 0.3138715439944244, 0.9411440474105875, 0.12542940601858074 ),
  19619. new Vector3( 0.8351825262580098, 0.54174002562179, - 0.09480449605683638 ),
  19620. new Vector3( 0.9997531780538501, 0, - 0.02221672728433752 ),
  19621. new Vector3( 0.40693407933981185, - 0.7512629496079668, 0.5196235518317053 ),
  19622. new Vector3( - 0.42632467075185815, - 0.6396469221230213, 0.6396085444448543 )
  19623. ];
  19624. var tangents = [
  19625. curve.getTangent( 0 ),
  19626. curve.getTangent( 0.25 ),
  19627. curve.getTangent( 0.5 ),
  19628. curve.getTangent( 0.75 ),
  19629. curve.getTangent( 1 )
  19630. ];
  19631. expectedTangents.forEach( function ( exp, i ) {
  19632. var tangent = tangents[ i ];
  19633. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  19634. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  19635. } );
  19636. //
  19637. expectedTangents = [
  19638. new Vector3( 0.3138715439944244, 0.9411440474105875, 0.12542940601858074 ),
  19639. new Vector3( 0.8016539573770751, 0.5918626760037707, - 0.08396133262002324 ),
  19640. new Vector3( 0.997337559412928, 0.05740742907719314, - 0.044968652092444425 ),
  19641. new Vector3( 0.1389373097746809, - 0.7882209938358005, 0.5995032016837588 ),
  19642. new Vector3( - 0.42632467075185815, - 0.6396469221230213, 0.6396085444448543 )
  19643. ];
  19644. tangents = [
  19645. curve.getTangentAt( 0 ),
  19646. curve.getTangentAt( 0.25 ),
  19647. curve.getTangentAt( 0.5 ),
  19648. curve.getTangentAt( 0.75 ),
  19649. curve.getTangentAt( 1 )
  19650. ];
  19651. expectedTangents.forEach( function ( exp, i ) {
  19652. var tangent = tangents[ i ];
  19653. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  19654. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  19655. } );
  19656. } );
  19657. QUnit.test( "getUtoTmapping", ( assert ) => {
  19658. var start = curve.getUtoTmapping( 0, 0 );
  19659. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19660. var somewhere = curve.getUtoTmapping( 0.5, 1 );
  19661. var expectedSomewhere = 0.021163245321323316;
  19662. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19663. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19664. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 1 ) is correct" );
  19665. } );
  19666. QUnit.test( "getSpacedPoints", ( assert ) => {
  19667. var expectedPoints = [
  19668. new Vector3( - 10, 0, 2 ),
  19669. new Vector3( - 5.756524515061918, 6.568020242700483, 2.22116711170301 ),
  19670. new Vector3( 1.0003511895116906, 10.49656064587831, 1.4727101010850698 ),
  19671. new Vector3( 8.767656412295171, 10.784286845278622, 1.2873599519775174 ),
  19672. new Vector3( 12.306772513558396, 5.545103788071547, 4.909948454535794 ),
  19673. new Vector3( 10, 0, 10 )
  19674. ];
  19675. var points = curve.getSpacedPoints();
  19676. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19677. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19678. } );
  19679. QUnit.test( "computeFrenetFrames", ( assert ) => {
  19680. var expected = {
  19681. binormals: [
  19682. new Vector3( - 0.9486358543207215, 0.316370061632252, - 6.938893903907228e-18 ),
  19683. new Vector3( - 0.05491430765311864, 0.9969838307670049, 0.054842137122173326 ),
  19684. new Vector3( 0.5944656510461876, 0.334836503700931, 0.7310917216844742 )
  19685. ],
  19686. normals: [
  19687. new Vector3( 0.03968210891259515, 0.11898683173537697, - 0.9921025471723304 ),
  19688. new Vector3( - 0.047981365124836806, 0.05222670079466692, - 0.9974819097732357 ),
  19689. new Vector3( 0.6818048583242511, - 0.6919077473246573, - 0.23749906180354932 )
  19690. ],
  19691. tangents: [
  19692. new Vector3( 0.3138715439944244, 0.9411440474105875, 0.12542940601858074 ),
  19693. new Vector3( 0.9973375594129282, 0.05740742907719315, - 0.04496865209244443 ),
  19694. new Vector3( - 0.42632467075185815, - 0.6396469221230213, 0.6396085444448543 )
  19695. ]
  19696. };
  19697. var frames = curve.computeFrenetFrames( 2, false );
  19698. Object.keys( expected ).forEach( function ( group, i ) {
  19699. expected[ group ].forEach( function ( vec, j ) {
  19700. assert.numEqual( frames[ group ][ j ].x, vec.x, "Frenet frames [" + i + ", " + j + "].x correct" );
  19701. assert.numEqual( frames[ group ][ j ].y, vec.y, "Frenet frames [" + i + ", " + j + "].y correct" );
  19702. assert.numEqual( frames[ group ][ j ].z, vec.z, "Frenet frames [" + i + ", " + j + "].z correct" );
  19703. } );
  19704. } );
  19705. } );
  19706. } );
  19707. } );
  19708. } );
  19709. /**
  19710. * @author TristanVALCKE / https://github.com/Itee
  19711. */
  19712. /* global QUnit */
  19713. QUnit.module( 'Extras', () => {
  19714. QUnit.module( 'Curves', () => {
  19715. QUnit.module.todo( 'EllipseCurve', ( hooks ) => {
  19716. let curve = undefined;
  19717. hooks.before( function () {
  19718. curve = new EllipseCurve(
  19719. 0, 0, // ax, aY
  19720. 10, 10, // xRadius, yRadius
  19721. 0, 2 * Math.PI, // aStartAngle, aEndAngle
  19722. false, // aClockwise
  19723. 0 // aRotation
  19724. );
  19725. } );
  19726. // INHERITANCE
  19727. QUnit.test( "Extending", ( assert ) => {
  19728. assert.ok( false, "everything's gonna be alright" );
  19729. } );
  19730. // INSTANCING
  19731. QUnit.test( "Instancing", ( assert ) => {
  19732. assert.ok( false, "everything's gonna be alright" );
  19733. } );
  19734. // PUBLIC STUFF
  19735. QUnit.test( "isEllipseCurve", ( assert ) => {
  19736. assert.ok( false, "everything's gonna be alright" );
  19737. } );
  19738. QUnit.test( "getPoint", ( assert ) => {
  19739. assert.ok( false, "everything's gonna be alright" );
  19740. } );
  19741. // OTHERS
  19742. QUnit.test( "Simple curve", ( assert ) => {
  19743. var expectedPoints = [
  19744. new Vector2( 10, 0 ),
  19745. new Vector2( 0, 10 ),
  19746. new Vector2( - 10, 0 ),
  19747. new Vector2( 0, - 10 ),
  19748. new Vector2( 10, 0 )
  19749. ];
  19750. var points = curve.getPoints( expectedPoints.length - 1 );
  19751. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19752. points.forEach( function ( point, i ) {
  19753. assert.numEqual( point.x, expectedPoints[ i ].x, "point[" + i + "].x correct" );
  19754. assert.numEqual( point.y, expectedPoints[ i ].y, "point[" + i + "].y correct" );
  19755. } );
  19756. } );
  19757. QUnit.test( "getLength/getLengths", ( assert ) => {
  19758. var length = curve.getLength();
  19759. var expectedLength = 62.829269247282795;
  19760. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19761. var lengths = curve.getLengths( 5 );
  19762. var expectedLengths = [
  19763. 0,
  19764. 11.755705045849462,
  19765. 23.51141009169892,
  19766. 35.26711513754839,
  19767. 47.02282018339785,
  19768. 58.77852522924731
  19769. ];
  19770. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19771. lengths.forEach( function ( segment, i ) {
  19772. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19773. } );
  19774. } );
  19775. QUnit.test( "getPoint/getPointAt", ( assert ) => {
  19776. var testValues = [ 0, 0.3, 0.5, 0.7, 1 ];
  19777. testValues.forEach( function ( val, i ) {
  19778. var expectedX = Math.cos( val * Math.PI * 2 ) * 10;
  19779. var expectedY = Math.sin( val * Math.PI * 2 ) * 10;
  19780. var p = curve.getPoint( val );
  19781. var a = curve.getPointAt( val );
  19782. assert.numEqual( p.x, expectedX, "getPoint(" + val + ").x correct" );
  19783. assert.numEqual( p.y, expectedY, "getPoint(" + val + ").y correct" );
  19784. assert.numEqual( a.x, expectedX, "getPointAt(" + val + ").x correct" );
  19785. assert.numEqual( a.y, expectedY, "getPointAt(" + val + ").y correct" );
  19786. } );
  19787. } );
  19788. QUnit.test( "getTangent", ( assert ) => {
  19789. var expectedTangents = [
  19790. new Vector2( - 0.000314159260186071, 0.9999999506519786 ),
  19791. new Vector2( - 1, 0 ),
  19792. new Vector2( 0, - 1 ),
  19793. new Vector2( 1, 0 ),
  19794. new Vector2( 0.00031415926018600165, 0.9999999506519784 )
  19795. ];
  19796. var tangents = [
  19797. curve.getTangent( 0 ),
  19798. curve.getTangent( 0.25 ),
  19799. curve.getTangent( 0.5 ),
  19800. curve.getTangent( 0.75 ),
  19801. curve.getTangent( 1 )
  19802. ];
  19803. expectedTangents.forEach( function ( exp, i ) {
  19804. var tangent = tangents[ i ];
  19805. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  19806. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  19807. } );
  19808. } );
  19809. QUnit.test( "getUtoTmapping", ( assert ) => {
  19810. var start = curve.getUtoTmapping( 0, 0 );
  19811. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19812. var somewhere = curve.getUtoTmapping( 0.7, 1 );
  19813. var expectedSomewhere = 0.01591614882650014;
  19814. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19815. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19816. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.7, 1 ) is correct" );
  19817. } );
  19818. QUnit.test( "getSpacedPoints", ( assert ) => {
  19819. var expectedPoints = [
  19820. new Vector2( 10, 0 ),
  19821. new Vector2( 3.0901699437494603, 9.51056516295154 ),
  19822. new Vector2( - 8.090169943749492, 5.877852522924707 ),
  19823. new Vector2( - 8.090169943749459, - 5.877852522924751 ),
  19824. new Vector2( 3.0901699437494807, - 9.510565162951533 ),
  19825. new Vector2( 10, - 2.4492935982947065e-15 )
  19826. ];
  19827. var points = curve.getSpacedPoints();
  19828. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19829. expectedPoints.forEach( function ( exp, i ) {
  19830. var point = points[ i ];
  19831. assert.numEqual( point.x, exp.x, "Point #" + i + ": x correct" );
  19832. assert.numEqual( point.y, exp.y, "Point #" + i + ": y correct" );
  19833. } );
  19834. } );
  19835. } );
  19836. } );
  19837. } );
  19838. /**
  19839. * @author TristanVALCKE / https://github.com/Itee
  19840. */
  19841. /* global QUnit */
  19842. QUnit.module( 'Extras', () => {
  19843. QUnit.module( 'Curves', () => {
  19844. QUnit.module.todo( 'LineCurve', ( hooks ) => {
  19845. let _points = undefined;
  19846. let _curve = undefined;
  19847. hooks.before( function () {
  19848. _points = [
  19849. new Vector2( 0, 0 ),
  19850. new Vector2( 10, 10 ),
  19851. new Vector2( - 10, 10 ),
  19852. new Vector2( - 8, 5 )
  19853. ];
  19854. _curve = new LineCurve( _points[ 0 ], _points[ 1 ] );
  19855. } );
  19856. // INHERITANCE
  19857. QUnit.test( "Extending", ( assert ) => {
  19858. assert.ok( false, "everything's gonna be alright" );
  19859. } );
  19860. // INSTANCING
  19861. QUnit.test( "Instancing", ( assert ) => {
  19862. assert.ok( false, "everything's gonna be alright" );
  19863. } );
  19864. // PUBLIC STUFF
  19865. QUnit.test( "isLineCurve", ( assert ) => {
  19866. assert.ok( false, "everything's gonna be alright" );
  19867. } );
  19868. QUnit.test( "getPoint", ( assert ) => {
  19869. assert.ok( false, "everything's gonna be alright" );
  19870. } );
  19871. QUnit.test( "getPointAt", ( assert ) => {
  19872. var curve = new LineCurve( _points[ 0 ], _points[ 3 ] );
  19873. var expectedPoints = [
  19874. new Vector2( 0, 0 ),
  19875. new Vector2( - 2.4, 1.5 ),
  19876. new Vector2( - 4, 2.5 ),
  19877. new Vector2( - 8, 5 )
  19878. ];
  19879. var points = [
  19880. curve.getPointAt( 0 ),
  19881. curve.getPointAt( 0.3 ),
  19882. curve.getPointAt( 0.5 ),
  19883. curve.getPointAt( 1 )
  19884. ];
  19885. assert.deepEqual( points, expectedPoints, "Correct points" );
  19886. } );
  19887. QUnit.test( "getTangent", ( assert ) => {
  19888. var curve = _curve;
  19889. var tangent = curve.getTangent( 0 );
  19890. var expectedTangent = Math.sqrt( 0.5 );
  19891. assert.numEqual( tangent.x, expectedTangent, "tangent.x correct" );
  19892. assert.numEqual( tangent.y, expectedTangent, "tangent.y correct" );
  19893. } );
  19894. // OTHERS
  19895. QUnit.test( "Simple curve", ( assert ) => {
  19896. var curve = _curve;
  19897. var expectedPoints = [
  19898. new Vector2( 0, 0 ),
  19899. new Vector2( 2, 2 ),
  19900. new Vector2( 4, 4 ),
  19901. new Vector2( 6, 6 ),
  19902. new Vector2( 8, 8 ),
  19903. new Vector2( 10, 10 )
  19904. ];
  19905. var points = curve.getPoints();
  19906. assert.deepEqual( points, expectedPoints, "Correct points for first curve" );
  19907. //
  19908. curve = new LineCurve( _points[ 1 ], _points[ 2 ] );
  19909. expectedPoints = [
  19910. new Vector2( 10, 10 ),
  19911. new Vector2( 6, 10 ),
  19912. new Vector2( 2, 10 ),
  19913. new Vector2( - 2, 10 ),
  19914. new Vector2( - 6, 10 ),
  19915. new Vector2( - 10, 10 )
  19916. ];
  19917. points = curve.getPoints();
  19918. assert.deepEqual( points, expectedPoints, "Correct points for second curve" );
  19919. } );
  19920. QUnit.test( "getLength/getLengths", ( assert ) => {
  19921. var curve = _curve;
  19922. var length = curve.getLength();
  19923. var expectedLength = Math.sqrt( 200 );
  19924. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19925. var lengths = curve.getLengths( 5 );
  19926. var expectedLengths = [
  19927. 0.0,
  19928. Math.sqrt( 8 ),
  19929. Math.sqrt( 32 ),
  19930. Math.sqrt( 72 ),
  19931. Math.sqrt( 128 ),
  19932. Math.sqrt( 200 )
  19933. ];
  19934. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19935. lengths.forEach( function ( segment, i ) {
  19936. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19937. } );
  19938. } );
  19939. QUnit.test( "getUtoTmapping", ( assert ) => {
  19940. var curve = _curve;
  19941. var start = curve.getUtoTmapping( 0, 0 );
  19942. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19943. var somewhere = curve.getUtoTmapping( 0.3, 0 );
  19944. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19945. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19946. assert.numEqual( somewhere, 0.3, "getUtoTmapping( 0.3, 0 ) is correct" );
  19947. } );
  19948. QUnit.test( "getSpacedPoints", ( assert ) => {
  19949. var curve = _curve;
  19950. var expectedPoints = [
  19951. new Vector2( 0, 0 ),
  19952. new Vector2( 2.5, 2.5 ),
  19953. new Vector2( 5, 5 ),
  19954. new Vector2( 7.5, 7.5 ),
  19955. new Vector2( 10, 10 )
  19956. ];
  19957. var points = curve.getSpacedPoints( 4 );
  19958. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19959. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19960. } );
  19961. } );
  19962. } );
  19963. } );
  19964. function LineCurve3( v1, v2 ) {
  19965. Curve.call( this );
  19966. this.type = 'LineCurve3';
  19967. this.v1 = v1 || new Vector3();
  19968. this.v2 = v2 || new Vector3();
  19969. }
  19970. LineCurve3.prototype = Object.create( Curve.prototype );
  19971. LineCurve3.prototype.constructor = LineCurve3;
  19972. LineCurve3.prototype.isLineCurve3 = true;
  19973. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19974. var point = optionalTarget || new Vector3();
  19975. if ( t === 1 ) {
  19976. point.copy( this.v2 );
  19977. } else {
  19978. point.copy( this.v2 ).sub( this.v1 );
  19979. point.multiplyScalar( t ).add( this.v1 );
  19980. }
  19981. return point;
  19982. };
  19983. // Line curve is linear, so we can overwrite default getPointAt
  19984. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  19985. return this.getPoint( u, optionalTarget );
  19986. };
  19987. LineCurve3.prototype.copy = function ( source ) {
  19988. Curve.prototype.copy.call( this, source );
  19989. this.v1.copy( source.v1 );
  19990. this.v2.copy( source.v2 );
  19991. return this;
  19992. };
  19993. /**
  19994. * @author TristanVALCKE / https://github.com/Itee
  19995. */
  19996. /* global QUnit */
  19997. QUnit.module( 'Extras', () => {
  19998. QUnit.module( 'Curves', () => {
  19999. QUnit.module.todo( 'LineCurve3', ( hooks ) => {
  20000. let _points = undefined;
  20001. let _curve = undefined;
  20002. hooks.before( function () {
  20003. _points = [
  20004. new Vector3( 0, 0, 0 ),
  20005. new Vector3( 10, 10, 10 ),
  20006. new Vector3( - 10, 10, - 10 ),
  20007. new Vector3( - 8, 5, - 7 )
  20008. ];
  20009. _curve = new LineCurve3( _points[ 0 ], _points[ 1 ] );
  20010. } );
  20011. // INHERITANCE
  20012. QUnit.test( "Extending", ( assert ) => {
  20013. assert.ok( false, "everything's gonna be alright" );
  20014. } );
  20015. // INSTANCING
  20016. QUnit.test( "Instancing", ( assert ) => {
  20017. assert.ok( false, "everything's gonna be alright" );
  20018. } );
  20019. // PUBLIC STUFF
  20020. QUnit.test( "isCatmullRomCurve3", ( assert ) => {
  20021. assert.ok( false, "everything's gonna be alright" );
  20022. } );
  20023. QUnit.test( "getPoint", ( assert ) => {
  20024. assert.ok( false, "everything's gonna be alright" );
  20025. } );
  20026. QUnit.test( "getPointAt", ( assert ) => {
  20027. var curve = new LineCurve3( _points[ 0 ], _points[ 3 ] );
  20028. var expectedPoints = [
  20029. new Vector3( 0, 0, 0 ),
  20030. new Vector3( - 2.4, 1.5, - 2.1 ),
  20031. new Vector3( - 4, 2.5, - 3.5 ),
  20032. new Vector3( - 8, 5, - 7 )
  20033. ];
  20034. var points = [
  20035. curve.getPointAt( 0 ),
  20036. curve.getPointAt( 0.3 ),
  20037. curve.getPointAt( 0.5 ),
  20038. curve.getPointAt( 1 )
  20039. ];
  20040. assert.deepEqual( points, expectedPoints, "Correct getPointAt points" );
  20041. } );
  20042. // OTHERS
  20043. QUnit.test( "Simple curve", ( assert ) => {
  20044. var curve = _curve;
  20045. var expectedPoints = [
  20046. new Vector3( 0, 0, 0 ),
  20047. new Vector3( 2, 2, 2 ),
  20048. new Vector3( 4, 4, 4 ),
  20049. new Vector3( 6, 6, 6 ),
  20050. new Vector3( 8, 8, 8 ),
  20051. new Vector3( 10, 10, 10 )
  20052. ];
  20053. var points = curve.getPoints();
  20054. assert.deepEqual( points, expectedPoints, "Correct points for first curve" );
  20055. //
  20056. curve = new LineCurve3( _points[ 1 ], _points[ 2 ] );
  20057. expectedPoints = [
  20058. new Vector3( 10, 10, 10 ),
  20059. new Vector3( 6, 10, 6 ),
  20060. new Vector3( 2, 10, 2 ),
  20061. new Vector3( - 2, 10, - 2 ),
  20062. new Vector3( - 6, 10, - 6 ),
  20063. new Vector3( - 10, 10, - 10 )
  20064. ];
  20065. points = curve.getPoints();
  20066. assert.deepEqual( points, expectedPoints, "Correct points for second curve" );
  20067. } );
  20068. QUnit.test( "getLength/getLengths", ( assert ) => {
  20069. var curve = _curve;
  20070. var length = curve.getLength();
  20071. var expectedLength = Math.sqrt( 300 );
  20072. assert.numEqual( length, expectedLength, "Correct length of curve" );
  20073. var lengths = curve.getLengths( 5 );
  20074. var expectedLengths = [
  20075. 0.0,
  20076. Math.sqrt( 12 ),
  20077. Math.sqrt( 48 ),
  20078. Math.sqrt( 108 ),
  20079. Math.sqrt( 192 ),
  20080. Math.sqrt( 300 )
  20081. ];
  20082. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  20083. lengths.forEach( function ( segment, i ) {
  20084. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  20085. } );
  20086. } );
  20087. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  20088. var curve = _curve;
  20089. var tangent = curve.getTangent( 0.5 );
  20090. var expectedTangent = Math.sqrt( 1 / 3 );
  20091. assert.numEqual( tangent.x, expectedTangent, "tangent.x correct" );
  20092. assert.numEqual( tangent.y, expectedTangent, "tangent.y correct" );
  20093. assert.numEqual( tangent.z, expectedTangent, "tangent.z correct" );
  20094. tangent = curve.getTangentAt( 0.5 );
  20095. assert.numEqual( tangent.x, expectedTangent, "tangentAt.x correct" );
  20096. assert.numEqual( tangent.y, expectedTangent, "tangentAt.y correct" );
  20097. assert.numEqual( tangent.z, expectedTangent, "tangentAt.z correct" );
  20098. } );
  20099. QUnit.test( "computeFrenetFrames", ( assert ) => {
  20100. var curve = _curve;
  20101. var expected = {
  20102. binormals: new Vector3( - 0.5 * Math.sqrt( 2 ), 0.5 * Math.sqrt( 2 ), 0 ),
  20103. normals: new Vector3( Math.sqrt( 1 / 6 ), Math.sqrt( 1 / 6 ), - Math.sqrt( 2 / 3 ) ),
  20104. tangents: new Vector3( Math.sqrt( 1 / 3 ), Math.sqrt( 1 / 3 ), Math.sqrt( 1 / 3 ) )
  20105. };
  20106. var frames = curve.computeFrenetFrames( 1, false );
  20107. for ( var val in expected ) {
  20108. assert.numEqual( frames[ val ][ 0 ].x, expected[ val ].x, "Frenet frames " + val + ".x correct" );
  20109. assert.numEqual( frames[ val ][ 0 ].y, expected[ val ].y, "Frenet frames " + val + ".y correct" );
  20110. assert.numEqual( frames[ val ][ 0 ].z, expected[ val ].z, "Frenet frames " + val + ".z correct" );
  20111. }
  20112. } );
  20113. QUnit.test( "getUtoTmapping", ( assert ) => {
  20114. var curve = _curve;
  20115. var start = curve.getUtoTmapping( 0, 0 );
  20116. var end = curve.getUtoTmapping( 0, curve.getLength() );
  20117. var somewhere = curve.getUtoTmapping( 0.7, 0 );
  20118. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  20119. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  20120. assert.numEqual( somewhere, 0.7, "getUtoTmapping( 0.7, 0 ) is correct" );
  20121. } );
  20122. QUnit.test( "getSpacedPoints", ( assert ) => {
  20123. var curve = _curve;
  20124. var expectedPoints = [
  20125. new Vector3( 0, 0, 0 ),
  20126. new Vector3( 2.5, 2.5, 2.5 ),
  20127. new Vector3( 5, 5, 5 ),
  20128. new Vector3( 7.5, 7.5, 7.5 ),
  20129. new Vector3( 10, 10, 10 )
  20130. ];
  20131. var points = curve.getSpacedPoints( 4 );
  20132. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  20133. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  20134. } );
  20135. } );
  20136. } );
  20137. } );
  20138. /**
  20139. * @author TristanVALCKE / https://github.com/Itee
  20140. */
  20141. /* global QUnit */
  20142. QUnit.module( 'Extras', () => {
  20143. QUnit.module( 'Curves', () => {
  20144. QUnit.module.todo( 'QuadraticBezierCurve', ( hooks ) => {
  20145. let _curve = undefined;
  20146. hooks.before( function () {
  20147. _curve = new QuadraticBezierCurve(
  20148. new Vector2( - 10, 0 ),
  20149. new Vector2( 20, 15 ),
  20150. new Vector2( 10, 0 )
  20151. );
  20152. } );
  20153. // INHERITANCE
  20154. QUnit.test( "Extending", ( assert ) => {
  20155. assert.ok( false, "everything's gonna be alright" );
  20156. } );
  20157. // INSTANCING
  20158. QUnit.test( "Instancing", ( assert ) => {
  20159. assert.ok( false, "everything's gonna be alright" );
  20160. } );
  20161. // PUBLIC STUFF
  20162. QUnit.test( "isQuadraticBezierCurve", ( assert ) => {
  20163. assert.ok( false, "everything's gonna be alright" );
  20164. } );
  20165. QUnit.test( "getPoint", ( assert ) => {
  20166. assert.ok( false, "everything's gonna be alright" );
  20167. } );
  20168. // OTHERS
  20169. QUnit.test( "Simple curve", ( assert ) => {
  20170. var curve = _curve;
  20171. var expectedPoints = [
  20172. new Vector2( - 10, 0 ),
  20173. new Vector2( 2.5, 5.625 ),
  20174. new Vector2( 10, 7.5 ),
  20175. new Vector2( 12.5, 5.625 ),
  20176. new Vector2( 10, 0 )
  20177. ];
  20178. var points = curve.getPoints( expectedPoints.length - 1 );
  20179. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  20180. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  20181. // symmetry
  20182. var curveRev = new QuadraticBezierCurve(
  20183. curve.v2, curve.v1, curve.v0
  20184. );
  20185. points = curveRev.getPoints( expectedPoints.length - 1 );
  20186. assert.strictEqual( points.length, expectedPoints.length, "Reversed: Correct number of points" );
  20187. assert.deepEqual( points, expectedPoints.reverse(), "Reversed: Correct points curve" );
  20188. } );
  20189. QUnit.test( "getLength/getLengths", ( assert ) => {
  20190. var curve = _curve;
  20191. var length = curve.getLength();
  20192. var expectedLength = 31.269026549416683;
  20193. assert.numEqual( length, expectedLength, "Correct length of curve" );
  20194. var expectedLengths = [
  20195. 0,
  20196. 13.707320124663317,
  20197. 21.43814317269643,
  20198. 24.56314317269643,
  20199. 30.718679298818998
  20200. ];
  20201. var lengths = curve.getLengths( expectedLengths.length - 1 );
  20202. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  20203. lengths.forEach( function ( segment, i ) {
  20204. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  20205. } );
  20206. } );
  20207. QUnit.test( "getPointAt", ( assert ) => {
  20208. var curve = _curve;
  20209. var expectedPoints = [
  20210. new Vector2( - 10, 0 ),
  20211. new Vector2( - 1.5127849599387615, 3.993582003773624 ),
  20212. new Vector2( 4.310076165722796, 6.269921971403917 ),
  20213. new Vector2( 10, 0 )
  20214. ];
  20215. var points = [
  20216. curve.getPointAt( 0 ),
  20217. curve.getPointAt( 0.3 ),
  20218. curve.getPointAt( 0.5 ),
  20219. curve.getPointAt( 1 )
  20220. ];
  20221. assert.deepEqual( points, expectedPoints, "Correct points" );
  20222. } );
  20223. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  20224. var curve = _curve;
  20225. var expectedTangents = [
  20226. new Vector2( 0.89443315420562, 0.44720166888975904 ),
  20227. new Vector2( 0.936329177569021, 0.3511234415884543 ),
  20228. new Vector2( 1, 0 ),
  20229. new Vector2( - 5.921189464667277e-13, - 1 ),
  20230. new Vector2( - 0.5546617882904897, - 0.8320758983472577 )
  20231. ];
  20232. var tangents = [
  20233. curve.getTangent( 0 ),
  20234. curve.getTangent( 0.25 ),
  20235. curve.getTangent( 0.5 ),
  20236. curve.getTangent( 0.75 ),
  20237. curve.getTangent( 1 )
  20238. ];
  20239. expectedTangents.forEach( function ( exp, i ) {
  20240. var tangent = tangents[ i ];
  20241. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  20242. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  20243. } );
  20244. //
  20245. expectedTangents = [
  20246. new Vector2( 0.89443315420562, 0.44720166888975904 ),
  20247. new Vector2( 0.9125211423360805, 0.40902954024086674 ),
  20248. new Vector2( 0.9480289098765387, 0.3181842014278863 ),
  20249. new Vector2( 0.7969127189169473, - 0.6040944615111106 ),
  20250. new Vector2( - 0.5546617882904897, - 0.8320758983472577 )
  20251. ];
  20252. tangents = [
  20253. curve.getTangentAt( 0 ),
  20254. curve.getTangentAt( 0.25 ),
  20255. curve.getTangentAt( 0.5 ),
  20256. curve.getTangentAt( 0.75 ),
  20257. curve.getTangentAt( 1 )
  20258. ];
  20259. expectedTangents.forEach( function ( exp, i ) {
  20260. var tangent = tangents[ i ];
  20261. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  20262. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  20263. } );
  20264. } );
  20265. QUnit.test( "getUtoTmapping", ( assert ) => {
  20266. var curve = _curve;
  20267. var start = curve.getUtoTmapping( 0, 0 );
  20268. var end = curve.getUtoTmapping( 0, curve.getLength() );
  20269. var somewhere = curve.getUtoTmapping( 0.5, 1 );
  20270. var expectedSomewhere = 0.015073978276116116;
  20271. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  20272. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  20273. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 1 ) is correct" );
  20274. } );
  20275. QUnit.test( "getSpacedPoints", ( assert ) => {
  20276. var curve = _curve;
  20277. var expectedPoints = [
  20278. new Vector2( - 10, 0 ),
  20279. new Vector2( - 4.366603655406173, 2.715408933540383 ),
  20280. new Vector2( 1.3752241477827831, 5.191972084404416 ),
  20281. new Vector2( 7.312990279153634, 7.136310044848586 ),
  20282. new Vector2( 12.499856644824826, 5.653289188715387 ),
  20283. new Vector2( 10, 0 )
  20284. ];
  20285. var points = curve.getSpacedPoints();
  20286. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  20287. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  20288. } );
  20289. } );
  20290. } );
  20291. } );
  20292. function QuadraticBezierCurve3( v0, v1, v2 ) {
  20293. Curve.call( this );
  20294. this.type = 'QuadraticBezierCurve3';
  20295. this.v0 = v0 || new Vector3();
  20296. this.v1 = v1 || new Vector3();
  20297. this.v2 = v2 || new Vector3();
  20298. }
  20299. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  20300. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  20301. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  20302. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  20303. var point = optionalTarget || new Vector3();
  20304. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  20305. point.set(
  20306. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  20307. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  20308. QuadraticBezier( t, v0.z, v1.z, v2.z )
  20309. );
  20310. return point;
  20311. };
  20312. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  20313. Curve.prototype.copy.call( this, source );
  20314. this.v0.copy( source.v0 );
  20315. this.v1.copy( source.v1 );
  20316. this.v2.copy( source.v2 );
  20317. return this;
  20318. };
  20319. /**
  20320. * @author TristanVALCKE / https://github.com/Itee
  20321. */
  20322. /* global QUnit */
  20323. QUnit.module( 'Extras', () => {
  20324. QUnit.module( 'Curves', () => {
  20325. QUnit.module.todo( 'QuadraticBezierCurve3', ( hooks ) => {
  20326. let _curve = undefined;
  20327. hooks.before( function () {
  20328. _curve = new QuadraticBezierCurve3(
  20329. new Vector3( - 10, 0, 2 ),
  20330. new Vector3( 20, 15, - 5 ),
  20331. new Vector3( 10, 0, 10 )
  20332. );
  20333. } );
  20334. // INHERITANCE
  20335. QUnit.test( "Extending", ( assert ) => {
  20336. assert.ok( false, "everything's gonna be alright" );
  20337. } );
  20338. // INSTANCING
  20339. QUnit.test( "Instancing", ( assert ) => {
  20340. assert.ok( false, "everything's gonna be alright" );
  20341. } );
  20342. // PUBLIC STUFF
  20343. QUnit.test( "isQuadraticBezierCurve3", ( assert ) => {
  20344. assert.ok( false, "everything's gonna be alright" );
  20345. } );
  20346. QUnit.test( "getPoint", ( assert ) => {
  20347. assert.ok( false, "everything's gonna be alright" );
  20348. } );
  20349. // OTHERS
  20350. QUnit.test( "Simple curve", ( assert ) => {
  20351. var curve = _curve;
  20352. var expectedPoints = [
  20353. new Vector3( - 10, 0, 2 ),
  20354. new Vector3( 2.5, 5.625, - 0.125 ),
  20355. new Vector3( 10, 7.5, 0.5 ),
  20356. new Vector3( 12.5, 5.625, 3.875 ),
  20357. new Vector3( 10, 0, 10 )
  20358. ];
  20359. var points = curve.getPoints( expectedPoints.length - 1 );
  20360. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  20361. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  20362. // symmetry
  20363. var curveRev = new QuadraticBezierCurve3(
  20364. curve.v2, curve.v1, curve.v0
  20365. );
  20366. points = curveRev.getPoints( expectedPoints.length - 1 );
  20367. assert.strictEqual( points.length, expectedPoints.length, "Reversed: Correct number of points" );
  20368. assert.deepEqual( points, expectedPoints.reverse(), "Reversed: Correct points curve" );
  20369. } );
  20370. QUnit.test( "getLength/getLengths", ( assert ) => {
  20371. var curve = _curve;
  20372. var length = curve.getLength();
  20373. var expectedLength = 35.47294274967861;
  20374. assert.numEqual( length, expectedLength, "Correct length of curve" );
  20375. var expectedLengths = [
  20376. 0,
  20377. 13.871057998581074,
  20378. 21.62710402732536,
  20379. 26.226696400568883,
  20380. 34.91037361704809
  20381. ];
  20382. var lengths = curve.getLengths( expectedLengths.length - 1 );
  20383. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  20384. lengths.forEach( function ( segment, i ) {
  20385. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  20386. } );
  20387. } );
  20388. QUnit.test( "getPointAt", ( assert ) => {
  20389. var curve = _curve;
  20390. var expectedPoints = [
  20391. new Vector3( - 10, 0, 2 ),
  20392. new Vector3( - 0.4981634504454243, 4.427089043881476, 0.19308849757196012 ),
  20393. new Vector3( 6.149415812887238, 6.838853310980195, - 0.20278120208668637 ),
  20394. new Vector3( 10, 0, 10 )
  20395. ];
  20396. var points = [
  20397. curve.getPointAt( 0 ),
  20398. curve.getPointAt( 0.3 ),
  20399. curve.getPointAt( 0.5 ),
  20400. curve.getPointAt( 1 )
  20401. ];
  20402. assert.deepEqual( points, expectedPoints, "Correct points" );
  20403. } );
  20404. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  20405. var curve = _curve;
  20406. var expectedTangents = [
  20407. new Vector3( 0.8755715084258769, 0.4377711603816079, - 0.2042815331129452 ),
  20408. new Vector3( 0.9340289249885844, 0.3502608468707904, - 0.07005216937416067 ),
  20409. new Vector3( 0.9284766908853163, 0, 0.37139067635396156 ),
  20410. new Vector3( - 3.669031233375946e-13, - 0.6196442885791218, 0.7848827655333463 ),
  20411. new Vector3( - 0.4263618889888853, - 0.6396068005601663, 0.6396238584473043 )
  20412. ];
  20413. var tangents = [
  20414. curve.getTangent( 0 ),
  20415. curve.getTangent( 0.25 ),
  20416. curve.getTangent( 0.5 ),
  20417. curve.getTangent( 0.75 ),
  20418. curve.getTangent( 1 )
  20419. ];
  20420. expectedTangents.forEach( function ( exp, i ) {
  20421. var tangent = tangents[ i ];
  20422. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  20423. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  20424. } );
  20425. //
  20426. expectedTangents = [
  20427. new Vector3( 0.8755715084258769, 0.4377711603816079, - 0.2042815331129452 ),
  20428. new Vector3( 0.9060725703490549, 0.3984742932857448, - 0.14230507668907377 ),
  20429. new Vector3( 0.9621604167456882, 0.2688562845452628, 0.044312872940942424 ),
  20430. new Vector3( 0.016586454041780826, - 0.6163270940470614, 0.7873155674098058 ),
  20431. new Vector3( - 0.4263618889888853, - 0.6396068005601663, 0.6396238584473043 )
  20432. ];
  20433. tangents = [
  20434. curve.getTangentAt( 0 ),
  20435. curve.getTangentAt( 0.25 ),
  20436. curve.getTangentAt( 0.5 ),
  20437. curve.getTangentAt( 0.75 ),
  20438. curve.getTangentAt( 1 )
  20439. ];
  20440. expectedTangents.forEach( function ( exp, i ) {
  20441. var tangent = tangents[ i ];
  20442. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  20443. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  20444. } );
  20445. } );
  20446. QUnit.test( "getUtoTmapping", ( assert ) => {
  20447. var curve = _curve;
  20448. var start = curve.getUtoTmapping( 0, 0 );
  20449. var end = curve.getUtoTmapping( 0, curve.getLength() );
  20450. var somewhere = curve.getUtoTmapping( 0.5, 1 );
  20451. var expectedSomewhere = 0.014760890927167196;
  20452. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  20453. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  20454. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 1 ) is correct" );
  20455. } );
  20456. QUnit.test( "getSpacedPoints", ( assert ) => {
  20457. var curve = _curve;
  20458. var expectedPoints = [
  20459. new Vector3( - 10, 0, 2 ),
  20460. new Vector3( - 3.712652983516992, 3.015179001762753, 0.6957120710270492 ),
  20461. new Vector3( 2.7830973773262975, 5.730399338061483, - 0.1452668772806931 ),
  20462. new Vector3( 9.575825284074465, 7.48754187603603, 0.3461104039841496 ),
  20463. new Vector3( 12.345199937734154, 4.575759904730531, 5.142117429101656 ),
  20464. new Vector3( 10, 0, 10 )
  20465. ];
  20466. var points = curve.getSpacedPoints();
  20467. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  20468. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  20469. } );
  20470. QUnit.test( "computeFrenetFrames", ( assert ) => {
  20471. var curve = _curve;
  20472. var expected = {
  20473. binormals: [
  20474. new Vector3( - 0.447201668889759, 0.8944331542056199, 0 ),
  20475. new Vector3( - 0.2684231751110917, 0.9631753839815436, - 0.01556209353802903 ),
  20476. new Vector3( 0.3459273556592433, 0.53807011680075, 0.7686447905324219 )
  20477. ],
  20478. normals: [
  20479. new Vector3( - 0.18271617600817133, - 0.09135504253146765, - 0.9789121795283909 ),
  20480. new Vector3( 0.046865035058597876, - 0.003078628350883253, - 0.9988964863970807 ),
  20481. new Vector3( 0.8357929194629689, - 0.5489842348221077, 0.008155102228190641 )
  20482. ],
  20483. tangents: [
  20484. new Vector3( 0.8755715084258767, 0.4377711603816078, - 0.20428153311294514 ),
  20485. new Vector3( 0.9621604167456884, 0.26885628454526284, 0.04431287294094243 ),
  20486. new Vector3( - 0.4263618889888853, - 0.6396068005601663, 0.6396238584473043 )
  20487. ]
  20488. };
  20489. var frames = curve.computeFrenetFrames( 2, false );
  20490. Object.keys( expected ).forEach( function ( group, i ) {
  20491. expected[ group ].forEach( function ( vec, j ) {
  20492. assert.numEqual( frames[ group ][ j ].x, vec.x, "Frenet frames [" + i + ", " + j + "].x correct" );
  20493. assert.numEqual( frames[ group ][ j ].y, vec.y, "Frenet frames [" + i + ", " + j + "].y correct" );
  20494. assert.numEqual( frames[ group ][ j ].z, vec.z, "Frenet frames [" + i + ", " + j + "].z correct" );
  20495. } );
  20496. } );
  20497. } );
  20498. } );
  20499. } );
  20500. } );
  20501. /**
  20502. * @author TristanVALCKE / https://github.com/Itee
  20503. */
  20504. /* global QUnit */
  20505. QUnit.module( 'Extras', () => {
  20506. QUnit.module( 'Curves', () => {
  20507. QUnit.module.todo( 'SplineCurve', ( hooks ) => {
  20508. let _curve = undefined;
  20509. hooks.before( function () {
  20510. _curve = new SplineCurve( [
  20511. new Vector2( - 10, 0 ),
  20512. new Vector2( - 5, 5 ),
  20513. new Vector2( 0, 0 ),
  20514. new Vector2( 5, - 5 ),
  20515. new Vector2( 10, 0 )
  20516. ] );
  20517. } );
  20518. // INHERITANCE
  20519. QUnit.test( "Extending", ( assert ) => {
  20520. assert.ok( false, "everything's gonna be alright" );
  20521. } );
  20522. // INSTANCING
  20523. QUnit.test( "Instancing", ( assert ) => {
  20524. assert.ok( false, "everything's gonna be alright" );
  20525. } );
  20526. // PUBLIC STUFF
  20527. QUnit.test( "isSplineCurve", ( assert ) => {
  20528. assert.ok( false, "everything's gonna be alright" );
  20529. } );
  20530. QUnit.test( "getPoint", ( assert ) => {
  20531. assert.ok( false, "everything's gonna be alright" );
  20532. } );
  20533. // OTHERS
  20534. QUnit.test( "Simple curve", ( assert ) => {
  20535. var curve = _curve;
  20536. var expectedPoints = [
  20537. new Vector2( - 10, 0 ),
  20538. new Vector2( - 6.08, 4.56 ),
  20539. new Vector2( - 2, 2.48 ),
  20540. new Vector2( 2, - 2.48 ),
  20541. new Vector2( 6.08, - 4.56 ),
  20542. new Vector2( 10, 0 )
  20543. ];
  20544. var points = curve.getPoints( 5 );
  20545. assert.strictEqual( points.length, expectedPoints.length, "1st: Correct number of points" );
  20546. points.forEach( function ( point, i ) {
  20547. assert.numEqual( point.x, expectedPoints[ i ].x, "points[" + i + "].x" );
  20548. assert.numEqual( point.y, expectedPoints[ i ].y, "points[" + i + "].y" );
  20549. } );
  20550. //
  20551. points = curve.getPoints( 4 );
  20552. assert.deepEqual( points, curve.points, "2nd: Returned points are identical to control points" );
  20553. } );
  20554. QUnit.test( "getLength/getLengths", ( assert ) => {
  20555. var curve = _curve;
  20556. var length = curve.getLength();
  20557. var expectedLength = 28.876950901868135;
  20558. assert.numEqual( length, expectedLength, "Correct length of curve" );
  20559. var expectedLengths = [
  20560. 0.0,
  20561. Math.sqrt( 50 ),
  20562. Math.sqrt( 200 ),
  20563. Math.sqrt( 450 ),
  20564. Math.sqrt( 800 )
  20565. ];
  20566. var lengths = curve.getLengths( 4 );
  20567. assert.deepEqual( lengths, expectedLengths, "Correct segment lengths" );
  20568. } );
  20569. QUnit.test( "getPointAt", ( assert ) => {
  20570. var curve = _curve;
  20571. assert.ok( curve.getPointAt( 0 ).equals( curve.points[ 0 ] ), "PointAt 0.0 correct" );
  20572. assert.ok( curve.getPointAt( 1 ).equals( curve.points[ 4 ] ), "PointAt 1.0 correct" );
  20573. var pointAt = curve.getPointAt( 0.5 );
  20574. assert.numEqual( pointAt.x, 0.0, "PointAt 0.5 x correct" );
  20575. assert.numEqual( pointAt.y, 0.0, "PointAt 0.5 y correct" );
  20576. } );
  20577. QUnit.test( "getTangent", ( assert ) => {
  20578. var curve = _curve;
  20579. var expectedTangent = [
  20580. new Vector2( 0.7068243340243188, 0.7073891155729485 ), // 0
  20581. new Vector2( 0.7069654305325396, - 0.7072481035902046 ), // 0.5
  20582. new Vector2( 0.7068243340245123, 0.7073891155727552 ) // 1
  20583. ];
  20584. var tangents = [
  20585. curve.getTangent( 0 ),
  20586. curve.getTangent( 0.5 ),
  20587. curve.getTangent( 1 )
  20588. ];
  20589. tangents.forEach( function ( tangent, i ) {
  20590. assert.numEqual( tangent.x, expectedTangent[ i ].x, "tangent[" + i + "].x" );
  20591. assert.numEqual( tangent.y, expectedTangent[ i ].y, "tangent[" + i + "].y" );
  20592. } );
  20593. } );
  20594. QUnit.test( "getUtoTmapping", ( assert ) => {
  20595. var curve = _curve;
  20596. var start = curve.getUtoTmapping( 0, 0 );
  20597. var end = curve.getUtoTmapping( 0, curve.getLength() );
  20598. var middle = curve.getUtoTmapping( 0.5, 0 );
  20599. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  20600. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  20601. assert.numEqual( middle, 0.5, "getUtoTmapping( 0.5, 0 ) is the middle" );
  20602. } );
  20603. QUnit.test( "getSpacedPoints", ( assert ) => {
  20604. var curve = _curve;
  20605. var expectedPoints = [
  20606. new Vector2( - 10, 0 ),
  20607. new Vector2( - 4.996509634683014, 4.999995128640857 ),
  20608. new Vector2( 0, 0 ),
  20609. new Vector2( 4.996509634683006, - 4.999995128640857 ),
  20610. new Vector2( 10, 0 )
  20611. ];
  20612. var points = curve.getSpacedPoints( 4 );
  20613. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  20614. points.forEach( function ( point, i ) {
  20615. assert.numEqual( point.x, expectedPoints[ i ].x, "points[" + i + "].x" );
  20616. assert.numEqual( point.y, expectedPoints[ i ].y, "points[" + i + "].y" );
  20617. } );
  20618. } );
  20619. } );
  20620. } );
  20621. } );
  20622. /**
  20623. * @author TristanVALCKE / https://github.com/Itee
  20624. */
  20625. /* global QUnit */
  20626. QUnit.module( 'Extras', () => {
  20627. QUnit.module( 'Objects', () => {
  20628. QUnit.module.todo( 'ImmediateRenderObject', () => {
  20629. // INHERITANCE
  20630. QUnit.test( "Extending", ( assert ) => {
  20631. assert.ok( false, "everything's gonna be alright" );
  20632. } );
  20633. // INSTANCING
  20634. QUnit.test( "Instancing", ( assert ) => {
  20635. assert.ok( false, "everything's gonna be alright" );
  20636. } );
  20637. // PUBLIC STUFF
  20638. QUnit.test( "isImmediateRenderObject", ( assert ) => {
  20639. assert.ok( false, "everything's gonna be alright" );
  20640. } );
  20641. } );
  20642. } );
  20643. } );
  20644. /**
  20645. * @author TristanVALCKE / https://github.com/Itee
  20646. * @author Anonymous
  20647. */
  20648. /* global QUnit */
  20649. QUnit.module( 'Geometries', () => {
  20650. QUnit.module.todo( 'BoxGeometry', ( hooks ) => {
  20651. var geometries = undefined;
  20652. hooks.beforeEach( function () {
  20653. const parameters = {
  20654. width: 10,
  20655. height: 20,
  20656. depth: 30,
  20657. widthSegments: 2,
  20658. heightSegments: 3,
  20659. depthSegments: 4
  20660. };
  20661. geometries = [
  20662. new BoxGeometry(),
  20663. new BoxGeometry( parameters.width, parameters.height, parameters.depth ),
  20664. new BoxGeometry( parameters.width, parameters.height, parameters.depth, parameters.widthSegments, parameters.heightSegments, parameters.depthSegments )
  20665. ];
  20666. } );
  20667. // INHERITANCE
  20668. QUnit.test( "Extending", ( assert ) => {
  20669. assert.ok( false, "everything's gonna be alright" );
  20670. } );
  20671. // INSTANCING
  20672. QUnit.test( "Instancing", ( assert ) => {
  20673. assert.ok( false, "everything's gonna be alright" );
  20674. } );
  20675. // OTHERS
  20676. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20677. runStdGeometryTests( assert, geometries );
  20678. } );
  20679. } );
  20680. QUnit.module.todo( 'BoxBufferGeometry', ( hooks ) => {
  20681. var geometries = undefined;
  20682. hooks.beforeEach( function () {
  20683. const parameters = {
  20684. width: 10,
  20685. height: 20,
  20686. depth: 30,
  20687. widthSegments: 2,
  20688. heightSegments: 3,
  20689. depthSegments: 4
  20690. };
  20691. geometries = [
  20692. new BoxBufferGeometry(),
  20693. new BoxBufferGeometry( parameters.width, parameters.height, parameters.depth ),
  20694. new BoxBufferGeometry( parameters.width, parameters.height, parameters.depth, parameters.widthSegments, parameters.heightSegments, parameters.depthSegments )
  20695. ];
  20696. } );
  20697. // INHERITANCE
  20698. QUnit.test( "Extending", ( assert ) => {
  20699. assert.ok( false, "everything's gonna be alright" );
  20700. } );
  20701. // INSTANCING
  20702. QUnit.test( "Instancing", ( assert ) => {
  20703. assert.ok( false, "everything's gonna be alright" );
  20704. } );
  20705. // OTHERS
  20706. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20707. runStdGeometryTests( assert, geometries );
  20708. } );
  20709. } );
  20710. } );
  20711. /**
  20712. * @author benaadams / https://twitter.com/ben_a_adams
  20713. * @author Mugen87 / https://github.com/Mugen87
  20714. * @author hughes
  20715. */
  20716. // CircleGeometry
  20717. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  20718. Geometry.call( this );
  20719. this.type = 'CircleGeometry';
  20720. this.parameters = {
  20721. radius: radius,
  20722. segments: segments,
  20723. thetaStart: thetaStart,
  20724. thetaLength: thetaLength
  20725. };
  20726. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  20727. this.mergeVertices();
  20728. }
  20729. CircleGeometry.prototype = Object.create( Geometry.prototype );
  20730. CircleGeometry.prototype.constructor = CircleGeometry;
  20731. // CircleBufferGeometry
  20732. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  20733. BufferGeometry.call( this );
  20734. this.type = 'CircleBufferGeometry';
  20735. this.parameters = {
  20736. radius: radius,
  20737. segments: segments,
  20738. thetaStart: thetaStart,
  20739. thetaLength: thetaLength
  20740. };
  20741. radius = radius || 1;
  20742. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  20743. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  20744. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  20745. // buffers
  20746. var indices = [];
  20747. var vertices = [];
  20748. var normals = [];
  20749. var uvs = [];
  20750. // helper variables
  20751. var i, s;
  20752. var vertex = new Vector3();
  20753. var uv = new Vector2();
  20754. // center point
  20755. vertices.push( 0, 0, 0 );
  20756. normals.push( 0, 0, 1 );
  20757. uvs.push( 0.5, 0.5 );
  20758. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  20759. var segment = thetaStart + s / segments * thetaLength;
  20760. // vertex
  20761. vertex.x = radius * Math.cos( segment );
  20762. vertex.y = radius * Math.sin( segment );
  20763. vertices.push( vertex.x, vertex.y, vertex.z );
  20764. // normal
  20765. normals.push( 0, 0, 1 );
  20766. // uvs
  20767. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  20768. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  20769. uvs.push( uv.x, uv.y );
  20770. }
  20771. // indices
  20772. for ( i = 1; i <= segments; i ++ ) {
  20773. indices.push( i, i + 1, 0 );
  20774. }
  20775. // build geometry
  20776. this.setIndex( indices );
  20777. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20778. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  20779. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  20780. }
  20781. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  20782. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  20783. /**
  20784. * @author TristanVALCKE / https://github.com/Itee
  20785. * @author Anonymous
  20786. */
  20787. /* global QUnit */
  20788. QUnit.module( 'Geometries', () => {
  20789. QUnit.module.todo( 'CircleGeometry', ( hooks ) => {
  20790. var geometries = undefined;
  20791. hooks.beforeEach( function () {
  20792. const parameters = {
  20793. radius: 10,
  20794. segments: 20,
  20795. thetaStart: 0.1,
  20796. thetaLength: 0.2
  20797. };
  20798. geometries = [
  20799. new CircleGeometry(),
  20800. new CircleGeometry( parameters.radius ),
  20801. new CircleGeometry( parameters.radius, parameters.segments ),
  20802. new CircleGeometry( parameters.radius, parameters.segments, parameters.thetaStart ),
  20803. new CircleGeometry( parameters.radius, parameters.segments, parameters.thetaStart, parameters.thetaLength ),
  20804. ];
  20805. } );
  20806. // INHERITANCE
  20807. QUnit.test( "Extending", ( assert ) => {
  20808. assert.ok( false, "everything's gonna be alright" );
  20809. } );
  20810. // INSTANCING
  20811. QUnit.test( "Instancing", ( assert ) => {
  20812. assert.ok( false, "everything's gonna be alright" );
  20813. } );
  20814. // OTHERS
  20815. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20816. runStdGeometryTests( assert, geometries );
  20817. } );
  20818. } );
  20819. QUnit.module.todo( 'CircleBufferGeometry', ( hooks ) => {
  20820. var geometries = undefined;
  20821. hooks.beforeEach( function () {
  20822. const parameters = {
  20823. radius: 10,
  20824. segments: 20,
  20825. thetaStart: 0.1,
  20826. thetaLength: 0.2
  20827. };
  20828. geometries = [
  20829. new CircleBufferGeometry(),
  20830. new CircleBufferGeometry( parameters.radius ),
  20831. new CircleBufferGeometry( parameters.radius, parameters.segments ),
  20832. new CircleBufferGeometry( parameters.radius, parameters.segments, parameters.thetaStart ),
  20833. new CircleBufferGeometry( parameters.radius, parameters.segments, parameters.thetaStart, parameters.thetaLength ),
  20834. ];
  20835. } );
  20836. // INHERITANCE
  20837. QUnit.test( "Extending", ( assert ) => {
  20838. assert.ok( false, "everything's gonna be alright" );
  20839. } );
  20840. // INSTANCING
  20841. QUnit.test( "Instancing", ( assert ) => {
  20842. assert.ok( false, "everything's gonna be alright" );
  20843. } );
  20844. // OTHERS
  20845. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20846. runStdGeometryTests( assert, geometries );
  20847. } );
  20848. } );
  20849. } );
  20850. /**
  20851. * @author mrdoob / http://mrdoob.com/
  20852. * @author Mugen87 / https://github.com/Mugen87
  20853. */
  20854. // CylinderGeometry
  20855. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  20856. Geometry.call( this );
  20857. this.type = 'CylinderGeometry';
  20858. this.parameters = {
  20859. radiusTop: radiusTop,
  20860. radiusBottom: radiusBottom,
  20861. height: height,
  20862. radialSegments: radialSegments,
  20863. heightSegments: heightSegments,
  20864. openEnded: openEnded,
  20865. thetaStart: thetaStart,
  20866. thetaLength: thetaLength
  20867. };
  20868. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  20869. this.mergeVertices();
  20870. }
  20871. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  20872. CylinderGeometry.prototype.constructor = CylinderGeometry;
  20873. // CylinderBufferGeometry
  20874. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  20875. BufferGeometry.call( this );
  20876. this.type = 'CylinderBufferGeometry';
  20877. this.parameters = {
  20878. radiusTop: radiusTop,
  20879. radiusBottom: radiusBottom,
  20880. height: height,
  20881. radialSegments: radialSegments,
  20882. heightSegments: heightSegments,
  20883. openEnded: openEnded,
  20884. thetaStart: thetaStart,
  20885. thetaLength: thetaLength
  20886. };
  20887. var scope = this;
  20888. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  20889. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  20890. height = height || 1;
  20891. radialSegments = Math.floor( radialSegments ) || 8;
  20892. heightSegments = Math.floor( heightSegments ) || 1;
  20893. openEnded = openEnded !== undefined ? openEnded : false;
  20894. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  20895. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  20896. // buffers
  20897. var indices = [];
  20898. var vertices = [];
  20899. var normals = [];
  20900. var uvs = [];
  20901. // helper variables
  20902. var index = 0;
  20903. var indexArray = [];
  20904. var halfHeight = height / 2;
  20905. var groupStart = 0;
  20906. // generate geometry
  20907. generateTorso();
  20908. if ( openEnded === false ) {
  20909. if ( radiusTop > 0 ) generateCap( true );
  20910. if ( radiusBottom > 0 ) generateCap( false );
  20911. }
  20912. // build geometry
  20913. this.setIndex( indices );
  20914. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20915. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  20916. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  20917. function generateTorso() {
  20918. var x, y;
  20919. var normal = new Vector3();
  20920. var vertex = new Vector3();
  20921. var groupCount = 0;
  20922. // this will be used to calculate the normal
  20923. var slope = ( radiusBottom - radiusTop ) / height;
  20924. // generate vertices, normals and uvs
  20925. for ( y = 0; y <= heightSegments; y ++ ) {
  20926. var indexRow = [];
  20927. var v = y / heightSegments;
  20928. // calculate the radius of the current row
  20929. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  20930. for ( x = 0; x <= radialSegments; x ++ ) {
  20931. var u = x / radialSegments;
  20932. var theta = u * thetaLength + thetaStart;
  20933. var sinTheta = Math.sin( theta );
  20934. var cosTheta = Math.cos( theta );
  20935. // vertex
  20936. vertex.x = radius * sinTheta;
  20937. vertex.y = - v * height + halfHeight;
  20938. vertex.z = radius * cosTheta;
  20939. vertices.push( vertex.x, vertex.y, vertex.z );
  20940. // normal
  20941. normal.set( sinTheta, slope, cosTheta ).normalize();
  20942. normals.push( normal.x, normal.y, normal.z );
  20943. // uv
  20944. uvs.push( u, 1 - v );
  20945. // save index of vertex in respective row
  20946. indexRow.push( index ++ );
  20947. }
  20948. // now save vertices of the row in our index array
  20949. indexArray.push( indexRow );
  20950. }
  20951. // generate indices
  20952. for ( x = 0; x < radialSegments; x ++ ) {
  20953. for ( y = 0; y < heightSegments; y ++ ) {
  20954. // we use the index array to access the correct indices
  20955. var a = indexArray[ y ][ x ];
  20956. var b = indexArray[ y + 1 ][ x ];
  20957. var c = indexArray[ y + 1 ][ x + 1 ];
  20958. var d = indexArray[ y ][ x + 1 ];
  20959. // faces
  20960. indices.push( a, b, d );
  20961. indices.push( b, c, d );
  20962. // update group counter
  20963. groupCount += 6;
  20964. }
  20965. }
  20966. // add a group to the geometry. this will ensure multi material support
  20967. scope.addGroup( groupStart, groupCount, 0 );
  20968. // calculate new start value for groups
  20969. groupStart += groupCount;
  20970. }
  20971. function generateCap( top ) {
  20972. var x, centerIndexStart, centerIndexEnd;
  20973. var uv = new Vector2();
  20974. var vertex = new Vector3();
  20975. var groupCount = 0;
  20976. var radius = ( top === true ) ? radiusTop : radiusBottom;
  20977. var sign = ( top === true ) ? 1 : - 1;
  20978. // save the index of the first center vertex
  20979. centerIndexStart = index;
  20980. // first we generate the center vertex data of the cap.
  20981. // because the geometry needs one set of uvs per face,
  20982. // we must generate a center vertex per face/segment
  20983. for ( x = 1; x <= radialSegments; x ++ ) {
  20984. // vertex
  20985. vertices.push( 0, halfHeight * sign, 0 );
  20986. // normal
  20987. normals.push( 0, sign, 0 );
  20988. // uv
  20989. uvs.push( 0.5, 0.5 );
  20990. // increase index
  20991. index ++;
  20992. }
  20993. // save the index of the last center vertex
  20994. centerIndexEnd = index;
  20995. // now we generate the surrounding vertices, normals and uvs
  20996. for ( x = 0; x <= radialSegments; x ++ ) {
  20997. var u = x / radialSegments;
  20998. var theta = u * thetaLength + thetaStart;
  20999. var cosTheta = Math.cos( theta );
  21000. var sinTheta = Math.sin( theta );
  21001. // vertex
  21002. vertex.x = radius * sinTheta;
  21003. vertex.y = halfHeight * sign;
  21004. vertex.z = radius * cosTheta;
  21005. vertices.push( vertex.x, vertex.y, vertex.z );
  21006. // normal
  21007. normals.push( 0, sign, 0 );
  21008. // uv
  21009. uv.x = ( cosTheta * 0.5 ) + 0.5;
  21010. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  21011. uvs.push( uv.x, uv.y );
  21012. // increase index
  21013. index ++;
  21014. }
  21015. // generate indices
  21016. for ( x = 0; x < radialSegments; x ++ ) {
  21017. var c = centerIndexStart + x;
  21018. var i = centerIndexEnd + x;
  21019. if ( top === true ) {
  21020. // face top
  21021. indices.push( i, i + 1, c );
  21022. } else {
  21023. // face bottom
  21024. indices.push( i + 1, i, c );
  21025. }
  21026. groupCount += 3;
  21027. }
  21028. // add a group to the geometry. this will ensure multi material support
  21029. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  21030. // calculate new start value for groups
  21031. groupStart += groupCount;
  21032. }
  21033. }
  21034. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  21035. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  21036. /**
  21037. * @author abelnation / http://github.com/abelnation
  21038. */
  21039. // ConeGeometry
  21040. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21041. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  21042. this.type = 'ConeGeometry';
  21043. this.parameters = {
  21044. radius: radius,
  21045. height: height,
  21046. radialSegments: radialSegments,
  21047. heightSegments: heightSegments,
  21048. openEnded: openEnded,
  21049. thetaStart: thetaStart,
  21050. thetaLength: thetaLength
  21051. };
  21052. }
  21053. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  21054. ConeGeometry.prototype.constructor = ConeGeometry;
  21055. // ConeBufferGeometry
  21056. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21057. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  21058. this.type = 'ConeBufferGeometry';
  21059. this.parameters = {
  21060. radius: radius,
  21061. height: height,
  21062. radialSegments: radialSegments,
  21063. heightSegments: heightSegments,
  21064. openEnded: openEnded,
  21065. thetaStart: thetaStart,
  21066. thetaLength: thetaLength
  21067. };
  21068. }
  21069. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  21070. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  21071. /**
  21072. * @author TristanVALCKE / https://github.com/Itee
  21073. */
  21074. /* global QUnit */
  21075. QUnit.module( 'Geometries', () => {
  21076. QUnit.module.todo( 'ConeGeometry', ( hooks ) => {
  21077. var geometries = undefined;
  21078. hooks.beforeEach( function () {
  21079. const parameters = {};
  21080. geometries = [
  21081. new ConeGeometry()
  21082. ];
  21083. } );
  21084. // INHERITANCE
  21085. QUnit.test( "Extending", ( assert ) => {
  21086. assert.ok( false, "everything's gonna be alright" );
  21087. } );
  21088. // INSTANCING
  21089. QUnit.test( "Instancing", ( assert ) => {
  21090. assert.ok( false, "everything's gonna be alright" );
  21091. } );
  21092. // OTHERS
  21093. QUnit.test( 'Standard geometry tests', ( assert ) => {
  21094. runStdGeometryTests( assert, geometries );
  21095. } );
  21096. } );
  21097. QUnit.module.todo( 'ConeBufferGeometry', ( hooks ) => {
  21098. var geometries = undefined;
  21099. hooks.beforeEach( function () {
  21100. const parameters = {};
  21101. geometries = [
  21102. new ConeBufferGeometry()
  21103. ];
  21104. } );
  21105. // INHERITANCE
  21106. QUnit.test( "Extending", ( assert ) => {
  21107. assert.ok( false, "everything's gonna be alright" );
  21108. } );
  21109. // INSTANCING
  21110. QUnit.test( "Instancing", ( assert ) => {
  21111. assert.ok( false, "everything's gonna be alright" );
  21112. } );
  21113. // OTHERS
  21114. QUnit.test( 'Standard geometry tests', ( assert ) => {
  21115. runStdGeometryTests( assert, geometries );
  21116. } );
  21117. } );
  21118. } );
  21119. /**
  21120. * @author TristanVALCKE / https://github.com/Itee
  21121. * @author Anonymous
  21122. */
  21123. /* global QUnit */
  21124. QUnit.module( 'Geometries', () => {
  21125. QUnit.module.todo( 'CylinderGeometry', ( hooks ) => {
  21126. var geometries = undefined;
  21127. hooks.beforeEach( function () {
  21128. const parameters = {
  21129. radiusTop: 10,
  21130. radiusBottom: 20,
  21131. height: 30,
  21132. radialSegments: 20,
  21133. heightSegments: 30,
  21134. openEnded: true,
  21135. thetaStart: 0.1,
  21136. thetaLength: 2.0,
  21137. };
  21138. geometries = [
  21139. new CylinderGeometry(),
  21140. new CylinderGeometry( parameters.radiusTop ),
  21141. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom ),
  21142. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height ),
  21143. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments ),
  21144. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments ),
  21145. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded ),
  21146. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded, parameters.thetaStart ),
  21147. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded, parameters.thetaStart, parameters.thetaLength ),
  21148. ];
  21149. } );
  21150. // INHERITANCE
  21151. QUnit.test( "Extending", ( assert ) => {
  21152. assert.ok( false, "everything's gonna be alright" );
  21153. } );
  21154. // INSTANCING
  21155. QUnit.test( "Instancing", ( assert ) => {
  21156. assert.ok( false, "everything's gonna be alright" );
  21157. } );
  21158. // OTHERS
  21159. QUnit.test( 'Standard geometry tests', ( assert ) => {
  21160. runStdGeometryTests( assert, geometries );
  21161. } );
  21162. } );
  21163. QUnit.module.todo( 'CylinderBufferGeometry', ( hooks ) => {
  21164. var geometries = undefined;
  21165. hooks.beforeEach( function () {
  21166. const parameters = {
  21167. radiusTop: 10,
  21168. radiusBottom: 20,
  21169. height: 30,
  21170. radialSegments: 20,
  21171. heightSegments: 30,
  21172. openEnded: true,
  21173. thetaStart: 0.1,
  21174. thetaLength: 2.0,
  21175. };
  21176. geometries = [
  21177. new CylinderBufferGeometry(),
  21178. new CylinderBufferGeometry( parameters.radiusTop ),
  21179. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom ),
  21180. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height ),
  21181. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments ),
  21182. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments ),
  21183. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded ),
  21184. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded, parameters.thetaStart ),
  21185. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded, parameters.thetaStart, parameters.thetaLength ),
  21186. ];
  21187. } );
  21188. // INHERITANCE
  21189. QUnit.test( "Extending", ( assert ) => {
  21190. assert.ok( false, "everything's gonna be alright" );
  21191. } );
  21192. // INSTANCING
  21193. QUnit.test( "Instancing", ( assert ) => {
  21194. assert.ok( false, "everything's gonna be alright" );
  21195. } );
  21196. // OTHERS
  21197. QUnit.test( 'Standard geometry tests', ( assert ) => {
  21198. runStdGeometryTests( assert, geometries );
  21199. } );
  21200. } );
  21201. } );
  21202. /**
  21203. * @author TristanVALCKE / https://github.com/Itee
  21204. * @author Anonymous
  21205. */
  21206. /* global QUnit */
  21207. QUnit.module( 'Geometries', () => {
  21208. QUnit.module.todo( 'CircleGeometry', ( hooks ) => {
  21209. var geometries = undefined;
  21210. hooks.beforeEach( function () {
  21211. const parameters = {
  21212. radius: 10,
  21213. detail: undefined
  21214. };
  21215. geometries = [
  21216. new DodecahedronGeometry(),
  21217. new DodecahedronGeometry( parameters.radius ),
  21218. new DodecahedronGeometry( parameters.radius, parameters.detail ),
  21219. ];
  21220. } );
  21221. // INHERITANCE
  21222. QUnit.test( "Extending", ( assert ) => {
  21223. assert.ok( false, "everything's gonna be alright" );
  21224. } );
  21225. // INSTANCING
  21226. QUnit.test( "Instancing", ( assert ) => {
  21227. assert.ok( false, "everything's gonna be alright" );
  21228. } );
  21229. // OTHERS
  21230. QUnit.test( 'Standard geometry tests', ( assert ) => {
  21231. runStdGeometryTests( assert, geometries );
  21232. } );
  21233. } );
  21234. QUnit.module.todo( 'CircleBufferGeometry', ( hooks ) => {
  21235. var geometries = undefined;
  21236. hooks.beforeEach( function () {
  21237. const parameters = {
  21238. radius: 10,
  21239. detail: undefined
  21240. };
  21241. geometries = [
  21242. new DodecahedronBufferGeometry(),
  21243. new DodecahedronBufferGeometry( parameters.radius ),
  21244. new DodecahedronBufferGeometry( parameters.radius, parameters.detail ),
  21245. ];
  21246. } );
  21247. // INHERITANCE
  21248. QUnit.test( "Extending", ( assert ) => {
  21249. assert.ok( false, "everything's gonna be alright" );
  21250. } );
  21251. // INSTANCING
  21252. QUnit.test( "Instancing", ( assert ) => {
  21253. assert.ok( false, "everything's gonna be alright" );
  21254. } );
  21255. // OTHERS
  21256. QUnit.test( 'Standard geometry tests', ( assert ) => {
  21257. runStdGeometryTests( assert, geometries );
  21258. } );
  21259. } );
  21260. } );
  21261. /**
  21262. * @author WestLangley / http://github.com/WestLangley
  21263. * @author Mugen87 / https://github.com/Mugen87
  21264. */
  21265. function EdgesGeometry( geometry, thresholdAngle ) {
  21266. BufferGeometry.call( this );
  21267. this.type = 'EdgesGeometry';
  21268. this.parameters = {
  21269. thresholdAngle: thresholdAngle
  21270. };
  21271. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  21272. // buffer
  21273. var vertices = [];
  21274. // helper variables
  21275. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  21276. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  21277. var key, keys = [ 'a', 'b', 'c' ];
  21278. // prepare source geometry
  21279. var geometry2;
  21280. if ( geometry.isBufferGeometry ) {
  21281. geometry2 = new Geometry();
  21282. geometry2.fromBufferGeometry( geometry );
  21283. } else {
  21284. geometry2 = geometry.clone();
  21285. }
  21286. geometry2.mergeVertices();
  21287. geometry2.computeFaceNormals();
  21288. var sourceVertices = geometry2.vertices;
  21289. var faces = geometry2.faces;
  21290. // now create a data structure where each entry represents an edge with its adjoining faces
  21291. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21292. var face = faces[ i ];
  21293. for ( var j = 0; j < 3; j ++ ) {
  21294. edge1 = face[ keys[ j ] ];
  21295. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  21296. edge[ 0 ] = Math.min( edge1, edge2 );
  21297. edge[ 1 ] = Math.max( edge1, edge2 );
  21298. key = edge[ 0 ] + ',' + edge[ 1 ];
  21299. if ( edges[ key ] === undefined ) {
  21300. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  21301. } else {
  21302. edges[ key ].face2 = i;
  21303. }
  21304. }
  21305. }
  21306. // generate vertices
  21307. for ( key in edges ) {
  21308. var e = edges[ key ];
  21309. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  21310. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  21311. var vertex = sourceVertices[ e.index1 ];
  21312. vertices.push( vertex.x, vertex.y, vertex.z );
  21313. vertex = sourceVertices[ e.index2 ];
  21314. vertices.push( vertex.x, vertex.y, vertex.z );
  21315. }
  21316. }
  21317. // build geometry
  21318. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21319. }
  21320. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  21321. EdgesGeometry.prototype.constructor = EdgesGeometry;
  21322. /**
  21323. * @author mrdoob / http://mrdoob.com/
  21324. */
  21325. function Scene() {
  21326. Object3D.call( this );
  21327. this.type = 'Scene';
  21328. this.background = null;
  21329. this.fog = null;
  21330. this.overrideMaterial = null;
  21331. this.autoUpdate = true; // checked by the renderer
  21332. }
  21333. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  21334. constructor: Scene,
  21335. copy: function ( source, recursive ) {
  21336. Object3D.prototype.copy.call( this, source, recursive );
  21337. if ( source.background !== null ) this.background = source.background.clone();
  21338. if ( source.fog !== null ) this.fog = source.fog.clone();
  21339. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  21340. this.autoUpdate = source.autoUpdate;
  21341. this.matrixAutoUpdate = source.matrixAutoUpdate;
  21342. return this;
  21343. },
  21344. toJSON: function ( meta ) {
  21345. var data = Object3D.prototype.toJSON.call( this, meta );
  21346. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  21347. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  21348. return data;
  21349. }
  21350. } );
  21351. /**
  21352. * @author alteredq / http://alteredqualia.com/
  21353. */
  21354. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  21355. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  21356. this.image = { data: data, width: width, height: height };
  21357. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  21358. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  21359. this.generateMipmaps = false;
  21360. this.flipY = false;
  21361. this.unpackAlignment = 1;
  21362. }
  21363. DataTexture.prototype = Object.create( Texture.prototype );
  21364. DataTexture.prototype.constructor = DataTexture;
  21365. DataTexture.prototype.isDataTexture = true;
  21366. /**
  21367. * @author mrdoob / http://mrdoob.com/
  21368. */
  21369. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  21370. images = images !== undefined ? images : [];
  21371. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  21372. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  21373. this.flipY = false;
  21374. }
  21375. CubeTexture.prototype = Object.create( Texture.prototype );
  21376. CubeTexture.prototype.constructor = CubeTexture;
  21377. CubeTexture.prototype.isCubeTexture = true;
  21378. Object.defineProperty( CubeTexture.prototype, 'images', {
  21379. get: function () {
  21380. return this.image;
  21381. },
  21382. set: function ( value ) {
  21383. this.image = value;
  21384. }
  21385. } );
  21386. /**
  21387. * @author tschw
  21388. *
  21389. * Uniforms of a program.
  21390. * Those form a tree structure with a special top-level container for the root,
  21391. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  21392. *
  21393. *
  21394. * Properties of inner nodes including the top-level container:
  21395. *
  21396. * .seq - array of nested uniforms
  21397. * .map - nested uniforms by name
  21398. *
  21399. *
  21400. * Methods of all nodes except the top-level container:
  21401. *
  21402. * .setValue( gl, value, [renderer] )
  21403. *
  21404. * uploads a uniform value(s)
  21405. * the 'renderer' parameter is needed for sampler uniforms
  21406. *
  21407. *
  21408. * Static methods of the top-level container (renderer factorizations):
  21409. *
  21410. * .upload( gl, seq, values, renderer )
  21411. *
  21412. * sets uniforms in 'seq' to 'values[id].value'
  21413. *
  21414. * .seqWithValue( seq, values ) : filteredSeq
  21415. *
  21416. * filters 'seq' entries with corresponding entry in values
  21417. *
  21418. *
  21419. * Methods of the top-level container (renderer factorizations):
  21420. *
  21421. * .setValue( gl, name, value )
  21422. *
  21423. * sets uniform with name 'name' to 'value'
  21424. *
  21425. * .set( gl, obj, prop )
  21426. *
  21427. * sets uniform from object and property with same name than uniform
  21428. *
  21429. * .setOptional( gl, obj, prop )
  21430. *
  21431. * like .set for an optional property of the object
  21432. *
  21433. */
  21434. var emptyTexture = new Texture();
  21435. var emptyCubeTexture = new CubeTexture();
  21436. // --- Base for inner nodes (including the root) ---
  21437. function UniformContainer() {
  21438. this.seq = [];
  21439. this.map = {};
  21440. }
  21441. // --- Utilities ---
  21442. // Array Caches (provide typed arrays for temporary by size)
  21443. var arrayCacheF32 = [];
  21444. var arrayCacheI32 = [];
  21445. // Float32Array caches used for uploading Matrix uniforms
  21446. var mat4array = new Float32Array( 16 );
  21447. var mat3array = new Float32Array( 9 );
  21448. // Flattening for arrays of vectors and matrices
  21449. function flatten( array, nBlocks, blockSize ) {
  21450. var firstElem = array[ 0 ];
  21451. if ( firstElem <= 0 || firstElem > 0 ) return array;
  21452. // unoptimized: ! isNaN( firstElem )
  21453. // see http://jacksondunstan.com/articles/983
  21454. var n = nBlocks * blockSize,
  21455. r = arrayCacheF32[ n ];
  21456. if ( r === undefined ) {
  21457. r = new Float32Array( n );
  21458. arrayCacheF32[ n ] = r;
  21459. }
  21460. if ( nBlocks !== 0 ) {
  21461. firstElem.toArray( r, 0 );
  21462. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  21463. offset += blockSize;
  21464. array[ i ].toArray( r, offset );
  21465. }
  21466. }
  21467. return r;
  21468. }
  21469. // Texture unit allocation
  21470. function allocTexUnits( renderer, n ) {
  21471. var r = arrayCacheI32[ n ];
  21472. if ( r === undefined ) {
  21473. r = new Int32Array( n );
  21474. arrayCacheI32[ n ] = r;
  21475. }
  21476. for ( var i = 0; i !== n; ++ i )
  21477. r[ i ] = renderer.allocTextureUnit();
  21478. return r;
  21479. }
  21480. // --- Setters ---
  21481. // Note: Defining these methods externally, because they come in a bunch
  21482. // and this way their names minify.
  21483. // Single scalar
  21484. function setValue1f( gl, v ) {
  21485. gl.uniform1f( this.addr, v );
  21486. }
  21487. function setValue1i( gl, v ) {
  21488. gl.uniform1i( this.addr, v );
  21489. }
  21490. // Single float vector (from flat array or THREE.VectorN)
  21491. function setValue2fv( gl, v ) {
  21492. if ( v.x === undefined ) {
  21493. gl.uniform2fv( this.addr, v );
  21494. } else {
  21495. gl.uniform2f( this.addr, v.x, v.y );
  21496. }
  21497. }
  21498. function setValue3fv( gl, v ) {
  21499. if ( v.x !== undefined ) {
  21500. gl.uniform3f( this.addr, v.x, v.y, v.z );
  21501. } else if ( v.r !== undefined ) {
  21502. gl.uniform3f( this.addr, v.r, v.g, v.b );
  21503. } else {
  21504. gl.uniform3fv( this.addr, v );
  21505. }
  21506. }
  21507. function setValue4fv( gl, v ) {
  21508. if ( v.x === undefined ) {
  21509. gl.uniform4fv( this.addr, v );
  21510. } else {
  21511. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  21512. }
  21513. }
  21514. // Single matrix (from flat array or MatrixN)
  21515. function setValue2fm( gl, v ) {
  21516. gl.uniformMatrix2fv( this.addr, false, v.elements || v );
  21517. }
  21518. function setValue3fm( gl, v ) {
  21519. if ( v.elements === undefined ) {
  21520. gl.uniformMatrix3fv( this.addr, false, v );
  21521. } else {
  21522. mat3array.set( v.elements );
  21523. gl.uniformMatrix3fv( this.addr, false, mat3array );
  21524. }
  21525. }
  21526. function setValue4fm( gl, v ) {
  21527. if ( v.elements === undefined ) {
  21528. gl.uniformMatrix4fv( this.addr, false, v );
  21529. } else {
  21530. mat4array.set( v.elements );
  21531. gl.uniformMatrix4fv( this.addr, false, mat4array );
  21532. }
  21533. }
  21534. // Single texture (2D / Cube)
  21535. function setValueT1( gl, v, renderer ) {
  21536. var unit = renderer.allocTextureUnit();
  21537. gl.uniform1i( this.addr, unit );
  21538. renderer.setTexture2D( v || emptyTexture, unit );
  21539. }
  21540. function setValueT6( gl, v, renderer ) {
  21541. var unit = renderer.allocTextureUnit();
  21542. gl.uniform1i( this.addr, unit );
  21543. renderer.setTextureCube( v || emptyCubeTexture, unit );
  21544. }
  21545. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  21546. function setValue2iv( gl, v ) {
  21547. gl.uniform2iv( this.addr, v );
  21548. }
  21549. function setValue3iv( gl, v ) {
  21550. gl.uniform3iv( this.addr, v );
  21551. }
  21552. function setValue4iv( gl, v ) {
  21553. gl.uniform4iv( this.addr, v );
  21554. }
  21555. // Helper to pick the right setter for the singular case
  21556. function getSingularSetter( type ) {
  21557. switch ( type ) {
  21558. case 0x1406: return setValue1f; // FLOAT
  21559. case 0x8b50: return setValue2fv; // _VEC2
  21560. case 0x8b51: return setValue3fv; // _VEC3
  21561. case 0x8b52: return setValue4fv; // _VEC4
  21562. case 0x8b5a: return setValue2fm; // _MAT2
  21563. case 0x8b5b: return setValue3fm; // _MAT3
  21564. case 0x8b5c: return setValue4fm; // _MAT4
  21565. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  21566. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  21567. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  21568. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  21569. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  21570. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  21571. }
  21572. }
  21573. // Array of scalars
  21574. function setValue1fv( gl, v ) {
  21575. gl.uniform1fv( this.addr, v );
  21576. }
  21577. function setValue1iv( gl, v ) {
  21578. gl.uniform1iv( this.addr, v );
  21579. }
  21580. // Array of vectors (flat or from THREE classes)
  21581. function setValueV2a( gl, v ) {
  21582. gl.uniform2fv( this.addr, flatten( v, this.size, 2 ) );
  21583. }
  21584. function setValueV3a( gl, v ) {
  21585. gl.uniform3fv( this.addr, flatten( v, this.size, 3 ) );
  21586. }
  21587. function setValueV4a( gl, v ) {
  21588. gl.uniform4fv( this.addr, flatten( v, this.size, 4 ) );
  21589. }
  21590. // Array of matrices (flat or from THREE clases)
  21591. function setValueM2a( gl, v ) {
  21592. gl.uniformMatrix2fv( this.addr, false, flatten( v, this.size, 4 ) );
  21593. }
  21594. function setValueM3a( gl, v ) {
  21595. gl.uniformMatrix3fv( this.addr, false, flatten( v, this.size, 9 ) );
  21596. }
  21597. function setValueM4a( gl, v ) {
  21598. gl.uniformMatrix4fv( this.addr, false, flatten( v, this.size, 16 ) );
  21599. }
  21600. // Array of textures (2D / Cube)
  21601. function setValueT1a( gl, v, renderer ) {
  21602. var n = v.length,
  21603. units = allocTexUnits( renderer, n );
  21604. gl.uniform1iv( this.addr, units );
  21605. for ( var i = 0; i !== n; ++ i ) {
  21606. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  21607. }
  21608. }
  21609. function setValueT6a( gl, v, renderer ) {
  21610. var n = v.length,
  21611. units = allocTexUnits( renderer, n );
  21612. gl.uniform1iv( this.addr, units );
  21613. for ( var i = 0; i !== n; ++ i ) {
  21614. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  21615. }
  21616. }
  21617. // Helper to pick the right setter for a pure (bottom-level) array
  21618. function getPureArraySetter( type ) {
  21619. switch ( type ) {
  21620. case 0x1406: return setValue1fv; // FLOAT
  21621. case 0x8b50: return setValueV2a; // _VEC2
  21622. case 0x8b51: return setValueV3a; // _VEC3
  21623. case 0x8b52: return setValueV4a; // _VEC4
  21624. case 0x8b5a: return setValueM2a; // _MAT2
  21625. case 0x8b5b: return setValueM3a; // _MAT3
  21626. case 0x8b5c: return setValueM4a; // _MAT4
  21627. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  21628. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  21629. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  21630. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  21631. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  21632. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  21633. }
  21634. }
  21635. // --- Uniform Classes ---
  21636. function SingleUniform( id, activeInfo, addr ) {
  21637. this.id = id;
  21638. this.addr = addr;
  21639. this.setValue = getSingularSetter( activeInfo.type );
  21640. // this.path = activeInfo.name; // DEBUG
  21641. }
  21642. function PureArrayUniform( id, activeInfo, addr ) {
  21643. this.id = id;
  21644. this.addr = addr;
  21645. this.size = activeInfo.size;
  21646. this.setValue = getPureArraySetter( activeInfo.type );
  21647. // this.path = activeInfo.name; // DEBUG
  21648. }
  21649. function StructuredUniform( id ) {
  21650. this.id = id;
  21651. UniformContainer.call( this ); // mix-in
  21652. }
  21653. StructuredUniform.prototype.setValue = function ( gl, value ) {
  21654. // Note: Don't need an extra 'renderer' parameter, since samplers
  21655. // are not allowed in structured uniforms.
  21656. var seq = this.seq;
  21657. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  21658. var u = seq[ i ];
  21659. u.setValue( gl, value[ u.id ] );
  21660. }
  21661. };
  21662. // --- Top-level ---
  21663. // Parser - builds up the property tree from the path strings
  21664. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  21665. // extracts
  21666. // - the identifier (member name or array index)
  21667. // - followed by an optional right bracket (found when array index)
  21668. // - followed by an optional left bracket or dot (type of subscript)
  21669. //
  21670. // Note: These portions can be read in a non-overlapping fashion and
  21671. // allow straightforward parsing of the hierarchy that WebGL encodes
  21672. // in the uniform names.
  21673. function addUniform( container, uniformObject ) {
  21674. container.seq.push( uniformObject );
  21675. container.map[ uniformObject.id ] = uniformObject;
  21676. }
  21677. function parseUniform( activeInfo, addr, container ) {
  21678. var path = activeInfo.name,
  21679. pathLength = path.length;
  21680. // reset RegExp object, because of the early exit of a previous run
  21681. RePathPart.lastIndex = 0;
  21682. for ( ; ; ) {
  21683. var match = RePathPart.exec( path ),
  21684. matchEnd = RePathPart.lastIndex,
  21685. id = match[ 1 ],
  21686. idIsIndex = match[ 2 ] === ']',
  21687. subscript = match[ 3 ];
  21688. if ( idIsIndex ) id = id | 0; // convert to integer
  21689. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  21690. // bare name or "pure" bottom-level array "[0]" suffix
  21691. addUniform( container, subscript === undefined ?
  21692. new SingleUniform( id, activeInfo, addr ) :
  21693. new PureArrayUniform( id, activeInfo, addr ) );
  21694. break;
  21695. } else {
  21696. // step into inner node / create it in case it doesn't exist
  21697. var map = container.map, next = map[ id ];
  21698. if ( next === undefined ) {
  21699. next = new StructuredUniform( id );
  21700. addUniform( container, next );
  21701. }
  21702. container = next;
  21703. }
  21704. }
  21705. }
  21706. // Root Container
  21707. function WebGLUniforms( gl, program, renderer ) {
  21708. UniformContainer.call( this );
  21709. this.renderer = renderer;
  21710. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  21711. for ( var i = 0; i < n; ++ i ) {
  21712. var info = gl.getActiveUniform( program, i ),
  21713. path = info.name,
  21714. addr = gl.getUniformLocation( program, path );
  21715. parseUniform( info, addr, this );
  21716. }
  21717. }
  21718. WebGLUniforms.prototype.setValue = function ( gl, name, value ) {
  21719. var u = this.map[ name ];
  21720. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  21721. };
  21722. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  21723. var v = object[ name ];
  21724. if ( v !== undefined ) this.setValue( gl, name, v );
  21725. };
  21726. // Static interface
  21727. WebGLUniforms.upload = function ( gl, seq, values, renderer ) {
  21728. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  21729. var u = seq[ i ],
  21730. v = values[ u.id ];
  21731. if ( v.needsUpdate !== false ) {
  21732. // note: always updating when .needsUpdate is undefined
  21733. u.setValue( gl, v.value, renderer );
  21734. }
  21735. }
  21736. };
  21737. WebGLUniforms.seqWithValue = function ( seq, values ) {
  21738. var r = [];
  21739. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  21740. var u = seq[ i ];
  21741. if ( u.id in values ) r.push( u );
  21742. }
  21743. return r;
  21744. };
  21745. /**
  21746. * Uniforms library for shared webgl shaders
  21747. */
  21748. var UniformsLib = {
  21749. common: {
  21750. diffuse: { value: new Color( 0xeeeeee ) },
  21751. opacity: { value: 1.0 },
  21752. map: { value: null },
  21753. uvTransform: { value: new Matrix3() },
  21754. alphaMap: { value: null },
  21755. },
  21756. specularmap: {
  21757. specularMap: { value: null },
  21758. },
  21759. envmap: {
  21760. envMap: { value: null },
  21761. flipEnvMap: { value: - 1 },
  21762. reflectivity: { value: 1.0 },
  21763. refractionRatio: { value: 0.98 }
  21764. },
  21765. aomap: {
  21766. aoMap: { value: null },
  21767. aoMapIntensity: { value: 1 }
  21768. },
  21769. lightmap: {
  21770. lightMap: { value: null },
  21771. lightMapIntensity: { value: 1 }
  21772. },
  21773. emissivemap: {
  21774. emissiveMap: { value: null }
  21775. },
  21776. bumpmap: {
  21777. bumpMap: { value: null },
  21778. bumpScale: { value: 1 }
  21779. },
  21780. normalmap: {
  21781. normalMap: { value: null },
  21782. normalScale: { value: new Vector2( 1, 1 ) }
  21783. },
  21784. displacementmap: {
  21785. displacementMap: { value: null },
  21786. displacementScale: { value: 1 },
  21787. displacementBias: { value: 0 }
  21788. },
  21789. roughnessmap: {
  21790. roughnessMap: { value: null }
  21791. },
  21792. metalnessmap: {
  21793. metalnessMap: { value: null }
  21794. },
  21795. gradientmap: {
  21796. gradientMap: { value: null }
  21797. },
  21798. fog: {
  21799. fogDensity: { value: 0.00025 },
  21800. fogNear: { value: 1 },
  21801. fogFar: { value: 2000 },
  21802. fogColor: { value: new Color( 0xffffff ) }
  21803. },
  21804. lights: {
  21805. ambientLightColor: { value: [] },
  21806. directionalLights: { value: [], properties: {
  21807. direction: {},
  21808. color: {},
  21809. shadow: {},
  21810. shadowBias: {},
  21811. shadowRadius: {},
  21812. shadowMapSize: {}
  21813. } },
  21814. directionalShadowMap: { value: [] },
  21815. directionalShadowMatrix: { value: [] },
  21816. spotLights: { value: [], properties: {
  21817. color: {},
  21818. position: {},
  21819. direction: {},
  21820. distance: {},
  21821. coneCos: {},
  21822. penumbraCos: {},
  21823. decay: {},
  21824. shadow: {},
  21825. shadowBias: {},
  21826. shadowRadius: {},
  21827. shadowMapSize: {}
  21828. } },
  21829. spotShadowMap: { value: [] },
  21830. spotShadowMatrix: { value: [] },
  21831. pointLights: { value: [], properties: {
  21832. color: {},
  21833. position: {},
  21834. decay: {},
  21835. distance: {},
  21836. shadow: {},
  21837. shadowBias: {},
  21838. shadowRadius: {},
  21839. shadowMapSize: {},
  21840. shadowCameraNear: {},
  21841. shadowCameraFar: {}
  21842. } },
  21843. pointShadowMap: { value: [] },
  21844. pointShadowMatrix: { value: [] },
  21845. hemisphereLights: { value: [], properties: {
  21846. direction: {},
  21847. skyColor: {},
  21848. groundColor: {}
  21849. } },
  21850. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  21851. rectAreaLights: { value: [], properties: {
  21852. color: {},
  21853. position: {},
  21854. width: {},
  21855. height: {}
  21856. } }
  21857. },
  21858. points: {
  21859. diffuse: { value: new Color( 0xeeeeee ) },
  21860. opacity: { value: 1.0 },
  21861. size: { value: 1.0 },
  21862. scale: { value: 1.0 },
  21863. map: { value: null },
  21864. uvTransform: { value: new Matrix3() }
  21865. }
  21866. };
  21867. var alphamap_fragment = "#ifdef USE_ALPHAMAP\r\n\r\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\r\n\r\n#endif\r\n";
  21868. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\r\n\r\n\tuniform sampler2D alphaMap;\r\n\r\n#endif\r\n";
  21869. var alphatest_fragment = "#ifdef ALPHATEST\r\n\r\n\tif ( diffuseColor.a < ALPHATEST ) discard;\r\n\r\n#endif\r\n";
  21870. 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";
  21871. var aomap_pars_fragment = "#ifdef USE_AOMAP\r\n\r\n\tuniform sampler2D aoMap;\r\n\tuniform float aoMapIntensity;\r\n\r\n#endif";
  21872. var begin_vertex = "\r\nvec3 transformed = vec3( position );\r\n";
  21873. var beginnormal_vertex = "\r\nvec3 objectNormal = vec3( normal );\r\n";
  21874. 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";
  21875. 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";
  21876. 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";
  21877. 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";
  21878. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\r\n\tvarying vec3 vViewPosition;\r\n#endif\r\n";
  21879. 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";
  21880. var color_fragment = "#ifdef USE_COLOR\r\n\r\n\tdiffuseColor.rgb *= vColor;\r\n\r\n#endif";
  21881. var color_pars_fragment = "#ifdef USE_COLOR\r\n\r\n\tvarying vec3 vColor;\r\n\r\n#endif\r\n";
  21882. var color_pars_vertex = "#ifdef USE_COLOR\r\n\r\n\tvarying vec3 vColor;\r\n\r\n#endif";
  21883. var color_vertex = "#ifdef USE_COLOR\r\n\r\n\tvColor.xyz = color.xyz;\r\n\r\n#endif";
  21884. 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";
  21885. 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";
  21886. 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";
  21887. 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";
  21888. 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";
  21889. 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";
  21890. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\r\n\r\n\tuniform sampler2D emissiveMap;\r\n\r\n#endif\r\n";
  21891. var encodings_fragment = " gl_FragColor = linearToOutputTexel( gl_FragColor );\r\n";
  21892. 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";
  21893. 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";
  21894. 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";
  21895. 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";
  21896. 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";
  21897. var fog_vertex = "\r\n#ifdef USE_FOG\r\nfogDepth = -mvPosition.z;\r\n#endif";
  21898. var fog_pars_vertex = "#ifdef USE_FOG\r\n\r\n varying float fogDepth;\r\n\r\n#endif\r\n";
  21899. 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";
  21900. 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";
  21901. 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";
  21902. 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";
  21903. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\r\n\r\n\tuniform sampler2D lightMap;\r\n\tuniform float lightMapIntensity;\r\n\r\n#endif";
  21904. 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";
  21905. 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";
  21906. 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";
  21907. 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";
  21908. 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";
  21909. 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";
  21910. 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";
  21911. 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";
  21912. 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";
  21913. 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";
  21914. 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";
  21915. 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";
  21916. var map_pars_fragment = "#ifdef USE_MAP\r\n\r\n\tuniform sampler2D map;\r\n\r\n#endif\r\n";
  21917. 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";
  21918. 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";
  21919. 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";
  21920. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\r\n\r\n\tuniform sampler2D metalnessMap;\r\n\r\n#endif";
  21921. 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";
  21922. 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";
  21923. 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";
  21924. 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";
  21925. 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";
  21926. 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";
  21927. 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";
  21928. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\r\n\r\ngl_Position = projectionMatrix * mvPosition;\r\n";
  21929. var dithering_fragment = "#if defined( DITHERING )\r\n\r\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\r\n\r\n#endif\r\n";
  21930. 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";
  21931. 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";
  21932. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\r\n\r\n\tuniform sampler2D roughnessMap;\r\n\r\n#endif";
  21933. 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";
  21934. 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";
  21935. 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";
  21936. 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";
  21937. 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";
  21938. 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";
  21939. 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";
  21940. 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";
  21941. 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";
  21942. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\r\n\r\n\tuniform sampler2D specularMap;\r\n\r\n#endif";
  21943. 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";
  21944. var tonemapping_pars_fragment = "#ifndef saturate\r\n\t#define saturate(a) clamp( a, 0.0, 1.0 )\r\n#endif\r\n\r\nuniform float toneMappingExposure;\r\nuniform float toneMappingWhitePoint;\r\n\r\n// exposure only\r\nvec3 LinearToneMapping( vec3 color ) {\r\n\r\n\treturn toneMappingExposure * color;\r\n\r\n}\r\n\r\n// source: https://www.cs.utah.edu/~reinhard/cdrom/\r\nvec3 ReinhardToneMapping( vec3 color ) {\r\n\r\n\tcolor *= toneMappingExposure;\r\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\r\n\r\n}\r\n\r\n// source: http://filmicgames.com/archives/75\r\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\r\nvec3 Uncharted2ToneMapping( vec3 color ) {\r\n\r\n\t// John Hable's filmic operator from Uncharted 2 video game\r\n\tcolor *= toneMappingExposure;\r\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\r\n\r\n}\r\n\r\n// source: http://filmicgames.com/archives/75\r\nvec3 OptimizedCineonToneMapping( vec3 color ) {\r\n\r\n\t// optimized filmic operator by Jim Hejl and Richard Burgess-Dawson\r\n\tcolor *= toneMappingExposure;\r\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\r\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\r\n\r\n}\r\n";
  21945. 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";
  21946. 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";
  21947. 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";
  21948. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\r\n\r\n\tvarying vec2 vUv2;\r\n\r\n#endif";
  21949. 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";
  21950. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\r\n\r\n\tvUv2 = uv2;\r\n\r\n#endif";
  21951. 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";
  21952. 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";
  21953. 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";
  21954. 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";
  21955. 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";
  21956. 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";
  21957. 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";
  21958. 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";
  21959. 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";
  21960. 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";
  21961. 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";
  21962. 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";
  21963. 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";
  21964. 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";
  21965. 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";
  21966. 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";
  21967. 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";
  21968. 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";
  21969. 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";
  21970. 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";
  21971. 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";
  21972. 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";
  21973. 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";
  21974. 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";
  21975. 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";
  21976. var ShaderChunk = {
  21977. alphamap_fragment: alphamap_fragment,
  21978. alphamap_pars_fragment: alphamap_pars_fragment,
  21979. alphatest_fragment: alphatest_fragment,
  21980. aomap_fragment: aomap_fragment,
  21981. aomap_pars_fragment: aomap_pars_fragment,
  21982. begin_vertex: begin_vertex,
  21983. beginnormal_vertex: beginnormal_vertex,
  21984. bsdfs: bsdfs,
  21985. bumpmap_pars_fragment: bumpmap_pars_fragment,
  21986. clipping_planes_fragment: clipping_planes_fragment,
  21987. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  21988. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  21989. clipping_planes_vertex: clipping_planes_vertex,
  21990. color_fragment: color_fragment,
  21991. color_pars_fragment: color_pars_fragment,
  21992. color_pars_vertex: color_pars_vertex,
  21993. color_vertex: color_vertex,
  21994. common: common,
  21995. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  21996. defaultnormal_vertex: defaultnormal_vertex,
  21997. displacementmap_pars_vertex: displacementmap_pars_vertex,
  21998. displacementmap_vertex: displacementmap_vertex,
  21999. emissivemap_fragment: emissivemap_fragment,
  22000. emissivemap_pars_fragment: emissivemap_pars_fragment,
  22001. encodings_fragment: encodings_fragment,
  22002. encodings_pars_fragment: encodings_pars_fragment,
  22003. envmap_fragment: envmap_fragment,
  22004. envmap_pars_fragment: envmap_pars_fragment,
  22005. envmap_pars_vertex: envmap_pars_vertex,
  22006. envmap_vertex: envmap_vertex,
  22007. fog_vertex: fog_vertex,
  22008. fog_pars_vertex: fog_pars_vertex,
  22009. fog_fragment: fog_fragment,
  22010. fog_pars_fragment: fog_pars_fragment,
  22011. gradientmap_pars_fragment: gradientmap_pars_fragment,
  22012. lightmap_fragment: lightmap_fragment,
  22013. lightmap_pars_fragment: lightmap_pars_fragment,
  22014. lights_lambert_vertex: lights_lambert_vertex,
  22015. lights_pars: lights_pars,
  22016. lights_phong_fragment: lights_phong_fragment,
  22017. lights_phong_pars_fragment: lights_phong_pars_fragment,
  22018. lights_physical_fragment: lights_physical_fragment,
  22019. lights_physical_pars_fragment: lights_physical_pars_fragment,
  22020. lights_template: lights_template,
  22021. logdepthbuf_fragment: logdepthbuf_fragment,
  22022. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  22023. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  22024. logdepthbuf_vertex: logdepthbuf_vertex,
  22025. map_fragment: map_fragment,
  22026. map_pars_fragment: map_pars_fragment,
  22027. map_particle_fragment: map_particle_fragment,
  22028. map_particle_pars_fragment: map_particle_pars_fragment,
  22029. metalnessmap_fragment: metalnessmap_fragment,
  22030. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  22031. morphnormal_vertex: morphnormal_vertex,
  22032. morphtarget_pars_vertex: morphtarget_pars_vertex,
  22033. morphtarget_vertex: morphtarget_vertex,
  22034. normal_fragment: normal_fragment,
  22035. normalmap_pars_fragment: normalmap_pars_fragment,
  22036. packing: packing,
  22037. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  22038. project_vertex: project_vertex,
  22039. dithering_fragment: dithering_fragment,
  22040. dithering_pars_fragment: dithering_pars_fragment,
  22041. roughnessmap_fragment: roughnessmap_fragment,
  22042. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  22043. shadowmap_pars_fragment: shadowmap_pars_fragment,
  22044. shadowmap_pars_vertex: shadowmap_pars_vertex,
  22045. shadowmap_vertex: shadowmap_vertex,
  22046. shadowmask_pars_fragment: shadowmask_pars_fragment,
  22047. skinbase_vertex: skinbase_vertex,
  22048. skinning_pars_vertex: skinning_pars_vertex,
  22049. skinning_vertex: skinning_vertex,
  22050. skinnormal_vertex: skinnormal_vertex,
  22051. specularmap_fragment: specularmap_fragment,
  22052. specularmap_pars_fragment: specularmap_pars_fragment,
  22053. tonemapping_fragment: tonemapping_fragment,
  22054. tonemapping_pars_fragment: tonemapping_pars_fragment,
  22055. uv_pars_fragment: uv_pars_fragment,
  22056. uv_pars_vertex: uv_pars_vertex,
  22057. uv_vertex: uv_vertex,
  22058. uv2_pars_fragment: uv2_pars_fragment,
  22059. uv2_pars_vertex: uv2_pars_vertex,
  22060. uv2_vertex: uv2_vertex,
  22061. worldpos_vertex: worldpos_vertex,
  22062. cube_frag: cube_frag,
  22063. cube_vert: cube_vert,
  22064. depth_frag: depth_frag,
  22065. depth_vert: depth_vert,
  22066. distanceRGBA_frag: distanceRGBA_frag,
  22067. distanceRGBA_vert: distanceRGBA_vert,
  22068. equirect_frag: equirect_frag,
  22069. equirect_vert: equirect_vert,
  22070. linedashed_frag: linedashed_frag,
  22071. linedashed_vert: linedashed_vert,
  22072. meshbasic_frag: meshbasic_frag,
  22073. meshbasic_vert: meshbasic_vert,
  22074. meshlambert_frag: meshlambert_frag,
  22075. meshlambert_vert: meshlambert_vert,
  22076. meshphong_frag: meshphong_frag,
  22077. meshphong_vert: meshphong_vert,
  22078. meshphysical_frag: meshphysical_frag,
  22079. meshphysical_vert: meshphysical_vert,
  22080. normal_frag: normal_frag,
  22081. normal_vert: normal_vert,
  22082. points_frag: points_frag,
  22083. points_vert: points_vert,
  22084. shadow_frag: shadow_frag,
  22085. shadow_vert: shadow_vert
  22086. };
  22087. /**
  22088. * @author alteredq / http://alteredqualia.com/
  22089. * @author mrdoob / http://mrdoob.com/
  22090. * @author mikael emtinger / http://gomo.se/
  22091. */
  22092. var ShaderLib = {
  22093. basic: {
  22094. uniforms: UniformsUtils.merge( [
  22095. UniformsLib.common,
  22096. UniformsLib.specularmap,
  22097. UniformsLib.envmap,
  22098. UniformsLib.aomap,
  22099. UniformsLib.lightmap,
  22100. UniformsLib.fog
  22101. ] ),
  22102. vertexShader: ShaderChunk.meshbasic_vert,
  22103. fragmentShader: ShaderChunk.meshbasic_frag
  22104. },
  22105. lambert: {
  22106. uniforms: UniformsUtils.merge( [
  22107. UniformsLib.common,
  22108. UniformsLib.specularmap,
  22109. UniformsLib.envmap,
  22110. UniformsLib.aomap,
  22111. UniformsLib.lightmap,
  22112. UniformsLib.emissivemap,
  22113. UniformsLib.fog,
  22114. UniformsLib.lights,
  22115. {
  22116. emissive: { value: new Color( 0x000000 ) }
  22117. }
  22118. ] ),
  22119. vertexShader: ShaderChunk.meshlambert_vert,
  22120. fragmentShader: ShaderChunk.meshlambert_frag
  22121. },
  22122. phong: {
  22123. uniforms: UniformsUtils.merge( [
  22124. UniformsLib.common,
  22125. UniformsLib.specularmap,
  22126. UniformsLib.envmap,
  22127. UniformsLib.aomap,
  22128. UniformsLib.lightmap,
  22129. UniformsLib.emissivemap,
  22130. UniformsLib.bumpmap,
  22131. UniformsLib.normalmap,
  22132. UniformsLib.displacementmap,
  22133. UniformsLib.gradientmap,
  22134. UniformsLib.fog,
  22135. UniformsLib.lights,
  22136. {
  22137. emissive: { value: new Color( 0x000000 ) },
  22138. specular: { value: new Color( 0x111111 ) },
  22139. shininess: { value: 30 }
  22140. }
  22141. ] ),
  22142. vertexShader: ShaderChunk.meshphong_vert,
  22143. fragmentShader: ShaderChunk.meshphong_frag
  22144. },
  22145. standard: {
  22146. uniforms: UniformsUtils.merge( [
  22147. UniformsLib.common,
  22148. UniformsLib.envmap,
  22149. UniformsLib.aomap,
  22150. UniformsLib.lightmap,
  22151. UniformsLib.emissivemap,
  22152. UniformsLib.bumpmap,
  22153. UniformsLib.normalmap,
  22154. UniformsLib.displacementmap,
  22155. UniformsLib.roughnessmap,
  22156. UniformsLib.metalnessmap,
  22157. UniformsLib.fog,
  22158. UniformsLib.lights,
  22159. {
  22160. emissive: { value: new Color( 0x000000 ) },
  22161. roughness: { value: 0.5 },
  22162. metalness: { value: 0.5 },
  22163. envMapIntensity: { value: 1 } // temporary
  22164. }
  22165. ] ),
  22166. vertexShader: ShaderChunk.meshphysical_vert,
  22167. fragmentShader: ShaderChunk.meshphysical_frag
  22168. },
  22169. points: {
  22170. uniforms: UniformsUtils.merge( [
  22171. UniformsLib.points,
  22172. UniformsLib.fog
  22173. ] ),
  22174. vertexShader: ShaderChunk.points_vert,
  22175. fragmentShader: ShaderChunk.points_frag
  22176. },
  22177. dashed: {
  22178. uniforms: UniformsUtils.merge( [
  22179. UniformsLib.common,
  22180. UniformsLib.fog,
  22181. {
  22182. scale: { value: 1 },
  22183. dashSize: { value: 1 },
  22184. totalSize: { value: 2 }
  22185. }
  22186. ] ),
  22187. vertexShader: ShaderChunk.linedashed_vert,
  22188. fragmentShader: ShaderChunk.linedashed_frag
  22189. },
  22190. depth: {
  22191. uniforms: UniformsUtils.merge( [
  22192. UniformsLib.common,
  22193. UniformsLib.displacementmap
  22194. ] ),
  22195. vertexShader: ShaderChunk.depth_vert,
  22196. fragmentShader: ShaderChunk.depth_frag
  22197. },
  22198. normal: {
  22199. uniforms: UniformsUtils.merge( [
  22200. UniformsLib.common,
  22201. UniformsLib.bumpmap,
  22202. UniformsLib.normalmap,
  22203. UniformsLib.displacementmap,
  22204. {
  22205. opacity: { value: 1.0 }
  22206. }
  22207. ] ),
  22208. vertexShader: ShaderChunk.normal_vert,
  22209. fragmentShader: ShaderChunk.normal_frag
  22210. },
  22211. /* -------------------------------------------------------------------------
  22212. // Cube map shader
  22213. ------------------------------------------------------------------------- */
  22214. cube: {
  22215. uniforms: {
  22216. tCube: { value: null },
  22217. tFlip: { value: - 1 },
  22218. opacity: { value: 1.0 }
  22219. },
  22220. vertexShader: ShaderChunk.cube_vert,
  22221. fragmentShader: ShaderChunk.cube_frag
  22222. },
  22223. equirect: {
  22224. uniforms: {
  22225. tEquirect: { value: null },
  22226. },
  22227. vertexShader: ShaderChunk.equirect_vert,
  22228. fragmentShader: ShaderChunk.equirect_frag
  22229. },
  22230. distanceRGBA: {
  22231. uniforms: UniformsUtils.merge( [
  22232. UniformsLib.common,
  22233. UniformsLib.displacementmap,
  22234. {
  22235. referencePosition: { value: new Vector3() },
  22236. nearDistance: { value: 1 },
  22237. farDistance: { value: 1000 }
  22238. }
  22239. ] ),
  22240. vertexShader: ShaderChunk.distanceRGBA_vert,
  22241. fragmentShader: ShaderChunk.distanceRGBA_frag
  22242. },
  22243. shadow: {
  22244. uniforms: UniformsUtils.merge( [
  22245. UniformsLib.lights,
  22246. UniformsLib.fog,
  22247. {
  22248. color: { value: new Color( 0x00000 ) },
  22249. opacity: { value: 1.0 }
  22250. },
  22251. ] ),
  22252. vertexShader: ShaderChunk.shadow_vert,
  22253. fragmentShader: ShaderChunk.shadow_frag
  22254. }
  22255. };
  22256. ShaderLib.physical = {
  22257. uniforms: UniformsUtils.merge( [
  22258. ShaderLib.standard.uniforms,
  22259. {
  22260. clearCoat: { value: 0 },
  22261. clearCoatRoughness: { value: 0 }
  22262. }
  22263. ] ),
  22264. vertexShader: ShaderChunk.meshphysical_vert,
  22265. fragmentShader: ShaderChunk.meshphysical_frag
  22266. };
  22267. /**
  22268. * @author bhouston / http://clara.io
  22269. */
  22270. function Box2( min, max ) {
  22271. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  22272. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  22273. }
  22274. Object.assign( Box2.prototype, {
  22275. set: function ( min, max ) {
  22276. this.min.copy( min );
  22277. this.max.copy( max );
  22278. return this;
  22279. },
  22280. setFromPoints: function ( points ) {
  22281. this.makeEmpty();
  22282. for ( var i = 0, il = points.length; i < il; i ++ ) {
  22283. this.expandByPoint( points[ i ] );
  22284. }
  22285. return this;
  22286. },
  22287. setFromCenterAndSize: function () {
  22288. var v1 = new Vector2();
  22289. return function setFromCenterAndSize( center, size ) {
  22290. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  22291. this.min.copy( center ).sub( halfSize );
  22292. this.max.copy( center ).add( halfSize );
  22293. return this;
  22294. };
  22295. }(),
  22296. clone: function () {
  22297. return new this.constructor().copy( this );
  22298. },
  22299. copy: function ( box ) {
  22300. this.min.copy( box.min );
  22301. this.max.copy( box.max );
  22302. return this;
  22303. },
  22304. makeEmpty: function () {
  22305. this.min.x = this.min.y = + Infinity;
  22306. this.max.x = this.max.y = - Infinity;
  22307. return this;
  22308. },
  22309. isEmpty: function () {
  22310. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  22311. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  22312. },
  22313. getCenter: function ( optionalTarget ) {
  22314. var result = optionalTarget || new Vector2();
  22315. return this.isEmpty() ? result.set( 0, 0 ) : result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  22316. },
  22317. getSize: function ( optionalTarget ) {
  22318. var result = optionalTarget || new Vector2();
  22319. return this.isEmpty() ? result.set( 0, 0 ) : result.subVectors( this.max, this.min );
  22320. },
  22321. expandByPoint: function ( point ) {
  22322. this.min.min( point );
  22323. this.max.max( point );
  22324. return this;
  22325. },
  22326. expandByVector: function ( vector ) {
  22327. this.min.sub( vector );
  22328. this.max.add( vector );
  22329. return this;
  22330. },
  22331. expandByScalar: function ( scalar ) {
  22332. this.min.addScalar( - scalar );
  22333. this.max.addScalar( scalar );
  22334. return this;
  22335. },
  22336. containsPoint: function ( point ) {
  22337. return point.x < this.min.x || point.x > this.max.x ||
  22338. point.y < this.min.y || point.y > this.max.y ? false : true;
  22339. },
  22340. containsBox: function ( box ) {
  22341. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  22342. this.min.y <= box.min.y && box.max.y <= this.max.y;
  22343. },
  22344. getParameter: function ( point, optionalTarget ) {
  22345. // This can potentially have a divide by zero if the box
  22346. // has a size dimension of 0.
  22347. var result = optionalTarget || new Vector2();
  22348. return result.set(
  22349. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  22350. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  22351. );
  22352. },
  22353. intersectsBox: function ( box ) {
  22354. // using 4 splitting planes to rule out intersections
  22355. return box.max.x < this.min.x || box.min.x > this.max.x ||
  22356. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  22357. },
  22358. clampPoint: function ( point, optionalTarget ) {
  22359. var result = optionalTarget || new Vector2();
  22360. return result.copy( point ).clamp( this.min, this.max );
  22361. },
  22362. distanceToPoint: function () {
  22363. var v1 = new Vector2();
  22364. return function distanceToPoint( point ) {
  22365. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  22366. return clampedPoint.sub( point ).length();
  22367. };
  22368. }(),
  22369. intersect: function ( box ) {
  22370. this.min.max( box.min );
  22371. this.max.min( box.max );
  22372. return this;
  22373. },
  22374. union: function ( box ) {
  22375. this.min.min( box.min );
  22376. this.max.max( box.max );
  22377. return this;
  22378. },
  22379. translate: function ( offset ) {
  22380. this.min.add( offset );
  22381. this.max.add( offset );
  22382. return this;
  22383. },
  22384. equals: function ( box ) {
  22385. return box.min.equals( this.min ) && box.max.equals( this.max );
  22386. }
  22387. } );
  22388. /**
  22389. * @author mikael emtinger / http://gomo.se/
  22390. * @author alteredq / http://alteredqualia.com/
  22391. */
  22392. function WebGLFlareRenderer( renderer, gl, state, textures, capabilities ) {
  22393. var vertexBuffer, elementBuffer;
  22394. var shader, program, attributes, uniforms;
  22395. var tempTexture, occlusionTexture;
  22396. function init() {
  22397. var vertices = new Float32Array( [
  22398. - 1, - 1, 0, 0,
  22399. 1, - 1, 1, 0,
  22400. 1, 1, 1, 1,
  22401. - 1, 1, 0, 1
  22402. ] );
  22403. var faces = new Uint16Array( [
  22404. 0, 1, 2,
  22405. 0, 2, 3
  22406. ] );
  22407. // buffers
  22408. vertexBuffer = gl.createBuffer();
  22409. elementBuffer = gl.createBuffer();
  22410. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  22411. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  22412. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  22413. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  22414. // textures
  22415. tempTexture = gl.createTexture();
  22416. occlusionTexture = gl.createTexture();
  22417. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  22418. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  22419. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  22420. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  22421. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  22422. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  22423. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  22424. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  22425. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  22426. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  22427. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  22428. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  22429. shader = {
  22430. vertexShader: [
  22431. 'uniform lowp int renderType;',
  22432. 'uniform vec3 screenPosition;',
  22433. 'uniform vec2 scale;',
  22434. 'uniform float rotation;',
  22435. 'uniform sampler2D occlusionMap;',
  22436. 'attribute vec2 position;',
  22437. 'attribute vec2 uv;',
  22438. 'varying vec2 vUV;',
  22439. 'varying float vVisibility;',
  22440. 'void main() {',
  22441. ' vUV = uv;',
  22442. ' vec2 pos = position;',
  22443. ' if ( renderType == 2 ) {',
  22444. ' vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );',
  22445. ' visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );',
  22446. ' visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );',
  22447. ' visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );',
  22448. ' visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );',
  22449. ' visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );',
  22450. ' visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );',
  22451. ' visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );',
  22452. ' visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );',
  22453. ' vVisibility = visibility.r / 9.0;',
  22454. ' vVisibility *= 1.0 - visibility.g / 9.0;',
  22455. ' vVisibility *= visibility.b / 9.0;',
  22456. ' vVisibility *= 1.0 - visibility.a / 9.0;',
  22457. ' pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;',
  22458. ' pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;',
  22459. ' }',
  22460. ' gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );',
  22461. '}'
  22462. ].join( '\n' ),
  22463. fragmentShader: [
  22464. 'uniform lowp int renderType;',
  22465. 'uniform sampler2D map;',
  22466. 'uniform float opacity;',
  22467. 'uniform vec3 color;',
  22468. 'varying vec2 vUV;',
  22469. 'varying float vVisibility;',
  22470. 'void main() {',
  22471. // pink square
  22472. ' if ( renderType == 0 ) {',
  22473. ' gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );',
  22474. // restore
  22475. ' } else if ( renderType == 1 ) {',
  22476. ' gl_FragColor = texture2D( map, vUV );',
  22477. // flare
  22478. ' } else {',
  22479. ' vec4 texture = texture2D( map, vUV );',
  22480. ' texture.a *= opacity * vVisibility;',
  22481. ' gl_FragColor = texture;',
  22482. ' gl_FragColor.rgb *= color;',
  22483. ' }',
  22484. '}'
  22485. ].join( '\n' )
  22486. };
  22487. program = createProgram( shader );
  22488. attributes = {
  22489. vertex: gl.getAttribLocation( program, 'position' ),
  22490. uv: gl.getAttribLocation( program, 'uv' )
  22491. };
  22492. uniforms = {
  22493. renderType: gl.getUniformLocation( program, 'renderType' ),
  22494. map: gl.getUniformLocation( program, 'map' ),
  22495. occlusionMap: gl.getUniformLocation( program, 'occlusionMap' ),
  22496. opacity: gl.getUniformLocation( program, 'opacity' ),
  22497. color: gl.getUniformLocation( program, 'color' ),
  22498. scale: gl.getUniformLocation( program, 'scale' ),
  22499. rotation: gl.getUniformLocation( program, 'rotation' ),
  22500. screenPosition: gl.getUniformLocation( program, 'screenPosition' )
  22501. };
  22502. }
  22503. /*
  22504. * Render lens flares
  22505. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  22506. * reads these back and calculates occlusion.
  22507. */
  22508. this.render = function ( flares, scene, camera, viewport ) {
  22509. if ( flares.length === 0 ) return;
  22510. var tempPosition = new Vector3();
  22511. var invAspect = viewport.w / viewport.z,
  22512. halfViewportWidth = viewport.z * 0.5,
  22513. halfViewportHeight = viewport.w * 0.5;
  22514. var size = 16 / viewport.w,
  22515. scale = new Vector2( size * invAspect, size );
  22516. var screenPosition = new Vector3( 1, 1, 0 ),
  22517. screenPositionPixels = new Vector2( 1, 1 );
  22518. var validArea = new Box2();
  22519. validArea.min.set( viewport.x, viewport.y );
  22520. validArea.max.set( viewport.x + ( viewport.z - 16 ), viewport.y + ( viewport.w - 16 ) );
  22521. if ( program === undefined ) {
  22522. init();
  22523. }
  22524. state.useProgram( program );
  22525. state.initAttributes();
  22526. state.enableAttribute( attributes.vertex );
  22527. state.enableAttribute( attributes.uv );
  22528. state.disableUnusedAttributes();
  22529. // loop through all lens flares to update their occlusion and positions
  22530. // setup gl and common used attribs/uniforms
  22531. gl.uniform1i( uniforms.occlusionMap, 0 );
  22532. gl.uniform1i( uniforms.map, 1 );
  22533. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  22534. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  22535. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  22536. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  22537. state.disable( gl.CULL_FACE );
  22538. state.buffers.depth.setMask( false );
  22539. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  22540. size = 16 / viewport.w;
  22541. scale.set( size * invAspect, size );
  22542. // calc object screen position
  22543. var flare = flares[ i ];
  22544. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  22545. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  22546. tempPosition.applyMatrix4( camera.projectionMatrix );
  22547. // setup arrays for gl programs
  22548. screenPosition.copy( tempPosition );
  22549. // horizontal and vertical coordinate of the lower left corner of the pixels to copy
  22550. screenPositionPixels.x = viewport.x + ( screenPosition.x * halfViewportWidth ) + halfViewportWidth - 8;
  22551. screenPositionPixels.y = viewport.y + ( screenPosition.y * halfViewportHeight ) + halfViewportHeight - 8;
  22552. // screen cull
  22553. if ( validArea.containsPoint( screenPositionPixels ) === true ) {
  22554. // save current RGB to temp texture
  22555. state.activeTexture( gl.TEXTURE0 );
  22556. state.bindTexture( gl.TEXTURE_2D, null );
  22557. state.activeTexture( gl.TEXTURE1 );
  22558. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  22559. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  22560. // render pink quad
  22561. gl.uniform1i( uniforms.renderType, 0 );
  22562. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  22563. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  22564. state.disable( gl.BLEND );
  22565. state.enable( gl.DEPTH_TEST );
  22566. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  22567. // copy result to occlusionMap
  22568. state.activeTexture( gl.TEXTURE0 );
  22569. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  22570. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  22571. // restore graphics
  22572. gl.uniform1i( uniforms.renderType, 1 );
  22573. state.disable( gl.DEPTH_TEST );
  22574. state.activeTexture( gl.TEXTURE1 );
  22575. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  22576. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  22577. // update object positions
  22578. flare.positionScreen.copy( screenPosition );
  22579. if ( flare.customUpdateCallback ) {
  22580. flare.customUpdateCallback( flare );
  22581. } else {
  22582. flare.updateLensFlares();
  22583. }
  22584. // render flares
  22585. gl.uniform1i( uniforms.renderType, 2 );
  22586. state.enable( gl.BLEND );
  22587. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  22588. var sprite = flare.lensFlares[ j ];
  22589. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  22590. screenPosition.x = sprite.x;
  22591. screenPosition.y = sprite.y;
  22592. screenPosition.z = sprite.z;
  22593. size = sprite.size * sprite.scale / viewport.w;
  22594. scale.x = size * invAspect;
  22595. scale.y = size;
  22596. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  22597. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  22598. gl.uniform1f( uniforms.rotation, sprite.rotation );
  22599. gl.uniform1f( uniforms.opacity, sprite.opacity );
  22600. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  22601. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  22602. textures.setTexture2D( sprite.texture, 1 );
  22603. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  22604. }
  22605. }
  22606. }
  22607. }
  22608. // restore gl
  22609. state.enable( gl.CULL_FACE );
  22610. state.enable( gl.DEPTH_TEST );
  22611. state.buffers.depth.setMask( true );
  22612. state.reset();
  22613. };
  22614. function createProgram( shader ) {
  22615. var program = gl.createProgram();
  22616. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  22617. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  22618. var prefix = 'precision ' + capabilities.precision + ' float;\n';
  22619. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  22620. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  22621. gl.compileShader( fragmentShader );
  22622. gl.compileShader( vertexShader );
  22623. gl.attachShader( program, fragmentShader );
  22624. gl.attachShader( program, vertexShader );
  22625. gl.linkProgram( program );
  22626. return program;
  22627. }
  22628. }
  22629. /**
  22630. * @author mrdoob / http://mrdoob.com/
  22631. */
  22632. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  22633. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  22634. this.needsUpdate = true;
  22635. }
  22636. CanvasTexture.prototype = Object.create( Texture.prototype );
  22637. CanvasTexture.prototype.constructor = CanvasTexture;
  22638. /**
  22639. * @author mikael emtinger / http://gomo.se/
  22640. * @author alteredq / http://alteredqualia.com/
  22641. */
  22642. function WebGLSpriteRenderer( renderer, gl, state, textures, capabilities ) {
  22643. var vertexBuffer, elementBuffer;
  22644. var program, attributes, uniforms;
  22645. var texture;
  22646. // decompose matrixWorld
  22647. var spritePosition = new Vector3();
  22648. var spriteRotation = new Quaternion();
  22649. var spriteScale = new Vector3();
  22650. function init() {
  22651. var vertices = new Float32Array( [
  22652. - 0.5, - 0.5, 0, 0,
  22653. 0.5, - 0.5, 1, 0,
  22654. 0.5, 0.5, 1, 1,
  22655. - 0.5, 0.5, 0, 1
  22656. ] );
  22657. var faces = new Uint16Array( [
  22658. 0, 1, 2,
  22659. 0, 2, 3
  22660. ] );
  22661. vertexBuffer = gl.createBuffer();
  22662. elementBuffer = gl.createBuffer();
  22663. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  22664. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  22665. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  22666. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  22667. program = createProgram();
  22668. attributes = {
  22669. position: gl.getAttribLocation( program, 'position' ),
  22670. uv: gl.getAttribLocation( program, 'uv' )
  22671. };
  22672. uniforms = {
  22673. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  22674. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  22675. rotation: gl.getUniformLocation( program, 'rotation' ),
  22676. scale: gl.getUniformLocation( program, 'scale' ),
  22677. color: gl.getUniformLocation( program, 'color' ),
  22678. map: gl.getUniformLocation( program, 'map' ),
  22679. opacity: gl.getUniformLocation( program, 'opacity' ),
  22680. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  22681. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  22682. fogType: gl.getUniformLocation( program, 'fogType' ),
  22683. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  22684. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  22685. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  22686. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  22687. fogDepth: gl.getUniformLocation( program, 'fogDepth' ),
  22688. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  22689. };
  22690. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  22691. canvas.width = 8;
  22692. canvas.height = 8;
  22693. var context = canvas.getContext( '2d' );
  22694. context.fillStyle = 'white';
  22695. context.fillRect( 0, 0, 8, 8 );
  22696. texture = new CanvasTexture( canvas );
  22697. }
  22698. this.render = function ( sprites, scene, camera ) {
  22699. if ( sprites.length === 0 ) return;
  22700. // setup gl
  22701. if ( program === undefined ) {
  22702. init();
  22703. }
  22704. state.useProgram( program );
  22705. state.initAttributes();
  22706. state.enableAttribute( attributes.position );
  22707. state.enableAttribute( attributes.uv );
  22708. state.disableUnusedAttributes();
  22709. state.disable( gl.CULL_FACE );
  22710. state.enable( gl.BLEND );
  22711. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  22712. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  22713. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  22714. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  22715. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  22716. state.activeTexture( gl.TEXTURE0 );
  22717. gl.uniform1i( uniforms.map, 0 );
  22718. var oldFogType = 0;
  22719. var sceneFogType = 0;
  22720. var fog = scene.fog;
  22721. if ( fog ) {
  22722. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  22723. if ( fog.isFog ) {
  22724. gl.uniform1f( uniforms.fogNear, fog.near );
  22725. gl.uniform1f( uniforms.fogFar, fog.far );
  22726. gl.uniform1i( uniforms.fogType, 1 );
  22727. oldFogType = 1;
  22728. sceneFogType = 1;
  22729. } else if ( fog.isFogExp2 ) {
  22730. gl.uniform1f( uniforms.fogDensity, fog.density );
  22731. gl.uniform1i( uniforms.fogType, 2 );
  22732. oldFogType = 2;
  22733. sceneFogType = 2;
  22734. }
  22735. } else {
  22736. gl.uniform1i( uniforms.fogType, 0 );
  22737. oldFogType = 0;
  22738. sceneFogType = 0;
  22739. }
  22740. // update positions and sort
  22741. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  22742. var sprite = sprites[ i ];
  22743. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  22744. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  22745. }
  22746. sprites.sort( painterSortStable );
  22747. // render all sprites
  22748. var scale = [];
  22749. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  22750. var sprite = sprites[ i ];
  22751. var material = sprite.material;
  22752. if ( material.visible === false ) continue;
  22753. sprite.onBeforeRender( renderer, scene, camera, undefined, material, undefined );
  22754. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  22755. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  22756. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  22757. scale[ 0 ] = spriteScale.x;
  22758. scale[ 1 ] = spriteScale.y;
  22759. var fogType = 0;
  22760. if ( scene.fog && material.fog ) {
  22761. fogType = sceneFogType;
  22762. }
  22763. if ( oldFogType !== fogType ) {
  22764. gl.uniform1i( uniforms.fogType, fogType );
  22765. oldFogType = fogType;
  22766. }
  22767. if ( material.map !== null ) {
  22768. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  22769. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  22770. } else {
  22771. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  22772. gl.uniform2f( uniforms.uvScale, 1, 1 );
  22773. }
  22774. gl.uniform1f( uniforms.opacity, material.opacity );
  22775. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  22776. gl.uniform1f( uniforms.rotation, material.rotation );
  22777. gl.uniform2fv( uniforms.scale, scale );
  22778. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  22779. state.buffers.depth.setTest( material.depthTest );
  22780. state.buffers.depth.setMask( material.depthWrite );
  22781. state.buffers.color.setMask( material.colorWrite );
  22782. textures.setTexture2D( material.map || texture, 0 );
  22783. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  22784. sprite.onAfterRender( renderer, scene, camera, undefined, material, undefined );
  22785. }
  22786. // restore gl
  22787. state.enable( gl.CULL_FACE );
  22788. state.reset();
  22789. };
  22790. function createProgram() {
  22791. var program = gl.createProgram();
  22792. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  22793. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  22794. gl.shaderSource( vertexShader, [
  22795. 'precision ' + capabilities.precision + ' float;',
  22796. '#define SHADER_NAME ' + 'SpriteMaterial',
  22797. 'uniform mat4 modelViewMatrix;',
  22798. 'uniform mat4 projectionMatrix;',
  22799. 'uniform float rotation;',
  22800. 'uniform vec2 scale;',
  22801. 'uniform vec2 uvOffset;',
  22802. 'uniform vec2 uvScale;',
  22803. 'attribute vec2 position;',
  22804. 'attribute vec2 uv;',
  22805. 'varying vec2 vUV;',
  22806. 'varying float fogDepth;',
  22807. 'void main() {',
  22808. ' vUV = uvOffset + uv * uvScale;',
  22809. ' vec2 alignedPosition = position * scale;',
  22810. ' vec2 rotatedPosition;',
  22811. ' rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  22812. ' rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  22813. ' vec4 mvPosition;',
  22814. ' mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  22815. ' mvPosition.xy += rotatedPosition;',
  22816. ' gl_Position = projectionMatrix * mvPosition;',
  22817. ' fogDepth = - mvPosition.z;',
  22818. '}'
  22819. ].join( '\n' ) );
  22820. gl.shaderSource( fragmentShader, [
  22821. 'precision ' + capabilities.precision + ' float;',
  22822. '#define SHADER_NAME ' + 'SpriteMaterial',
  22823. 'uniform vec3 color;',
  22824. 'uniform sampler2D map;',
  22825. 'uniform float opacity;',
  22826. 'uniform int fogType;',
  22827. 'uniform vec3 fogColor;',
  22828. 'uniform float fogDensity;',
  22829. 'uniform float fogNear;',
  22830. 'uniform float fogFar;',
  22831. 'uniform float alphaTest;',
  22832. 'varying vec2 vUV;',
  22833. 'varying float fogDepth;',
  22834. 'void main() {',
  22835. ' vec4 texture = texture2D( map, vUV );',
  22836. ' gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  22837. ' if ( gl_FragColor.a < alphaTest ) discard;',
  22838. ' if ( fogType > 0 ) {',
  22839. ' float fogFactor = 0.0;',
  22840. ' if ( fogType == 1 ) {',
  22841. ' fogFactor = smoothstep( fogNear, fogFar, fogDepth );',
  22842. ' } else {',
  22843. ' const float LOG2 = 1.442695;',
  22844. ' fogFactor = exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 );',
  22845. ' fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  22846. ' }',
  22847. ' gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );',
  22848. ' }',
  22849. '}'
  22850. ].join( '\n' ) );
  22851. gl.compileShader( vertexShader );
  22852. gl.compileShader( fragmentShader );
  22853. gl.attachShader( program, vertexShader );
  22854. gl.attachShader( program, fragmentShader );
  22855. gl.linkProgram( program );
  22856. return program;
  22857. }
  22858. function painterSortStable( a, b ) {
  22859. if ( a.renderOrder !== b.renderOrder ) {
  22860. return a.renderOrder - b.renderOrder;
  22861. } else if ( a.z !== b.z ) {
  22862. return b.z - a.z;
  22863. } else {
  22864. return b.id - a.id;
  22865. }
  22866. }
  22867. }
  22868. /**
  22869. * @author mrdoob / http://mrdoob.com/
  22870. * @author alteredq / http://alteredqualia.com/
  22871. * @author bhouston / http://clara.io
  22872. */
  22873. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  22874. this.planes = [
  22875. ( p0 !== undefined ) ? p0 : new Plane(),
  22876. ( p1 !== undefined ) ? p1 : new Plane(),
  22877. ( p2 !== undefined ) ? p2 : new Plane(),
  22878. ( p3 !== undefined ) ? p3 : new Plane(),
  22879. ( p4 !== undefined ) ? p4 : new Plane(),
  22880. ( p5 !== undefined ) ? p5 : new Plane()
  22881. ];
  22882. }
  22883. Object.assign( Frustum.prototype, {
  22884. set: function ( p0, p1, p2, p3, p4, p5 ) {
  22885. var planes = this.planes;
  22886. planes[ 0 ].copy( p0 );
  22887. planes[ 1 ].copy( p1 );
  22888. planes[ 2 ].copy( p2 );
  22889. planes[ 3 ].copy( p3 );
  22890. planes[ 4 ].copy( p4 );
  22891. planes[ 5 ].copy( p5 );
  22892. return this;
  22893. },
  22894. clone: function () {
  22895. return new this.constructor().copy( this );
  22896. },
  22897. copy: function ( frustum ) {
  22898. var planes = this.planes;
  22899. for ( var i = 0; i < 6; i ++ ) {
  22900. planes[ i ].copy( frustum.planes[ i ] );
  22901. }
  22902. return this;
  22903. },
  22904. setFromMatrix: function ( m ) {
  22905. var planes = this.planes;
  22906. var me = m.elements;
  22907. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  22908. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  22909. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  22910. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  22911. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  22912. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  22913. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  22914. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  22915. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  22916. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  22917. return this;
  22918. },
  22919. intersectsObject: function () {
  22920. var sphere = new Sphere();
  22921. return function intersectsObject( object ) {
  22922. var geometry = object.geometry;
  22923. if ( geometry.boundingSphere === null )
  22924. geometry.computeBoundingSphere();
  22925. sphere.copy( geometry.boundingSphere )
  22926. .applyMatrix4( object.matrixWorld );
  22927. return this.intersectsSphere( sphere );
  22928. };
  22929. }(),
  22930. intersectsSprite: function () {
  22931. var sphere = new Sphere();
  22932. return function intersectsSprite( sprite ) {
  22933. sphere.center.set( 0, 0, 0 );
  22934. sphere.radius = 0.7071067811865476;
  22935. sphere.applyMatrix4( sprite.matrixWorld );
  22936. return this.intersectsSphere( sphere );
  22937. };
  22938. }(),
  22939. intersectsSphere: function ( sphere ) {
  22940. var planes = this.planes;
  22941. var center = sphere.center;
  22942. var negRadius = - sphere.radius;
  22943. for ( var i = 0; i < 6; i ++ ) {
  22944. var distance = planes[ i ].distanceToPoint( center );
  22945. if ( distance < negRadius ) {
  22946. return false;
  22947. }
  22948. }
  22949. return true;
  22950. },
  22951. intersectsBox: function () {
  22952. var p1 = new Vector3(),
  22953. p2 = new Vector3();
  22954. return function intersectsBox( box ) {
  22955. var planes = this.planes;
  22956. for ( var i = 0; i < 6; i ++ ) {
  22957. var plane = planes[ i ];
  22958. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  22959. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  22960. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  22961. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  22962. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  22963. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  22964. var d1 = plane.distanceToPoint( p1 );
  22965. var d2 = plane.distanceToPoint( p2 );
  22966. // if both outside plane, no intersection
  22967. if ( d1 < 0 && d2 < 0 ) {
  22968. return false;
  22969. }
  22970. }
  22971. return true;
  22972. };
  22973. }(),
  22974. containsPoint: function ( point ) {
  22975. var planes = this.planes;
  22976. for ( var i = 0; i < 6; i ++ ) {
  22977. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  22978. return false;
  22979. }
  22980. }
  22981. return true;
  22982. }
  22983. } );
  22984. /**
  22985. * @author alteredq / http://alteredqualia.com/
  22986. * @author mrdoob / http://mrdoob.com/
  22987. */
  22988. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  22989. var _frustum = new Frustum(),
  22990. _projScreenMatrix = new Matrix4(),
  22991. _shadowMapSize = new Vector2(),
  22992. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  22993. _lookTarget = new Vector3(),
  22994. _lightPositionWorld = new Vector3(),
  22995. _MorphingFlag = 1,
  22996. _SkinningFlag = 2,
  22997. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  22998. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  22999. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  23000. _materialCache = {};
  23001. var cubeDirections = [
  23002. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  23003. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  23004. ];
  23005. var cubeUps = [
  23006. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  23007. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  23008. ];
  23009. var cube2DViewPorts = [
  23010. new Vector4(), new Vector4(), new Vector4(),
  23011. new Vector4(), new Vector4(), new Vector4()
  23012. ];
  23013. // init
  23014. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  23015. var useMorphing = ( i & _MorphingFlag ) !== 0;
  23016. var useSkinning = ( i & _SkinningFlag ) !== 0;
  23017. var depthMaterial = new MeshDepthMaterial( {
  23018. depthPacking: RGBADepthPacking,
  23019. morphTargets: useMorphing,
  23020. skinning: useSkinning
  23021. } );
  23022. _depthMaterials[ i ] = depthMaterial;
  23023. //
  23024. var distanceMaterial = new MeshDistanceMaterial( {
  23025. morphTargets: useMorphing,
  23026. skinning: useSkinning
  23027. } );
  23028. _distanceMaterials[ i ] = distanceMaterial;
  23029. }
  23030. //
  23031. var scope = this;
  23032. this.enabled = false;
  23033. this.autoUpdate = true;
  23034. this.needsUpdate = false;
  23035. this.type = PCFShadowMap;
  23036. this.renderReverseSided = true;
  23037. this.renderSingleSided = true;
  23038. this.render = function ( lights, scene, camera ) {
  23039. if ( scope.enabled === false ) return;
  23040. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  23041. if ( lights.length === 0 ) return;
  23042. // TODO Clean up (needed in case of contextlost)
  23043. var _gl = _renderer.context;
  23044. var _state = _renderer.state;
  23045. // Set GL state for depth map.
  23046. _state.disable( _gl.BLEND );
  23047. _state.buffers.color.setClear( 1, 1, 1, 1 );
  23048. _state.buffers.depth.setTest( true );
  23049. _state.setScissorTest( false );
  23050. // render depth map
  23051. var faceCount;
  23052. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  23053. var light = lights[ i ];
  23054. var shadow = light.shadow;
  23055. var isPointLight = light && light.isPointLight;
  23056. if ( shadow === undefined ) {
  23057. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  23058. continue;
  23059. }
  23060. var shadowCamera = shadow.camera;
  23061. _shadowMapSize.copy( shadow.mapSize );
  23062. _shadowMapSize.min( _maxShadowMapSize );
  23063. if ( isPointLight ) {
  23064. var vpWidth = _shadowMapSize.x;
  23065. var vpHeight = _shadowMapSize.y;
  23066. // These viewports map a cube-map onto a 2D texture with the
  23067. // following orientation:
  23068. //
  23069. // xzXZ
  23070. // y Y
  23071. //
  23072. // X - Positive x direction
  23073. // x - Negative x direction
  23074. // Y - Positive y direction
  23075. // y - Negative y direction
  23076. // Z - Positive z direction
  23077. // z - Negative z direction
  23078. // positive X
  23079. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  23080. // negative X
  23081. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  23082. // positive Z
  23083. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  23084. // negative Z
  23085. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  23086. // positive Y
  23087. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  23088. // negative Y
  23089. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  23090. _shadowMapSize.x *= 4.0;
  23091. _shadowMapSize.y *= 2.0;
  23092. }
  23093. if ( shadow.map === null ) {
  23094. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  23095. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  23096. shadow.map.texture.name = light.name + ".shadowMap";
  23097. shadowCamera.updateProjectionMatrix();
  23098. }
  23099. if ( shadow.isSpotLightShadow ) {
  23100. shadow.update( light );
  23101. }
  23102. var shadowMap = shadow.map;
  23103. var shadowMatrix = shadow.matrix;
  23104. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  23105. shadowCamera.position.copy( _lightPositionWorld );
  23106. if ( isPointLight ) {
  23107. faceCount = 6;
  23108. // for point lights we set the shadow matrix to be a translation-only matrix
  23109. // equal to inverse of the light's position
  23110. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  23111. } else {
  23112. faceCount = 1;
  23113. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  23114. shadowCamera.lookAt( _lookTarget );
  23115. shadowCamera.updateMatrixWorld();
  23116. // compute shadow matrix
  23117. shadowMatrix.set(
  23118. 0.5, 0.0, 0.0, 0.5,
  23119. 0.0, 0.5, 0.0, 0.5,
  23120. 0.0, 0.0, 0.5, 0.5,
  23121. 0.0, 0.0, 0.0, 1.0
  23122. );
  23123. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  23124. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  23125. }
  23126. _renderer.setRenderTarget( shadowMap );
  23127. _renderer.clear();
  23128. // render shadow map for each cube face (if omni-directional) or
  23129. // run a single pass if not
  23130. for ( var face = 0; face < faceCount; face ++ ) {
  23131. if ( isPointLight ) {
  23132. _lookTarget.copy( shadowCamera.position );
  23133. _lookTarget.add( cubeDirections[ face ] );
  23134. shadowCamera.up.copy( cubeUps[ face ] );
  23135. shadowCamera.lookAt( _lookTarget );
  23136. shadowCamera.updateMatrixWorld();
  23137. var vpDimensions = cube2DViewPorts[ face ];
  23138. _state.viewport( vpDimensions );
  23139. }
  23140. // update camera matrices and frustum
  23141. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  23142. _frustum.setFromMatrix( _projScreenMatrix );
  23143. // set object matrices & frustum culling
  23144. renderObject( scene, camera, shadowCamera, isPointLight );
  23145. }
  23146. }
  23147. scope.needsUpdate = false;
  23148. };
  23149. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  23150. var geometry = object.geometry;
  23151. var result = null;
  23152. var materialVariants = _depthMaterials;
  23153. var customMaterial = object.customDepthMaterial;
  23154. if ( isPointLight ) {
  23155. materialVariants = _distanceMaterials;
  23156. customMaterial = object.customDistanceMaterial;
  23157. }
  23158. if ( ! customMaterial ) {
  23159. var useMorphing = false;
  23160. if ( material.morphTargets ) {
  23161. if ( geometry && geometry.isBufferGeometry ) {
  23162. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  23163. } else if ( geometry && geometry.isGeometry ) {
  23164. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  23165. }
  23166. }
  23167. if ( object.isSkinnedMesh && material.skinning === false ) {
  23168. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  23169. }
  23170. var useSkinning = object.isSkinnedMesh && material.skinning;
  23171. var variantIndex = 0;
  23172. if ( useMorphing ) variantIndex |= _MorphingFlag;
  23173. if ( useSkinning ) variantIndex |= _SkinningFlag;
  23174. result = materialVariants[ variantIndex ];
  23175. } else {
  23176. result = customMaterial;
  23177. }
  23178. if ( _renderer.localClippingEnabled &&
  23179. material.clipShadows === true &&
  23180. material.clippingPlanes.length !== 0 ) {
  23181. // in this case we need a unique material instance reflecting the
  23182. // appropriate state
  23183. var keyA = result.uuid, keyB = material.uuid;
  23184. var materialsForVariant = _materialCache[ keyA ];
  23185. if ( materialsForVariant === undefined ) {
  23186. materialsForVariant = {};
  23187. _materialCache[ keyA ] = materialsForVariant;
  23188. }
  23189. var cachedMaterial = materialsForVariant[ keyB ];
  23190. if ( cachedMaterial === undefined ) {
  23191. cachedMaterial = result.clone();
  23192. materialsForVariant[ keyB ] = cachedMaterial;
  23193. }
  23194. result = cachedMaterial;
  23195. }
  23196. result.visible = material.visible;
  23197. result.wireframe = material.wireframe;
  23198. var side = material.side;
  23199. if ( scope.renderSingleSided && side == DoubleSide ) {
  23200. side = FrontSide;
  23201. }
  23202. if ( scope.renderReverseSided ) {
  23203. if ( side === FrontSide ) side = BackSide;
  23204. else if ( side === BackSide ) side = FrontSide;
  23205. }
  23206. result.side = side;
  23207. result.clipShadows = material.clipShadows;
  23208. result.clippingPlanes = material.clippingPlanes;
  23209. result.clipIntersection = material.clipIntersection;
  23210. result.wireframeLinewidth = material.wireframeLinewidth;
  23211. result.linewidth = material.linewidth;
  23212. if ( isPointLight && result.isMeshDistanceMaterial ) {
  23213. result.referencePosition.copy( lightPositionWorld );
  23214. result.nearDistance = shadowCameraNear;
  23215. result.farDistance = shadowCameraFar;
  23216. }
  23217. return result;
  23218. }
  23219. function renderObject( object, camera, shadowCamera, isPointLight ) {
  23220. if ( object.visible === false ) return;
  23221. var visible = object.layers.test( camera.layers );
  23222. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  23223. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  23224. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  23225. var geometry = _objects.update( object );
  23226. var material = object.material;
  23227. if ( Array.isArray( material ) ) {
  23228. var groups = geometry.groups;
  23229. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  23230. var group = groups[ k ];
  23231. var groupMaterial = material[ group.materialIndex ];
  23232. if ( groupMaterial && groupMaterial.visible ) {
  23233. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  23234. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  23235. }
  23236. }
  23237. } else if ( material.visible ) {
  23238. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  23239. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  23240. }
  23241. }
  23242. }
  23243. var children = object.children;
  23244. for ( var i = 0, l = children.length; i < l; i ++ ) {
  23245. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  23246. }
  23247. }
  23248. }
  23249. /**
  23250. * @author mrdoob / http://mrdoob.com/
  23251. */
  23252. function WebGLAttributes( gl ) {
  23253. var buffers = {};
  23254. function createBuffer( attribute, bufferType ) {
  23255. var array = attribute.array;
  23256. var usage = attribute.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  23257. var buffer = gl.createBuffer();
  23258. gl.bindBuffer( bufferType, buffer );
  23259. gl.bufferData( bufferType, array, usage );
  23260. attribute.onUploadCallback();
  23261. var type = gl.FLOAT;
  23262. if ( array instanceof Float32Array ) {
  23263. type = gl.FLOAT;
  23264. } else if ( array instanceof Float64Array ) {
  23265. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  23266. } else if ( array instanceof Uint16Array ) {
  23267. type = gl.UNSIGNED_SHORT;
  23268. } else if ( array instanceof Int16Array ) {
  23269. type = gl.SHORT;
  23270. } else if ( array instanceof Uint32Array ) {
  23271. type = gl.UNSIGNED_INT;
  23272. } else if ( array instanceof Int32Array ) {
  23273. type = gl.INT;
  23274. } else if ( array instanceof Int8Array ) {
  23275. type = gl.BYTE;
  23276. } else if ( array instanceof Uint8Array ) {
  23277. type = gl.UNSIGNED_BYTE;
  23278. }
  23279. return {
  23280. buffer: buffer,
  23281. type: type,
  23282. bytesPerElement: array.BYTES_PER_ELEMENT,
  23283. version: attribute.version
  23284. };
  23285. }
  23286. function updateBuffer( buffer, attribute, bufferType ) {
  23287. var array = attribute.array;
  23288. var updateRange = attribute.updateRange;
  23289. gl.bindBuffer( bufferType, buffer );
  23290. if ( attribute.dynamic === false ) {
  23291. gl.bufferData( bufferType, array, gl.STATIC_DRAW );
  23292. } else if ( updateRange.count === - 1 ) {
  23293. // Not using update ranges
  23294. gl.bufferSubData( bufferType, 0, array );
  23295. } else if ( updateRange.count === 0 ) {
  23296. 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.' );
  23297. } else {
  23298. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  23299. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  23300. updateRange.count = - 1; // reset range
  23301. }
  23302. }
  23303. //
  23304. function get( attribute ) {
  23305. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  23306. return buffers[ attribute.uuid ];
  23307. }
  23308. function remove( attribute ) {
  23309. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  23310. var data = buffers[ attribute.uuid ];
  23311. if ( data ) {
  23312. gl.deleteBuffer( data.buffer );
  23313. delete buffers[ attribute.uuid ];
  23314. }
  23315. }
  23316. function update( attribute, bufferType ) {
  23317. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  23318. var data = buffers[ attribute.uuid ];
  23319. if ( data === undefined ) {
  23320. buffers[ attribute.uuid ] = createBuffer( attribute, bufferType );
  23321. } else if ( data.version < attribute.version ) {
  23322. updateBuffer( data.buffer, attribute, bufferType );
  23323. data.version = attribute.version;
  23324. }
  23325. }
  23326. return {
  23327. get: get,
  23328. remove: remove,
  23329. update: update
  23330. };
  23331. }
  23332. /**
  23333. * @author mrdoob / http://mrdoob.com/
  23334. * @author Mugen87 / https://github.com/Mugen87
  23335. */
  23336. // PlaneGeometry
  23337. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  23338. Geometry.call( this );
  23339. this.type = 'PlaneGeometry';
  23340. this.parameters = {
  23341. width: width,
  23342. height: height,
  23343. widthSegments: widthSegments,
  23344. heightSegments: heightSegments
  23345. };
  23346. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  23347. this.mergeVertices();
  23348. }
  23349. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  23350. PlaneGeometry.prototype.constructor = PlaneGeometry;
  23351. // PlaneBufferGeometry
  23352. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  23353. BufferGeometry.call( this );
  23354. this.type = 'PlaneBufferGeometry';
  23355. this.parameters = {
  23356. width: width,
  23357. height: height,
  23358. widthSegments: widthSegments,
  23359. heightSegments: heightSegments
  23360. };
  23361. width = width || 1;
  23362. height = height || 1;
  23363. var width_half = width / 2;
  23364. var height_half = height / 2;
  23365. var gridX = Math.floor( widthSegments ) || 1;
  23366. var gridY = Math.floor( heightSegments ) || 1;
  23367. var gridX1 = gridX + 1;
  23368. var gridY1 = gridY + 1;
  23369. var segment_width = width / gridX;
  23370. var segment_height = height / gridY;
  23371. var ix, iy;
  23372. // buffers
  23373. var indices = [];
  23374. var vertices = [];
  23375. var normals = [];
  23376. var uvs = [];
  23377. // generate vertices, normals and uvs
  23378. for ( iy = 0; iy < gridY1; iy ++ ) {
  23379. var y = iy * segment_height - height_half;
  23380. for ( ix = 0; ix < gridX1; ix ++ ) {
  23381. var x = ix * segment_width - width_half;
  23382. vertices.push( x, - y, 0 );
  23383. normals.push( 0, 0, 1 );
  23384. uvs.push( ix / gridX );
  23385. uvs.push( 1 - ( iy / gridY ) );
  23386. }
  23387. }
  23388. // indices
  23389. for ( iy = 0; iy < gridY; iy ++ ) {
  23390. for ( ix = 0; ix < gridX; ix ++ ) {
  23391. var a = ix + gridX1 * iy;
  23392. var b = ix + gridX1 * ( iy + 1 );
  23393. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  23394. var d = ( ix + 1 ) + gridX1 * iy;
  23395. // faces
  23396. indices.push( a, b, d );
  23397. indices.push( b, c, d );
  23398. }
  23399. }
  23400. // build geometry
  23401. this.setIndex( indices );
  23402. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  23403. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  23404. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  23405. }
  23406. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  23407. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  23408. /**
  23409. * @author mrdoob / http://mrdoob.com/
  23410. */
  23411. function WebGLBackground( renderer, state, geometries, premultipliedAlpha ) {
  23412. var clearColor = new Color( 0x000000 );
  23413. var clearAlpha = 0;
  23414. var planeCamera, planeMesh;
  23415. var boxMesh;
  23416. function render( renderList, scene, camera, forceClear ) {
  23417. var background = scene.background;
  23418. if ( background === null ) {
  23419. setClear( clearColor, clearAlpha );
  23420. } else if ( background && background.isColor ) {
  23421. setClear( background, 1 );
  23422. forceClear = true;
  23423. }
  23424. if ( renderer.autoClear || forceClear ) {
  23425. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  23426. }
  23427. if ( background && background.isCubeTexture ) {
  23428. if ( boxMesh === undefined ) {
  23429. boxMesh = new Mesh(
  23430. new BoxBufferGeometry( 1, 1, 1 ),
  23431. new ShaderMaterial( {
  23432. uniforms: ShaderLib.cube.uniforms,
  23433. vertexShader: ShaderLib.cube.vertexShader,
  23434. fragmentShader: ShaderLib.cube.fragmentShader,
  23435. side: BackSide,
  23436. depthTest: true,
  23437. depthWrite: false,
  23438. fog: false
  23439. } )
  23440. );
  23441. boxMesh.geometry.removeAttribute( 'normal' );
  23442. boxMesh.geometry.removeAttribute( 'uv' );
  23443. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  23444. this.matrixWorld.copyPosition( camera.matrixWorld );
  23445. };
  23446. geometries.update( boxMesh.geometry );
  23447. }
  23448. boxMesh.material.uniforms.tCube.value = background;
  23449. renderList.push( boxMesh, boxMesh.geometry, boxMesh.material, 0, null );
  23450. } else if ( background && background.isTexture ) {
  23451. if ( planeCamera === undefined ) {
  23452. planeCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  23453. planeMesh = new Mesh(
  23454. new PlaneBufferGeometry( 2, 2 ),
  23455. new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
  23456. );
  23457. geometries.update( planeMesh.geometry );
  23458. }
  23459. planeMesh.material.map = background;
  23460. // TODO Push this to renderList
  23461. renderer.renderBufferDirect( planeCamera, null, planeMesh.geometry, planeMesh.material, planeMesh, null );
  23462. }
  23463. }
  23464. function setClear( color, alpha ) {
  23465. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  23466. }
  23467. return {
  23468. getClearColor: function () {
  23469. return clearColor;
  23470. },
  23471. setClearColor: function ( color, alpha ) {
  23472. clearColor.set( color );
  23473. clearAlpha = alpha !== undefined ? alpha : 1;
  23474. setClear( clearColor, clearAlpha );
  23475. },
  23476. getClearAlpha: function () {
  23477. return clearAlpha;
  23478. },
  23479. setClearAlpha: function ( alpha ) {
  23480. clearAlpha = alpha;
  23481. setClear( clearColor, clearAlpha );
  23482. },
  23483. render: render
  23484. };
  23485. }
  23486. /**
  23487. * @author mrdoob / http://mrdoob.com/
  23488. */
  23489. function painterSortStable( a, b ) {
  23490. if ( a.renderOrder !== b.renderOrder ) {
  23491. return a.renderOrder - b.renderOrder;
  23492. } else if ( a.program && b.program && a.program !== b.program ) {
  23493. return a.program.id - b.program.id;
  23494. } else if ( a.material.id !== b.material.id ) {
  23495. return a.material.id - b.material.id;
  23496. } else if ( a.z !== b.z ) {
  23497. return a.z - b.z;
  23498. } else {
  23499. return a.id - b.id;
  23500. }
  23501. }
  23502. function reversePainterSortStable( a, b ) {
  23503. if ( a.renderOrder !== b.renderOrder ) {
  23504. return a.renderOrder - b.renderOrder;
  23505. } if ( a.z !== b.z ) {
  23506. return b.z - a.z;
  23507. } else {
  23508. return a.id - b.id;
  23509. }
  23510. }
  23511. function WebGLRenderList() {
  23512. var renderItems = [];
  23513. var renderItemsIndex = 0;
  23514. var opaque = [];
  23515. var transparent = [];
  23516. function init() {
  23517. renderItemsIndex = 0;
  23518. opaque.length = 0;
  23519. transparent.length = 0;
  23520. }
  23521. function push( object, geometry, material, z, group ) {
  23522. var renderItem = renderItems[ renderItemsIndex ];
  23523. if ( renderItem === undefined ) {
  23524. renderItem = {
  23525. id: object.id,
  23526. object: object,
  23527. geometry: geometry,
  23528. material: material,
  23529. program: material.program,
  23530. renderOrder: object.renderOrder,
  23531. z: z,
  23532. group: group
  23533. };
  23534. renderItems[ renderItemsIndex ] = renderItem;
  23535. } else {
  23536. renderItem.id = object.id;
  23537. renderItem.object = object;
  23538. renderItem.geometry = geometry;
  23539. renderItem.material = material;
  23540. renderItem.program = material.program;
  23541. renderItem.renderOrder = object.renderOrder;
  23542. renderItem.z = z;
  23543. renderItem.group = group;
  23544. }
  23545. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  23546. renderItemsIndex ++;
  23547. }
  23548. function sort() {
  23549. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  23550. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  23551. }
  23552. return {
  23553. opaque: opaque,
  23554. transparent: transparent,
  23555. init: init,
  23556. push: push,
  23557. sort: sort
  23558. };
  23559. }
  23560. function WebGLRenderLists() {
  23561. var lists = {};
  23562. function get( scene, camera ) {
  23563. var hash = scene.id + ',' + camera.id;
  23564. var list = lists[ hash ];
  23565. if ( list === undefined ) {
  23566. // console.log( 'THREE.WebGLRenderLists:', hash );
  23567. list = new WebGLRenderList();
  23568. lists[ hash ] = list;
  23569. }
  23570. return list;
  23571. }
  23572. function dispose() {
  23573. lists = {};
  23574. }
  23575. return {
  23576. get: get,
  23577. dispose: dispose
  23578. };
  23579. }
  23580. /**
  23581. * @author mrdoob / http://mrdoob.com/
  23582. */
  23583. function absNumericalSort( a, b ) {
  23584. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  23585. }
  23586. function WebGLMorphtargets( gl ) {
  23587. var influencesList = {};
  23588. var morphInfluences = new Float32Array( 8 );
  23589. function update( object, geometry, material, program ) {
  23590. var objectInfluences = object.morphTargetInfluences;
  23591. var length = objectInfluences.length;
  23592. var influences = influencesList[ geometry.id ];
  23593. if ( influences === undefined ) {
  23594. // initialise list
  23595. influences = [];
  23596. for ( var i = 0; i < length; i ++ ) {
  23597. influences[ i ] = [ i, 0 ];
  23598. }
  23599. influencesList[ geometry.id ] = influences;
  23600. }
  23601. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  23602. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  23603. // Remove current morphAttributes
  23604. for ( var i = 0; i < length; i ++ ) {
  23605. var influence = influences[ i ];
  23606. if ( influence[ 1 ] !== 0 ) {
  23607. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  23608. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  23609. }
  23610. }
  23611. // Collect influences
  23612. for ( var i = 0; i < length; i ++ ) {
  23613. var influence = influences[ i ];
  23614. influence[ 0 ] = i;
  23615. influence[ 1 ] = objectInfluences[ i ];
  23616. }
  23617. influences.sort( absNumericalSort );
  23618. // Add morphAttributes
  23619. for ( var i = 0; i < 8; i ++ ) {
  23620. var influence = influences[ i ];
  23621. if ( influence ) {
  23622. var index = influence[ 0 ];
  23623. var value = influence[ 1 ];
  23624. if ( value ) {
  23625. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  23626. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  23627. morphInfluences[ i ] = value;
  23628. continue;
  23629. }
  23630. }
  23631. morphInfluences[ i ] = 0;
  23632. }
  23633. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  23634. }
  23635. return {
  23636. update: update
  23637. };
  23638. }
  23639. /**
  23640. * @author mrdoob / http://mrdoob.com/
  23641. */
  23642. function WebGLIndexedBufferRenderer( gl, extensions, infoRender ) {
  23643. var mode;
  23644. function setMode( value ) {
  23645. mode = value;
  23646. }
  23647. var type, bytesPerElement;
  23648. function setIndex( value ) {
  23649. type = value.type;
  23650. bytesPerElement = value.bytesPerElement;
  23651. }
  23652. function render( start, count ) {
  23653. gl.drawElements( mode, count, type, start * bytesPerElement );
  23654. infoRender.calls ++;
  23655. infoRender.vertices += count;
  23656. if ( mode === gl.TRIANGLES ) infoRender.faces += count / 3;
  23657. else if ( mode === gl.POINTS ) infoRender.points += count;
  23658. }
  23659. function renderInstances( geometry, start, count ) {
  23660. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  23661. if ( extension === null ) {
  23662. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  23663. return;
  23664. }
  23665. extension.drawElementsInstancedANGLE( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  23666. infoRender.calls ++;
  23667. infoRender.vertices += count * geometry.maxInstancedCount;
  23668. if ( mode === gl.TRIANGLES ) infoRender.faces += geometry.maxInstancedCount * count / 3;
  23669. else if ( mode === gl.POINTS ) infoRender.points += geometry.maxInstancedCount * count;
  23670. }
  23671. //
  23672. this.setMode = setMode;
  23673. this.setIndex = setIndex;
  23674. this.render = render;
  23675. this.renderInstances = renderInstances;
  23676. }
  23677. /**
  23678. * @author mrdoob / http://mrdoob.com/
  23679. */
  23680. function WebGLBufferRenderer( gl, extensions, infoRender ) {
  23681. var mode;
  23682. function setMode( value ) {
  23683. mode = value;
  23684. }
  23685. function render( start, count ) {
  23686. gl.drawArrays( mode, start, count );
  23687. infoRender.calls ++;
  23688. infoRender.vertices += count;
  23689. if ( mode === gl.TRIANGLES ) infoRender.faces += count / 3;
  23690. else if ( mode === gl.POINTS ) infoRender.points += count;
  23691. }
  23692. function renderInstances( geometry, start, count ) {
  23693. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  23694. if ( extension === null ) {
  23695. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  23696. return;
  23697. }
  23698. var position = geometry.attributes.position;
  23699. if ( position.isInterleavedBufferAttribute ) {
  23700. count = position.data.count;
  23701. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  23702. } else {
  23703. extension.drawArraysInstancedANGLE( mode, start, count, geometry.maxInstancedCount );
  23704. }
  23705. infoRender.calls ++;
  23706. infoRender.vertices += count * geometry.maxInstancedCount;
  23707. if ( mode === gl.TRIANGLES ) infoRender.faces += geometry.maxInstancedCount * count / 3;
  23708. else if ( mode === gl.POINTS ) infoRender.points += geometry.maxInstancedCount * count;
  23709. }
  23710. //
  23711. this.setMode = setMode;
  23712. this.render = render;
  23713. this.renderInstances = renderInstances;
  23714. }
  23715. /**
  23716. * @author mrdoob / http://mrdoob.com/
  23717. */
  23718. function WebGLGeometries( gl, attributes, infoMemory ) {
  23719. var geometries = {};
  23720. var wireframeAttributes = {};
  23721. function onGeometryDispose( event ) {
  23722. var geometry = event.target;
  23723. var buffergeometry = geometries[ geometry.id ];
  23724. if ( buffergeometry.index !== null ) {
  23725. attributes.remove( buffergeometry.index );
  23726. }
  23727. for ( var name in buffergeometry.attributes ) {
  23728. attributes.remove( buffergeometry.attributes[ name ] );
  23729. }
  23730. geometry.removeEventListener( 'dispose', onGeometryDispose );
  23731. delete geometries[ geometry.id ];
  23732. // TODO Remove duplicate code
  23733. var attribute = wireframeAttributes[ geometry.id ];
  23734. if ( attribute ) {
  23735. attributes.remove( attribute );
  23736. delete wireframeAttributes[ geometry.id ];
  23737. }
  23738. attribute = wireframeAttributes[ buffergeometry.id ];
  23739. if ( attribute ) {
  23740. attributes.remove( attribute );
  23741. delete wireframeAttributes[ buffergeometry.id ];
  23742. }
  23743. //
  23744. infoMemory.geometries --;
  23745. }
  23746. function get( object, geometry ) {
  23747. var buffergeometry = geometries[ geometry.id ];
  23748. if ( buffergeometry ) return buffergeometry;
  23749. geometry.addEventListener( 'dispose', onGeometryDispose );
  23750. if ( geometry.isBufferGeometry ) {
  23751. buffergeometry = geometry;
  23752. } else if ( geometry.isGeometry ) {
  23753. if ( geometry._bufferGeometry === undefined ) {
  23754. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  23755. }
  23756. buffergeometry = geometry._bufferGeometry;
  23757. }
  23758. geometries[ geometry.id ] = buffergeometry;
  23759. infoMemory.geometries ++;
  23760. return buffergeometry;
  23761. }
  23762. function update( geometry ) {
  23763. var index = geometry.index;
  23764. var geometryAttributes = geometry.attributes;
  23765. if ( index !== null ) {
  23766. attributes.update( index, gl.ELEMENT_ARRAY_BUFFER );
  23767. }
  23768. for ( var name in geometryAttributes ) {
  23769. attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );
  23770. }
  23771. // morph targets
  23772. var morphAttributes = geometry.morphAttributes;
  23773. for ( var name in morphAttributes ) {
  23774. var array = morphAttributes[ name ];
  23775. for ( var i = 0, l = array.length; i < l; i ++ ) {
  23776. attributes.update( array[ i ], gl.ARRAY_BUFFER );
  23777. }
  23778. }
  23779. }
  23780. function getWireframeAttribute( geometry ) {
  23781. var attribute = wireframeAttributes[ geometry.id ];
  23782. if ( attribute ) return attribute;
  23783. var indices = [];
  23784. var geometryIndex = geometry.index;
  23785. var geometryAttributes = geometry.attributes;
  23786. // console.time( 'wireframe' );
  23787. if ( geometryIndex !== null ) {
  23788. var array = geometryIndex.array;
  23789. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  23790. var a = array[ i + 0 ];
  23791. var b = array[ i + 1 ];
  23792. var c = array[ i + 2 ];
  23793. indices.push( a, b, b, c, c, a );
  23794. }
  23795. } else {
  23796. var array = geometryAttributes.position.array;
  23797. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  23798. var a = i + 0;
  23799. var b = i + 1;
  23800. var c = i + 2;
  23801. indices.push( a, b, b, c, c, a );
  23802. }
  23803. }
  23804. // console.timeEnd( 'wireframe' );
  23805. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  23806. attributes.update( attribute, gl.ELEMENT_ARRAY_BUFFER );
  23807. wireframeAttributes[ geometry.id ] = attribute;
  23808. return attribute;
  23809. }
  23810. return {
  23811. get: get,
  23812. update: update,
  23813. getWireframeAttribute: getWireframeAttribute
  23814. };
  23815. }
  23816. /**
  23817. * @author mrdoob / http://mrdoob.com/
  23818. */
  23819. function UniformsCache() {
  23820. var lights = {};
  23821. return {
  23822. get: function ( light ) {
  23823. if ( lights[ light.id ] !== undefined ) {
  23824. return lights[ light.id ];
  23825. }
  23826. var uniforms;
  23827. switch ( light.type ) {
  23828. case 'DirectionalLight':
  23829. uniforms = {
  23830. direction: new Vector3(),
  23831. color: new Color(),
  23832. shadow: false,
  23833. shadowBias: 0,
  23834. shadowRadius: 1,
  23835. shadowMapSize: new Vector2()
  23836. };
  23837. break;
  23838. case 'SpotLight':
  23839. uniforms = {
  23840. position: new Vector3(),
  23841. direction: new Vector3(),
  23842. color: new Color(),
  23843. distance: 0,
  23844. coneCos: 0,
  23845. penumbraCos: 0,
  23846. decay: 0,
  23847. shadow: false,
  23848. shadowBias: 0,
  23849. shadowRadius: 1,
  23850. shadowMapSize: new Vector2()
  23851. };
  23852. break;
  23853. case 'PointLight':
  23854. uniforms = {
  23855. position: new Vector3(),
  23856. color: new Color(),
  23857. distance: 0,
  23858. decay: 0,
  23859. shadow: false,
  23860. shadowBias: 0,
  23861. shadowRadius: 1,
  23862. shadowMapSize: new Vector2(),
  23863. shadowCameraNear: 1,
  23864. shadowCameraFar: 1000
  23865. };
  23866. break;
  23867. case 'HemisphereLight':
  23868. uniforms = {
  23869. direction: new Vector3(),
  23870. skyColor: new Color(),
  23871. groundColor: new Color()
  23872. };
  23873. break;
  23874. case 'RectAreaLight':
  23875. uniforms = {
  23876. color: new Color(),
  23877. position: new Vector3(),
  23878. halfWidth: new Vector3(),
  23879. halfHeight: new Vector3()
  23880. // TODO (abelnation): set RectAreaLight shadow uniforms
  23881. };
  23882. break;
  23883. }
  23884. lights[ light.id ] = uniforms;
  23885. return uniforms;
  23886. }
  23887. };
  23888. }
  23889. function WebGLLights() {
  23890. var cache = new UniformsCache();
  23891. var state = {
  23892. hash: '',
  23893. ambient: [ 0, 0, 0 ],
  23894. directional: [],
  23895. directionalShadowMap: [],
  23896. directionalShadowMatrix: [],
  23897. spot: [],
  23898. spotShadowMap: [],
  23899. spotShadowMatrix: [],
  23900. rectArea: [],
  23901. point: [],
  23902. pointShadowMap: [],
  23903. pointShadowMatrix: [],
  23904. hemi: []
  23905. };
  23906. var vector3 = new Vector3();
  23907. var matrix4 = new Matrix4();
  23908. var matrix42 = new Matrix4();
  23909. function setup( lights, shadows, camera ) {
  23910. var r = 0, g = 0, b = 0;
  23911. var directionalLength = 0;
  23912. var pointLength = 0;
  23913. var spotLength = 0;
  23914. var rectAreaLength = 0;
  23915. var hemiLength = 0;
  23916. var viewMatrix = camera.matrixWorldInverse;
  23917. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  23918. var light = lights[ i ];
  23919. var color = light.color;
  23920. var intensity = light.intensity;
  23921. var distance = light.distance;
  23922. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  23923. if ( light.isAmbientLight ) {
  23924. r += color.r * intensity;
  23925. g += color.g * intensity;
  23926. b += color.b * intensity;
  23927. } else if ( light.isDirectionalLight ) {
  23928. var uniforms = cache.get( light );
  23929. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  23930. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  23931. vector3.setFromMatrixPosition( light.target.matrixWorld );
  23932. uniforms.direction.sub( vector3 );
  23933. uniforms.direction.transformDirection( viewMatrix );
  23934. uniforms.shadow = light.castShadow;
  23935. if ( light.castShadow ) {
  23936. var shadow = light.shadow;
  23937. uniforms.shadowBias = shadow.bias;
  23938. uniforms.shadowRadius = shadow.radius;
  23939. uniforms.shadowMapSize = shadow.mapSize;
  23940. }
  23941. state.directionalShadowMap[ directionalLength ] = shadowMap;
  23942. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  23943. state.directional[ directionalLength ] = uniforms;
  23944. directionalLength ++;
  23945. } else if ( light.isSpotLight ) {
  23946. var uniforms = cache.get( light );
  23947. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  23948. uniforms.position.applyMatrix4( viewMatrix );
  23949. uniforms.color.copy( color ).multiplyScalar( intensity );
  23950. uniforms.distance = distance;
  23951. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  23952. vector3.setFromMatrixPosition( light.target.matrixWorld );
  23953. uniforms.direction.sub( vector3 );
  23954. uniforms.direction.transformDirection( viewMatrix );
  23955. uniforms.coneCos = Math.cos( light.angle );
  23956. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  23957. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  23958. uniforms.shadow = light.castShadow;
  23959. if ( light.castShadow ) {
  23960. var shadow = light.shadow;
  23961. uniforms.shadowBias = shadow.bias;
  23962. uniforms.shadowRadius = shadow.radius;
  23963. uniforms.shadowMapSize = shadow.mapSize;
  23964. }
  23965. state.spotShadowMap[ spotLength ] = shadowMap;
  23966. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  23967. state.spot[ spotLength ] = uniforms;
  23968. spotLength ++;
  23969. } else if ( light.isRectAreaLight ) {
  23970. var uniforms = cache.get( light );
  23971. // (a) intensity controls irradiance of entire light
  23972. uniforms.color
  23973. .copy( color )
  23974. .multiplyScalar( intensity / ( light.width * light.height ) );
  23975. // (b) intensity controls the radiance per light area
  23976. // uniforms.color.copy( color ).multiplyScalar( intensity );
  23977. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  23978. uniforms.position.applyMatrix4( viewMatrix );
  23979. // extract local rotation of light to derive width/height half vectors
  23980. matrix42.identity();
  23981. matrix4.copy( light.matrixWorld );
  23982. matrix4.premultiply( viewMatrix );
  23983. matrix42.extractRotation( matrix4 );
  23984. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  23985. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  23986. uniforms.halfWidth.applyMatrix4( matrix42 );
  23987. uniforms.halfHeight.applyMatrix4( matrix42 );
  23988. // TODO (abelnation): RectAreaLight distance?
  23989. // uniforms.distance = distance;
  23990. state.rectArea[ rectAreaLength ] = uniforms;
  23991. rectAreaLength ++;
  23992. } else if ( light.isPointLight ) {
  23993. var uniforms = cache.get( light );
  23994. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  23995. uniforms.position.applyMatrix4( viewMatrix );
  23996. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  23997. uniforms.distance = light.distance;
  23998. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  23999. uniforms.shadow = light.castShadow;
  24000. if ( light.castShadow ) {
  24001. var shadow = light.shadow;
  24002. uniforms.shadowBias = shadow.bias;
  24003. uniforms.shadowRadius = shadow.radius;
  24004. uniforms.shadowMapSize = shadow.mapSize;
  24005. uniforms.shadowCameraNear = shadow.camera.near;
  24006. uniforms.shadowCameraFar = shadow.camera.far;
  24007. }
  24008. state.pointShadowMap[ pointLength ] = shadowMap;
  24009. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  24010. state.point[ pointLength ] = uniforms;
  24011. pointLength ++;
  24012. } else if ( light.isHemisphereLight ) {
  24013. var uniforms = cache.get( light );
  24014. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  24015. uniforms.direction.transformDirection( viewMatrix );
  24016. uniforms.direction.normalize();
  24017. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  24018. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  24019. state.hemi[ hemiLength ] = uniforms;
  24020. hemiLength ++;
  24021. }
  24022. }
  24023. state.ambient[ 0 ] = r;
  24024. state.ambient[ 1 ] = g;
  24025. state.ambient[ 2 ] = b;
  24026. state.directional.length = directionalLength;
  24027. state.spot.length = spotLength;
  24028. state.rectArea.length = rectAreaLength;
  24029. state.point.length = pointLength;
  24030. state.hemi.length = hemiLength;
  24031. // TODO (sam-g-steel) why aren't we using join
  24032. state.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + rectAreaLength + ',' + hemiLength + ',' + shadows.length;
  24033. }
  24034. return {
  24035. setup: setup,
  24036. state: state
  24037. };
  24038. }
  24039. /**
  24040. * @author mrdoob / http://mrdoob.com/
  24041. */
  24042. function WebGLObjects( geometries, infoRender ) {
  24043. var updateList = {};
  24044. function update( object ) {
  24045. var frame = infoRender.frame;
  24046. var geometry = object.geometry;
  24047. var buffergeometry = geometries.get( object, geometry );
  24048. // Update once per frame
  24049. if ( updateList[ buffergeometry.id ] !== frame ) {
  24050. if ( geometry.isGeometry ) {
  24051. buffergeometry.updateFromObject( object );
  24052. }
  24053. geometries.update( buffergeometry );
  24054. updateList[ buffergeometry.id ] = frame;
  24055. }
  24056. return buffergeometry;
  24057. }
  24058. function clear() {
  24059. updateList = {};
  24060. }
  24061. return {
  24062. update: update,
  24063. clear: clear
  24064. };
  24065. }
  24066. /**
  24067. * @author mrdoob / http://mrdoob.com/
  24068. */
  24069. function addLineNumbers( string ) {
  24070. var lines = string.split( '\n' );
  24071. for ( var i = 0; i < lines.length; i ++ ) {
  24072. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  24073. }
  24074. return lines.join( '\n' );
  24075. }
  24076. function WebGLShader( gl, type, string ) {
  24077. var shader = gl.createShader( type );
  24078. gl.shaderSource( shader, string );
  24079. gl.compileShader( shader );
  24080. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  24081. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  24082. }
  24083. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  24084. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  24085. }
  24086. // --enable-privileged-webgl-extension
  24087. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  24088. return shader;
  24089. }
  24090. /**
  24091. * @author mrdoob / http://mrdoob.com/
  24092. */
  24093. var programIdCount = 0;
  24094. function getEncodingComponents( encoding ) {
  24095. switch ( encoding ) {
  24096. case LinearEncoding:
  24097. return [ 'Linear', '( value )' ];
  24098. case sRGBEncoding:
  24099. return [ 'sRGB', '( value )' ];
  24100. case RGBEEncoding:
  24101. return [ 'RGBE', '( value )' ];
  24102. case RGBM7Encoding:
  24103. return [ 'RGBM', '( value, 7.0 )' ];
  24104. case RGBM16Encoding:
  24105. return [ 'RGBM', '( value, 16.0 )' ];
  24106. case RGBDEncoding:
  24107. return [ 'RGBD', '( value, 256.0 )' ];
  24108. case GammaEncoding:
  24109. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  24110. default:
  24111. throw new Error( 'unsupported encoding: ' + encoding );
  24112. }
  24113. }
  24114. function getTexelDecodingFunction( functionName, encoding ) {
  24115. var components = getEncodingComponents( encoding );
  24116. return "vec4 " + functionName + "( vec4 value ) { return " + components[ 0 ] + "ToLinear" + components[ 1 ] + "; }";
  24117. }
  24118. function getTexelEncodingFunction( functionName, encoding ) {
  24119. var components = getEncodingComponents( encoding );
  24120. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[ 0 ] + components[ 1 ] + "; }";
  24121. }
  24122. function getToneMappingFunction( functionName, toneMapping ) {
  24123. var toneMappingName;
  24124. switch ( toneMapping ) {
  24125. case LinearToneMapping:
  24126. toneMappingName = "Linear";
  24127. break;
  24128. case ReinhardToneMapping:
  24129. toneMappingName = "Reinhard";
  24130. break;
  24131. case Uncharted2ToneMapping:
  24132. toneMappingName = "Uncharted2";
  24133. break;
  24134. case CineonToneMapping:
  24135. toneMappingName = "OptimizedCineon";
  24136. break;
  24137. default:
  24138. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  24139. }
  24140. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  24141. }
  24142. function generateExtensions( extensions, parameters, rendererExtensions ) {
  24143. extensions = extensions || {};
  24144. var chunks = [
  24145. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  24146. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  24147. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  24148. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  24149. ];
  24150. return chunks.filter( filterEmptyLine ).join( '\n' );
  24151. }
  24152. function generateDefines( defines ) {
  24153. var chunks = [];
  24154. for ( var name in defines ) {
  24155. var value = defines[ name ];
  24156. if ( value === false ) continue;
  24157. chunks.push( '#define ' + name + ' ' + value );
  24158. }
  24159. return chunks.join( '\n' );
  24160. }
  24161. function fetchAttributeLocations( gl, program ) {
  24162. var attributes = {};
  24163. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  24164. for ( var i = 0; i < n; i ++ ) {
  24165. var info = gl.getActiveAttrib( program, i );
  24166. var name = info.name;
  24167. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  24168. attributes[ name ] = gl.getAttribLocation( program, name );
  24169. }
  24170. return attributes;
  24171. }
  24172. function filterEmptyLine( string ) {
  24173. return string !== '';
  24174. }
  24175. function replaceLightNums( string, parameters ) {
  24176. return string
  24177. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  24178. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  24179. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  24180. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  24181. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  24182. }
  24183. function parseIncludes( string ) {
  24184. var pattern = /^[ \t]*#include +<([\w\d.]+)>/gm;
  24185. function replace( match, include ) {
  24186. var replace = ShaderChunk[ include ];
  24187. if ( replace === undefined ) {
  24188. throw new Error( 'Can not resolve #include <' + include + '>' );
  24189. }
  24190. return parseIncludes( replace );
  24191. }
  24192. return string.replace( pattern, replace );
  24193. }
  24194. function unrollLoops( string ) {
  24195. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  24196. function replace( match, start, end, snippet ) {
  24197. var unroll = '';
  24198. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  24199. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  24200. }
  24201. return unroll;
  24202. }
  24203. return string.replace( pattern, replace );
  24204. }
  24205. function WebGLProgram( renderer, extensions, code, material, shader, parameters ) {
  24206. var gl = renderer.context;
  24207. var defines = material.defines;
  24208. var vertexShader = shader.vertexShader;
  24209. var fragmentShader = shader.fragmentShader;
  24210. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  24211. if ( parameters.shadowMapType === PCFShadowMap ) {
  24212. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  24213. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  24214. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  24215. }
  24216. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  24217. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  24218. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  24219. if ( parameters.envMap ) {
  24220. switch ( material.envMap.mapping ) {
  24221. case CubeReflectionMapping:
  24222. case CubeRefractionMapping:
  24223. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  24224. break;
  24225. case CubeUVReflectionMapping:
  24226. case CubeUVRefractionMapping:
  24227. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  24228. break;
  24229. case EquirectangularReflectionMapping:
  24230. case EquirectangularRefractionMapping:
  24231. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  24232. break;
  24233. case SphericalReflectionMapping:
  24234. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  24235. break;
  24236. }
  24237. switch ( material.envMap.mapping ) {
  24238. case CubeRefractionMapping:
  24239. case EquirectangularRefractionMapping:
  24240. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  24241. break;
  24242. }
  24243. switch ( material.combine ) {
  24244. case MultiplyOperation:
  24245. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  24246. break;
  24247. case MixOperation:
  24248. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  24249. break;
  24250. case AddOperation:
  24251. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  24252. break;
  24253. }
  24254. }
  24255. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  24256. // console.log( 'building new program ' );
  24257. //
  24258. var customExtensions = generateExtensions( material.extensions, parameters, extensions );
  24259. var customDefines = generateDefines( defines );
  24260. //
  24261. var program = gl.createProgram();
  24262. var prefixVertex, prefixFragment;
  24263. if ( material.isRawShaderMaterial ) {
  24264. prefixVertex = [
  24265. customDefines
  24266. ].filter( filterEmptyLine ).join( '\n' );
  24267. if ( prefixVertex.length > 0 ) {
  24268. prefixVertex += '\n';
  24269. }
  24270. prefixFragment = [
  24271. customExtensions,
  24272. customDefines
  24273. ].filter( filterEmptyLine ).join( '\n' );
  24274. if ( prefixFragment.length > 0 ) {
  24275. prefixFragment += '\n';
  24276. }
  24277. } else {
  24278. prefixVertex = [
  24279. 'precision ' + parameters.precision + ' float;',
  24280. 'precision ' + parameters.precision + ' int;',
  24281. '#define SHADER_NAME ' + shader.name,
  24282. customDefines,
  24283. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  24284. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  24285. '#define MAX_BONES ' + parameters.maxBones,
  24286. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  24287. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  24288. parameters.map ? '#define USE_MAP' : '',
  24289. parameters.envMap ? '#define USE_ENVMAP' : '',
  24290. parameters.envMap ? '#define ' + envMapModeDefine : '',
  24291. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  24292. parameters.aoMap ? '#define USE_AOMAP' : '',
  24293. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  24294. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  24295. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  24296. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  24297. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  24298. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  24299. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  24300. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  24301. parameters.vertexColors ? '#define USE_COLOR' : '',
  24302. parameters.flatShading ? '#define FLAT_SHADED' : '',
  24303. parameters.skinning ? '#define USE_SKINNING' : '',
  24304. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  24305. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  24306. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  24307. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  24308. parameters.flipSided ? '#define FLIP_SIDED' : '',
  24309. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  24310. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  24311. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  24312. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  24313. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  24314. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  24315. 'uniform mat4 modelMatrix;',
  24316. 'uniform mat4 modelViewMatrix;',
  24317. 'uniform mat4 projectionMatrix;',
  24318. 'uniform mat4 viewMatrix;',
  24319. 'uniform mat3 normalMatrix;',
  24320. 'uniform vec3 cameraPosition;',
  24321. 'attribute vec3 position;',
  24322. 'attribute vec3 normal;',
  24323. 'attribute vec2 uv;',
  24324. '#ifdef USE_COLOR',
  24325. ' attribute vec3 color;',
  24326. '#endif',
  24327. '#ifdef USE_MORPHTARGETS',
  24328. ' attribute vec3 morphTarget0;',
  24329. ' attribute vec3 morphTarget1;',
  24330. ' attribute vec3 morphTarget2;',
  24331. ' attribute vec3 morphTarget3;',
  24332. ' #ifdef USE_MORPHNORMALS',
  24333. ' attribute vec3 morphNormal0;',
  24334. ' attribute vec3 morphNormal1;',
  24335. ' attribute vec3 morphNormal2;',
  24336. ' attribute vec3 morphNormal3;',
  24337. ' #else',
  24338. ' attribute vec3 morphTarget4;',
  24339. ' attribute vec3 morphTarget5;',
  24340. ' attribute vec3 morphTarget6;',
  24341. ' attribute vec3 morphTarget7;',
  24342. ' #endif',
  24343. '#endif',
  24344. '#ifdef USE_SKINNING',
  24345. ' attribute vec4 skinIndex;',
  24346. ' attribute vec4 skinWeight;',
  24347. '#endif',
  24348. '\n'
  24349. ].filter( filterEmptyLine ).join( '\n' );
  24350. prefixFragment = [
  24351. customExtensions,
  24352. 'precision ' + parameters.precision + ' float;',
  24353. 'precision ' + parameters.precision + ' int;',
  24354. '#define SHADER_NAME ' + shader.name,
  24355. customDefines,
  24356. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  24357. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  24358. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  24359. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  24360. parameters.map ? '#define USE_MAP' : '',
  24361. parameters.envMap ? '#define USE_ENVMAP' : '',
  24362. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  24363. parameters.envMap ? '#define ' + envMapModeDefine : '',
  24364. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  24365. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  24366. parameters.aoMap ? '#define USE_AOMAP' : '',
  24367. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  24368. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  24369. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  24370. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  24371. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  24372. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  24373. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  24374. parameters.vertexColors ? '#define USE_COLOR' : '',
  24375. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  24376. parameters.flatShading ? '#define FLAT_SHADED' : '',
  24377. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  24378. parameters.flipSided ? '#define FLIP_SIDED' : '',
  24379. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  24380. '#define UNION_CLIPPING_PLANES ' + ( parameters.numClippingPlanes - parameters.numClipIntersection ),
  24381. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  24382. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  24383. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  24384. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  24385. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  24386. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  24387. parameters.envMap && extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  24388. 'uniform mat4 viewMatrix;',
  24389. 'uniform vec3 cameraPosition;',
  24390. ( parameters.toneMapping !== NoToneMapping ) ? "#define TONE_MAPPING" : '',
  24391. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  24392. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
  24393. parameters.dithering ? '#define DITHERING' : '',
  24394. ( 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
  24395. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  24396. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  24397. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  24398. parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
  24399. parameters.depthPacking ? "#define DEPTH_PACKING " + material.depthPacking : '',
  24400. '\n'
  24401. ].filter( filterEmptyLine ).join( '\n' );
  24402. }
  24403. vertexShader = parseIncludes( vertexShader );
  24404. vertexShader = replaceLightNums( vertexShader, parameters );
  24405. fragmentShader = parseIncludes( fragmentShader );
  24406. fragmentShader = replaceLightNums( fragmentShader, parameters );
  24407. if ( ! material.isShaderMaterial ) {
  24408. vertexShader = unrollLoops( vertexShader );
  24409. fragmentShader = unrollLoops( fragmentShader );
  24410. }
  24411. var vertexGlsl = prefixVertex + vertexShader;
  24412. var fragmentGlsl = prefixFragment + fragmentShader;
  24413. // console.log( '*VERTEX*', vertexGlsl );
  24414. // console.log( '*FRAGMENT*', fragmentGlsl );
  24415. var glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  24416. var glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  24417. gl.attachShader( program, glVertexShader );
  24418. gl.attachShader( program, glFragmentShader );
  24419. // Force a particular attribute to index 0.
  24420. if ( material.index0AttributeName !== undefined ) {
  24421. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  24422. } else if ( parameters.morphTargets === true ) {
  24423. // programs with morphTargets displace position out of attribute 0
  24424. gl.bindAttribLocation( program, 0, 'position' );
  24425. }
  24426. gl.linkProgram( program );
  24427. var programLog = gl.getProgramInfoLog( program );
  24428. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  24429. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  24430. var runnable = true;
  24431. var haveDiagnostics = true;
  24432. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  24433. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  24434. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  24435. runnable = false;
  24436. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  24437. } else if ( programLog !== '' ) {
  24438. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  24439. } else if ( vertexLog === '' || fragmentLog === '' ) {
  24440. haveDiagnostics = false;
  24441. }
  24442. if ( haveDiagnostics ) {
  24443. this.diagnostics = {
  24444. runnable: runnable,
  24445. material: material,
  24446. programLog: programLog,
  24447. vertexShader: {
  24448. log: vertexLog,
  24449. prefix: prefixVertex
  24450. },
  24451. fragmentShader: {
  24452. log: fragmentLog,
  24453. prefix: prefixFragment
  24454. }
  24455. };
  24456. }
  24457. // clean up
  24458. gl.deleteShader( glVertexShader );
  24459. gl.deleteShader( glFragmentShader );
  24460. // set up caching for uniform locations
  24461. var cachedUniforms;
  24462. this.getUniforms = function () {
  24463. if ( cachedUniforms === undefined ) {
  24464. cachedUniforms = new WebGLUniforms( gl, program, renderer );
  24465. }
  24466. return cachedUniforms;
  24467. };
  24468. // set up caching for attribute locations
  24469. var cachedAttributes;
  24470. this.getAttributes = function () {
  24471. if ( cachedAttributes === undefined ) {
  24472. cachedAttributes = fetchAttributeLocations( gl, program );
  24473. }
  24474. return cachedAttributes;
  24475. };
  24476. // free resource
  24477. this.destroy = function () {
  24478. gl.deleteProgram( program );
  24479. this.program = undefined;
  24480. };
  24481. // DEPRECATED
  24482. Object.defineProperties( this, {
  24483. uniforms: {
  24484. get: function () {
  24485. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  24486. return this.getUniforms();
  24487. }
  24488. },
  24489. attributes: {
  24490. get: function () {
  24491. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  24492. return this.getAttributes();
  24493. }
  24494. }
  24495. } );
  24496. //
  24497. this.id = programIdCount ++;
  24498. this.code = code;
  24499. this.usedTimes = 1;
  24500. this.program = program;
  24501. this.vertexShader = glVertexShader;
  24502. this.fragmentShader = glFragmentShader;
  24503. return this;
  24504. }
  24505. /**
  24506. * @author mrdoob / http://mrdoob.com/
  24507. */
  24508. function WebGLPrograms( renderer, extensions, capabilities ) {
  24509. var programs = [];
  24510. var shaderIDs = {
  24511. MeshDepthMaterial: 'depth',
  24512. MeshDistanceMaterial: 'distanceRGBA',
  24513. MeshNormalMaterial: 'normal',
  24514. MeshBasicMaterial: 'basic',
  24515. MeshLambertMaterial: 'lambert',
  24516. MeshPhongMaterial: 'phong',
  24517. MeshToonMaterial: 'phong',
  24518. MeshStandardMaterial: 'physical',
  24519. MeshPhysicalMaterial: 'physical',
  24520. LineBasicMaterial: 'basic',
  24521. LineDashedMaterial: 'dashed',
  24522. PointsMaterial: 'points',
  24523. ShadowMaterial: 'shadow'
  24524. };
  24525. var parameterNames = [
  24526. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  24527. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  24528. "roughnessMap", "metalnessMap", "gradientMap",
  24529. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  24530. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  24531. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  24532. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  24533. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  24534. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  24535. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  24536. ];
  24537. function allocateBones( object ) {
  24538. var skeleton = object.skeleton;
  24539. var bones = skeleton.bones;
  24540. if ( capabilities.floatVertexTextures ) {
  24541. return 1024;
  24542. } else {
  24543. // default for when object is not specified
  24544. // ( for example when prebuilding shader to be used with multiple objects )
  24545. //
  24546. // - leave some extra space for other uniforms
  24547. // - limit here is ANGLE's 254 max uniform vectors
  24548. // (up to 54 should be safe)
  24549. var nVertexUniforms = capabilities.maxVertexUniforms;
  24550. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  24551. var maxBones = Math.min( nVertexMatrices, bones.length );
  24552. if ( maxBones < bones.length ) {
  24553. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  24554. return 0;
  24555. }
  24556. return maxBones;
  24557. }
  24558. }
  24559. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  24560. var encoding;
  24561. if ( ! map ) {
  24562. encoding = LinearEncoding;
  24563. } else if ( map.isTexture ) {
  24564. encoding = map.encoding;
  24565. } else if ( map.isWebGLRenderTarget ) {
  24566. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  24567. encoding = map.texture.encoding;
  24568. }
  24569. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  24570. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  24571. encoding = GammaEncoding;
  24572. }
  24573. return encoding;
  24574. }
  24575. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  24576. var shaderID = shaderIDs[ material.type ];
  24577. // heuristics to create shader parameters according to lights in the scene
  24578. // (not to blow over maxLights budget)
  24579. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  24580. var precision = capabilities.precision;
  24581. if ( material.precision !== null ) {
  24582. precision = capabilities.getMaxPrecision( material.precision );
  24583. if ( precision !== material.precision ) {
  24584. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  24585. }
  24586. }
  24587. var currentRenderTarget = renderer.getRenderTarget();
  24588. var parameters = {
  24589. shaderID: shaderID,
  24590. precision: precision,
  24591. supportsVertexTextures: capabilities.vertexTextures,
  24592. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  24593. map: !! material.map,
  24594. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  24595. envMap: !! material.envMap,
  24596. envMapMode: material.envMap && material.envMap.mapping,
  24597. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  24598. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  24599. lightMap: !! material.lightMap,
  24600. aoMap: !! material.aoMap,
  24601. emissiveMap: !! material.emissiveMap,
  24602. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  24603. bumpMap: !! material.bumpMap,
  24604. normalMap: !! material.normalMap,
  24605. displacementMap: !! material.displacementMap,
  24606. roughnessMap: !! material.roughnessMap,
  24607. metalnessMap: !! material.metalnessMap,
  24608. specularMap: !! material.specularMap,
  24609. alphaMap: !! material.alphaMap,
  24610. gradientMap: !! material.gradientMap,
  24611. combine: material.combine,
  24612. vertexColors: material.vertexColors,
  24613. fog: !! fog,
  24614. useFog: material.fog,
  24615. fogExp: ( fog && fog.isFogExp2 ),
  24616. flatShading: material.flatShading,
  24617. sizeAttenuation: material.sizeAttenuation,
  24618. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  24619. skinning: material.skinning && maxBones > 0,
  24620. maxBones: maxBones,
  24621. useVertexTexture: capabilities.floatVertexTextures,
  24622. morphTargets: material.morphTargets,
  24623. morphNormals: material.morphNormals,
  24624. maxMorphTargets: renderer.maxMorphTargets,
  24625. maxMorphNormals: renderer.maxMorphNormals,
  24626. numDirLights: lights.directional.length,
  24627. numPointLights: lights.point.length,
  24628. numSpotLights: lights.spot.length,
  24629. numRectAreaLights: lights.rectArea.length,
  24630. numHemiLights: lights.hemi.length,
  24631. numClippingPlanes: nClipPlanes,
  24632. numClipIntersection: nClipIntersection,
  24633. dithering: material.dithering,
  24634. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  24635. shadowMapType: renderer.shadowMap.type,
  24636. toneMapping: renderer.toneMapping,
  24637. physicallyCorrectLights: renderer.physicallyCorrectLights,
  24638. premultipliedAlpha: material.premultipliedAlpha,
  24639. alphaTest: material.alphaTest,
  24640. doubleSided: material.side === DoubleSide,
  24641. flipSided: material.side === BackSide,
  24642. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  24643. };
  24644. return parameters;
  24645. };
  24646. this.getProgramCode = function ( material, parameters ) {
  24647. var array = [];
  24648. if ( parameters.shaderID ) {
  24649. array.push( parameters.shaderID );
  24650. } else {
  24651. array.push( material.fragmentShader );
  24652. array.push( material.vertexShader );
  24653. }
  24654. if ( material.defines !== undefined ) {
  24655. for ( var name in material.defines ) {
  24656. array.push( name );
  24657. array.push( material.defines[ name ] );
  24658. }
  24659. }
  24660. for ( var i = 0; i < parameterNames.length; i ++ ) {
  24661. array.push( parameters[ parameterNames[ i ] ] );
  24662. }
  24663. array.push( material.onBeforeCompile.toString() );
  24664. array.push( renderer.gammaOutput );
  24665. return array.join();
  24666. };
  24667. this.acquireProgram = function ( material, shader, parameters, code ) {
  24668. var program;
  24669. // Check if code has been already compiled
  24670. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  24671. var programInfo = programs[ p ];
  24672. if ( programInfo.code === code ) {
  24673. program = programInfo;
  24674. ++ program.usedTimes;
  24675. break;
  24676. }
  24677. }
  24678. if ( program === undefined ) {
  24679. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters );
  24680. programs.push( program );
  24681. }
  24682. return program;
  24683. };
  24684. this.releaseProgram = function ( program ) {
  24685. if ( -- program.usedTimes === 0 ) {
  24686. // Remove from unordered set
  24687. var i = programs.indexOf( program );
  24688. programs[ i ] = programs[ programs.length - 1 ];
  24689. programs.pop();
  24690. // Free WebGL resources
  24691. program.destroy();
  24692. }
  24693. };
  24694. // Exposed for resource monitoring & error feedback via renderer.info:
  24695. this.programs = programs;
  24696. }
  24697. /**
  24698. * @author mrdoob / http://mrdoob.com/
  24699. */
  24700. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, infoMemory ) {
  24701. var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof window.WebGL2RenderingContext );
  24702. //
  24703. function clampToMaxSize( image, maxSize ) {
  24704. if ( image.width > maxSize || image.height > maxSize ) {
  24705. // Warning: Scaling through the canvas will only work with images that use
  24706. // premultiplied alpha.
  24707. var scale = maxSize / Math.max( image.width, image.height );
  24708. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  24709. canvas.width = Math.floor( image.width * scale );
  24710. canvas.height = Math.floor( image.height * scale );
  24711. var context = canvas.getContext( '2d' );
  24712. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  24713. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  24714. return canvas;
  24715. }
  24716. return image;
  24717. }
  24718. function isPowerOfTwo( image ) {
  24719. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  24720. }
  24721. function makePowerOfTwo( image ) {
  24722. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof ImageBitmap ) {
  24723. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  24724. canvas.width = _Math.floorPowerOfTwo( image.width );
  24725. canvas.height = _Math.floorPowerOfTwo( image.height );
  24726. var context = canvas.getContext( '2d' );
  24727. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  24728. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  24729. return canvas;
  24730. }
  24731. return image;
  24732. }
  24733. function textureNeedsPowerOfTwo( texture ) {
  24734. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  24735. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  24736. }
  24737. function textureNeedsGenerateMipmaps( texture, isPowerOfTwo ) {
  24738. return texture.generateMipmaps && isPowerOfTwo &&
  24739. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  24740. }
  24741. // Fallback filters for non-power-of-2 textures
  24742. function filterFallback( f ) {
  24743. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  24744. return _gl.NEAREST;
  24745. }
  24746. return _gl.LINEAR;
  24747. }
  24748. //
  24749. function onTextureDispose( event ) {
  24750. var texture = event.target;
  24751. texture.removeEventListener( 'dispose', onTextureDispose );
  24752. deallocateTexture( texture );
  24753. infoMemory.textures --;
  24754. }
  24755. function onRenderTargetDispose( event ) {
  24756. var renderTarget = event.target;
  24757. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  24758. deallocateRenderTarget( renderTarget );
  24759. infoMemory.textures --;
  24760. }
  24761. //
  24762. function deallocateTexture( texture ) {
  24763. var textureProperties = properties.get( texture );
  24764. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  24765. // cube texture
  24766. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  24767. } else {
  24768. // 2D texture
  24769. if ( textureProperties.__webglInit === undefined ) return;
  24770. _gl.deleteTexture( textureProperties.__webglTexture );
  24771. }
  24772. // remove all webgl properties
  24773. properties.remove( texture );
  24774. }
  24775. function deallocateRenderTarget( renderTarget ) {
  24776. var renderTargetProperties = properties.get( renderTarget );
  24777. var textureProperties = properties.get( renderTarget.texture );
  24778. if ( ! renderTarget ) return;
  24779. if ( textureProperties.__webglTexture !== undefined ) {
  24780. _gl.deleteTexture( textureProperties.__webglTexture );
  24781. }
  24782. if ( renderTarget.depthTexture ) {
  24783. renderTarget.depthTexture.dispose();
  24784. }
  24785. if ( renderTarget.isWebGLRenderTargetCube ) {
  24786. for ( var i = 0; i < 6; i ++ ) {
  24787. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  24788. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  24789. }
  24790. } else {
  24791. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  24792. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  24793. }
  24794. properties.remove( renderTarget.texture );
  24795. properties.remove( renderTarget );
  24796. }
  24797. //
  24798. function setTexture2D( texture, slot ) {
  24799. var textureProperties = properties.get( texture );
  24800. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  24801. var image = texture.image;
  24802. if ( image === undefined ) {
  24803. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  24804. } else if ( image.complete === false ) {
  24805. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  24806. } else {
  24807. uploadTexture( textureProperties, texture, slot );
  24808. return;
  24809. }
  24810. }
  24811. state.activeTexture( _gl.TEXTURE0 + slot );
  24812. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  24813. }
  24814. function setTextureCube( texture, slot ) {
  24815. var textureProperties = properties.get( texture );
  24816. if ( texture.image.length === 6 ) {
  24817. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  24818. if ( ! textureProperties.__image__webglTextureCube ) {
  24819. texture.addEventListener( 'dispose', onTextureDispose );
  24820. textureProperties.__image__webglTextureCube = _gl.createTexture();
  24821. infoMemory.textures ++;
  24822. }
  24823. state.activeTexture( _gl.TEXTURE0 + slot );
  24824. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  24825. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  24826. var isCompressed = ( texture && texture.isCompressedTexture );
  24827. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  24828. var cubeImage = [];
  24829. for ( var i = 0; i < 6; i ++ ) {
  24830. if ( ! isCompressed && ! isDataTexture ) {
  24831. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  24832. } else {
  24833. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  24834. }
  24835. }
  24836. var image = cubeImage[ 0 ],
  24837. isPowerOfTwoImage = isPowerOfTwo( image ),
  24838. glFormat = utils.convert( texture.format ),
  24839. glType = utils.convert( texture.type );
  24840. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  24841. for ( var i = 0; i < 6; i ++ ) {
  24842. if ( ! isCompressed ) {
  24843. if ( isDataTexture ) {
  24844. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  24845. } else {
  24846. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  24847. }
  24848. } else {
  24849. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  24850. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  24851. mipmap = mipmaps[ j ];
  24852. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  24853. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  24854. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  24855. } else {
  24856. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  24857. }
  24858. } else {
  24859. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  24860. }
  24861. }
  24862. }
  24863. }
  24864. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
  24865. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  24866. }
  24867. textureProperties.__version = texture.version;
  24868. if ( texture.onUpdate ) texture.onUpdate( texture );
  24869. } else {
  24870. state.activeTexture( _gl.TEXTURE0 + slot );
  24871. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  24872. }
  24873. }
  24874. }
  24875. function setTextureCubeDynamic( texture, slot ) {
  24876. state.activeTexture( _gl.TEXTURE0 + slot );
  24877. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  24878. }
  24879. function setTextureParameters( textureType, texture, isPowerOfTwoImage ) {
  24880. var extension;
  24881. if ( isPowerOfTwoImage ) {
  24882. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, utils.convert( texture.wrapS ) );
  24883. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, utils.convert( texture.wrapT ) );
  24884. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, utils.convert( texture.magFilter ) );
  24885. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, utils.convert( texture.minFilter ) );
  24886. } else {
  24887. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  24888. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  24889. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  24890. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  24891. }
  24892. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  24893. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  24894. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  24895. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  24896. }
  24897. }
  24898. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  24899. if ( extension ) {
  24900. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  24901. if ( texture.type === HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  24902. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  24903. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  24904. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  24905. }
  24906. }
  24907. }
  24908. function uploadTexture( textureProperties, texture, slot ) {
  24909. if ( textureProperties.__webglInit === undefined ) {
  24910. textureProperties.__webglInit = true;
  24911. texture.addEventListener( 'dispose', onTextureDispose );
  24912. textureProperties.__webglTexture = _gl.createTexture();
  24913. infoMemory.textures ++;
  24914. }
  24915. state.activeTexture( _gl.TEXTURE0 + slot );
  24916. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  24917. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  24918. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  24919. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  24920. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  24921. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  24922. image = makePowerOfTwo( image );
  24923. }
  24924. var isPowerOfTwoImage = isPowerOfTwo( image ),
  24925. glFormat = utils.convert( texture.format ),
  24926. glType = utils.convert( texture.type );
  24927. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  24928. var mipmap, mipmaps = texture.mipmaps;
  24929. if ( texture.isDepthTexture ) {
  24930. // populate depth texture with dummy data
  24931. var internalFormat = _gl.DEPTH_COMPONENT;
  24932. if ( texture.type === FloatType ) {
  24933. if ( ! _isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  24934. internalFormat = _gl.DEPTH_COMPONENT32F;
  24935. } else if ( _isWebGL2 ) {
  24936. // WebGL 2.0 requires signed internalformat for glTexImage2D
  24937. internalFormat = _gl.DEPTH_COMPONENT16;
  24938. }
  24939. if ( texture.format === DepthFormat && internalFormat === _gl.DEPTH_COMPONENT ) {
  24940. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  24941. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  24942. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  24943. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  24944. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  24945. texture.type = UnsignedShortType;
  24946. glType = utils.convert( texture.type );
  24947. }
  24948. }
  24949. // Depth stencil textures need the DEPTH_STENCIL internal format
  24950. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  24951. if ( texture.format === DepthStencilFormat ) {
  24952. internalFormat = _gl.DEPTH_STENCIL;
  24953. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  24954. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  24955. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  24956. if ( texture.type !== UnsignedInt248Type ) {
  24957. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  24958. texture.type = UnsignedInt248Type;
  24959. glType = utils.convert( texture.type );
  24960. }
  24961. }
  24962. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  24963. } else if ( texture.isDataTexture ) {
  24964. // use manually created mipmaps if available
  24965. // if there are no manual mipmaps
  24966. // set 0 level mipmap and then use GL to generate other mipmap levels
  24967. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  24968. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  24969. mipmap = mipmaps[ i ];
  24970. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  24971. }
  24972. texture.generateMipmaps = false;
  24973. } else {
  24974. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  24975. }
  24976. } else if ( texture.isCompressedTexture ) {
  24977. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  24978. mipmap = mipmaps[ i ];
  24979. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  24980. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  24981. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  24982. } else {
  24983. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  24984. }
  24985. } else {
  24986. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  24987. }
  24988. }
  24989. } else {
  24990. // regular Texture (image, video, canvas)
  24991. // use manually created mipmaps if available
  24992. // if there are no manual mipmaps
  24993. // set 0 level mipmap and then use GL to generate other mipmap levels
  24994. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  24995. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  24996. mipmap = mipmaps[ i ];
  24997. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  24998. }
  24999. texture.generateMipmaps = false;
  25000. } else {
  25001. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  25002. }
  25003. }
  25004. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) _gl.generateMipmap( _gl.TEXTURE_2D );
  25005. textureProperties.__version = texture.version;
  25006. if ( texture.onUpdate ) texture.onUpdate( texture );
  25007. }
  25008. // Render targets
  25009. // Setup storage for target texture and bind it to correct framebuffer
  25010. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  25011. var glFormat = utils.convert( renderTarget.texture.format );
  25012. var glType = utils.convert( renderTarget.texture.type );
  25013. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  25014. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  25015. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  25016. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  25017. }
  25018. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  25019. function setupRenderBufferStorage( renderbuffer, renderTarget ) {
  25020. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  25021. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  25022. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  25023. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  25024. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  25025. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  25026. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  25027. } else {
  25028. // FIXME: We don't support !depth !stencil
  25029. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  25030. }
  25031. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  25032. }
  25033. // Setup resources for a Depth Texture for a FBO (needs an extension)
  25034. function setupDepthTexture( framebuffer, renderTarget ) {
  25035. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  25036. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  25037. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  25038. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  25039. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  25040. }
  25041. // upload an empty depth texture with framebuffer size
  25042. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  25043. renderTarget.depthTexture.image.width !== renderTarget.width ||
  25044. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  25045. renderTarget.depthTexture.image.width = renderTarget.width;
  25046. renderTarget.depthTexture.image.height = renderTarget.height;
  25047. renderTarget.depthTexture.needsUpdate = true;
  25048. }
  25049. setTexture2D( renderTarget.depthTexture, 0 );
  25050. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  25051. if ( renderTarget.depthTexture.format === DepthFormat ) {
  25052. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  25053. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  25054. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  25055. } else {
  25056. throw new Error( 'Unknown depthTexture format' );
  25057. }
  25058. }
  25059. // Setup GL resources for a non-texture depth buffer
  25060. function setupDepthRenderbuffer( renderTarget ) {
  25061. var renderTargetProperties = properties.get( renderTarget );
  25062. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  25063. if ( renderTarget.depthTexture ) {
  25064. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  25065. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  25066. } else {
  25067. if ( isCube ) {
  25068. renderTargetProperties.__webglDepthbuffer = [];
  25069. for ( var i = 0; i < 6; i ++ ) {
  25070. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  25071. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  25072. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  25073. }
  25074. } else {
  25075. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  25076. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  25077. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  25078. }
  25079. }
  25080. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  25081. }
  25082. // Set up GL resources for the render target
  25083. function setupRenderTarget( renderTarget ) {
  25084. var renderTargetProperties = properties.get( renderTarget );
  25085. var textureProperties = properties.get( renderTarget.texture );
  25086. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  25087. textureProperties.__webglTexture = _gl.createTexture();
  25088. infoMemory.textures ++;
  25089. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  25090. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  25091. // Setup framebuffer
  25092. if ( isCube ) {
  25093. renderTargetProperties.__webglFramebuffer = [];
  25094. for ( var i = 0; i < 6; i ++ ) {
  25095. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  25096. }
  25097. } else {
  25098. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  25099. }
  25100. // Setup color buffer
  25101. if ( isCube ) {
  25102. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  25103. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  25104. for ( var i = 0; i < 6; i ++ ) {
  25105. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  25106. }
  25107. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  25108. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  25109. } else {
  25110. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  25111. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  25112. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  25113. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) _gl.generateMipmap( _gl.TEXTURE_2D );
  25114. state.bindTexture( _gl.TEXTURE_2D, null );
  25115. }
  25116. // Setup depth and stencil buffers
  25117. if ( renderTarget.depthBuffer ) {
  25118. setupDepthRenderbuffer( renderTarget );
  25119. }
  25120. }
  25121. function updateRenderTargetMipmap( renderTarget ) {
  25122. var texture = renderTarget.texture;
  25123. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  25124. if ( textureNeedsGenerateMipmaps( texture, isTargetPowerOfTwo ) ) {
  25125. var target = renderTarget.isWebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  25126. var webglTexture = properties.get( texture ).__webglTexture;
  25127. state.bindTexture( target, webglTexture );
  25128. _gl.generateMipmap( target );
  25129. state.bindTexture( target, null );
  25130. }
  25131. }
  25132. this.setTexture2D = setTexture2D;
  25133. this.setTextureCube = setTextureCube;
  25134. this.setTextureCubeDynamic = setTextureCubeDynamic;
  25135. this.setupRenderTarget = setupRenderTarget;
  25136. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  25137. }
  25138. /**
  25139. * @author fordacious / fordacious.github.io
  25140. */
  25141. function WebGLProperties() {
  25142. var properties = {};
  25143. function get( object ) {
  25144. var uuid = object.uuid;
  25145. var map = properties[ uuid ];
  25146. if ( map === undefined ) {
  25147. map = {};
  25148. properties[ uuid ] = map;
  25149. }
  25150. return map;
  25151. }
  25152. function remove( object ) {
  25153. delete properties[ object.uuid ];
  25154. }
  25155. function clear() {
  25156. properties = {};
  25157. }
  25158. return {
  25159. get: get,
  25160. remove: remove,
  25161. clear: clear
  25162. };
  25163. }
  25164. /**
  25165. * @author mrdoob / http://mrdoob.com/
  25166. */
  25167. function WebGLState( gl, extensions, utils ) {
  25168. function ColorBuffer() {
  25169. var locked = false;
  25170. var color = new Vector4();
  25171. var currentColorMask = null;
  25172. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  25173. return {
  25174. setMask: function ( colorMask ) {
  25175. if ( currentColorMask !== colorMask && ! locked ) {
  25176. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  25177. currentColorMask = colorMask;
  25178. }
  25179. },
  25180. setLocked: function ( lock ) {
  25181. locked = lock;
  25182. },
  25183. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  25184. if ( premultipliedAlpha === true ) {
  25185. r *= a; g *= a; b *= a;
  25186. }
  25187. color.set( r, g, b, a );
  25188. if ( currentColorClear.equals( color ) === false ) {
  25189. gl.clearColor( r, g, b, a );
  25190. currentColorClear.copy( color );
  25191. }
  25192. },
  25193. reset: function () {
  25194. locked = false;
  25195. currentColorMask = null;
  25196. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  25197. }
  25198. };
  25199. }
  25200. function DepthBuffer() {
  25201. var locked = false;
  25202. var currentDepthMask = null;
  25203. var currentDepthFunc = null;
  25204. var currentDepthClear = null;
  25205. return {
  25206. setTest: function ( depthTest ) {
  25207. if ( depthTest ) {
  25208. enable( gl.DEPTH_TEST );
  25209. } else {
  25210. disable( gl.DEPTH_TEST );
  25211. }
  25212. },
  25213. setMask: function ( depthMask ) {
  25214. if ( currentDepthMask !== depthMask && ! locked ) {
  25215. gl.depthMask( depthMask );
  25216. currentDepthMask = depthMask;
  25217. }
  25218. },
  25219. setFunc: function ( depthFunc ) {
  25220. if ( currentDepthFunc !== depthFunc ) {
  25221. if ( depthFunc ) {
  25222. switch ( depthFunc ) {
  25223. case NeverDepth:
  25224. gl.depthFunc( gl.NEVER );
  25225. break;
  25226. case AlwaysDepth:
  25227. gl.depthFunc( gl.ALWAYS );
  25228. break;
  25229. case LessDepth:
  25230. gl.depthFunc( gl.LESS );
  25231. break;
  25232. case LessEqualDepth:
  25233. gl.depthFunc( gl.LEQUAL );
  25234. break;
  25235. case EqualDepth:
  25236. gl.depthFunc( gl.EQUAL );
  25237. break;
  25238. case GreaterEqualDepth:
  25239. gl.depthFunc( gl.GEQUAL );
  25240. break;
  25241. case GreaterDepth:
  25242. gl.depthFunc( gl.GREATER );
  25243. break;
  25244. case NotEqualDepth:
  25245. gl.depthFunc( gl.NOTEQUAL );
  25246. break;
  25247. default:
  25248. gl.depthFunc( gl.LEQUAL );
  25249. }
  25250. } else {
  25251. gl.depthFunc( gl.LEQUAL );
  25252. }
  25253. currentDepthFunc = depthFunc;
  25254. }
  25255. },
  25256. setLocked: function ( lock ) {
  25257. locked = lock;
  25258. },
  25259. setClear: function ( depth ) {
  25260. if ( currentDepthClear !== depth ) {
  25261. gl.clearDepth( depth );
  25262. currentDepthClear = depth;
  25263. }
  25264. },
  25265. reset: function () {
  25266. locked = false;
  25267. currentDepthMask = null;
  25268. currentDepthFunc = null;
  25269. currentDepthClear = null;
  25270. }
  25271. };
  25272. }
  25273. function StencilBuffer() {
  25274. var locked = false;
  25275. var currentStencilMask = null;
  25276. var currentStencilFunc = null;
  25277. var currentStencilRef = null;
  25278. var currentStencilFuncMask = null;
  25279. var currentStencilFail = null;
  25280. var currentStencilZFail = null;
  25281. var currentStencilZPass = null;
  25282. var currentStencilClear = null;
  25283. return {
  25284. setTest: function ( stencilTest ) {
  25285. if ( stencilTest ) {
  25286. enable( gl.STENCIL_TEST );
  25287. } else {
  25288. disable( gl.STENCIL_TEST );
  25289. }
  25290. },
  25291. setMask: function ( stencilMask ) {
  25292. if ( currentStencilMask !== stencilMask && ! locked ) {
  25293. gl.stencilMask( stencilMask );
  25294. currentStencilMask = stencilMask;
  25295. }
  25296. },
  25297. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  25298. if ( currentStencilFunc !== stencilFunc ||
  25299. currentStencilRef !== stencilRef ||
  25300. currentStencilFuncMask !== stencilMask ) {
  25301. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  25302. currentStencilFunc = stencilFunc;
  25303. currentStencilRef = stencilRef;
  25304. currentStencilFuncMask = stencilMask;
  25305. }
  25306. },
  25307. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  25308. if ( currentStencilFail !== stencilFail ||
  25309. currentStencilZFail !== stencilZFail ||
  25310. currentStencilZPass !== stencilZPass ) {
  25311. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  25312. currentStencilFail = stencilFail;
  25313. currentStencilZFail = stencilZFail;
  25314. currentStencilZPass = stencilZPass;
  25315. }
  25316. },
  25317. setLocked: function ( lock ) {
  25318. locked = lock;
  25319. },
  25320. setClear: function ( stencil ) {
  25321. if ( currentStencilClear !== stencil ) {
  25322. gl.clearStencil( stencil );
  25323. currentStencilClear = stencil;
  25324. }
  25325. },
  25326. reset: function () {
  25327. locked = false;
  25328. currentStencilMask = null;
  25329. currentStencilFunc = null;
  25330. currentStencilRef = null;
  25331. currentStencilFuncMask = null;
  25332. currentStencilFail = null;
  25333. currentStencilZFail = null;
  25334. currentStencilZPass = null;
  25335. currentStencilClear = null;
  25336. }
  25337. };
  25338. }
  25339. //
  25340. var colorBuffer = new ColorBuffer();
  25341. var depthBuffer = new DepthBuffer();
  25342. var stencilBuffer = new StencilBuffer();
  25343. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  25344. var newAttributes = new Uint8Array( maxVertexAttributes );
  25345. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  25346. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  25347. var capabilities = {};
  25348. var compressedTextureFormats = null;
  25349. var currentProgram = null;
  25350. var currentBlending = null;
  25351. var currentBlendEquation = null;
  25352. var currentBlendSrc = null;
  25353. var currentBlendDst = null;
  25354. var currentBlendEquationAlpha = null;
  25355. var currentBlendSrcAlpha = null;
  25356. var currentBlendDstAlpha = null;
  25357. var currentPremultipledAlpha = false;
  25358. var currentFlipSided = null;
  25359. var currentCullFace = null;
  25360. var currentLineWidth = null;
  25361. var currentPolygonOffsetFactor = null;
  25362. var currentPolygonOffsetUnits = null;
  25363. var maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS );
  25364. var version = parseFloat( /^WebGL\ ([0-9])/.exec( gl.getParameter( gl.VERSION ) )[ 1 ] );
  25365. var lineWidthAvailable = parseFloat( version ) >= 1.0;
  25366. var currentTextureSlot = null;
  25367. var currentBoundTextures = {};
  25368. var currentScissor = new Vector4();
  25369. var currentViewport = new Vector4();
  25370. function createTexture( type, target, count ) {
  25371. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  25372. var texture = gl.createTexture();
  25373. gl.bindTexture( type, texture );
  25374. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  25375. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  25376. for ( var i = 0; i < count; i ++ ) {
  25377. gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  25378. }
  25379. return texture;
  25380. }
  25381. var emptyTextures = {};
  25382. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  25383. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  25384. // init
  25385. colorBuffer.setClear( 0, 0, 0, 1 );
  25386. depthBuffer.setClear( 1 );
  25387. stencilBuffer.setClear( 0 );
  25388. enable( gl.DEPTH_TEST );
  25389. depthBuffer.setFunc( LessEqualDepth );
  25390. setFlipSided( false );
  25391. setCullFace( CullFaceBack );
  25392. enable( gl.CULL_FACE );
  25393. enable( gl.BLEND );
  25394. setBlending( NormalBlending );
  25395. //
  25396. function initAttributes() {
  25397. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  25398. newAttributes[ i ] = 0;
  25399. }
  25400. }
  25401. function enableAttribute( attribute ) {
  25402. newAttributes[ attribute ] = 1;
  25403. if ( enabledAttributes[ attribute ] === 0 ) {
  25404. gl.enableVertexAttribArray( attribute );
  25405. enabledAttributes[ attribute ] = 1;
  25406. }
  25407. if ( attributeDivisors[ attribute ] !== 0 ) {
  25408. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  25409. extension.vertexAttribDivisorANGLE( attribute, 0 );
  25410. attributeDivisors[ attribute ] = 0;
  25411. }
  25412. }
  25413. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  25414. newAttributes[ attribute ] = 1;
  25415. if ( enabledAttributes[ attribute ] === 0 ) {
  25416. gl.enableVertexAttribArray( attribute );
  25417. enabledAttributes[ attribute ] = 1;
  25418. }
  25419. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  25420. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  25421. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  25422. attributeDivisors[ attribute ] = meshPerAttribute;
  25423. }
  25424. }
  25425. function disableUnusedAttributes() {
  25426. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  25427. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  25428. gl.disableVertexAttribArray( i );
  25429. enabledAttributes[ i ] = 0;
  25430. }
  25431. }
  25432. }
  25433. function enable( id ) {
  25434. if ( capabilities[ id ] !== true ) {
  25435. gl.enable( id );
  25436. capabilities[ id ] = true;
  25437. }
  25438. }
  25439. function disable( id ) {
  25440. if ( capabilities[ id ] !== false ) {
  25441. gl.disable( id );
  25442. capabilities[ id ] = false;
  25443. }
  25444. }
  25445. function getCompressedTextureFormats() {
  25446. if ( compressedTextureFormats === null ) {
  25447. compressedTextureFormats = [];
  25448. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  25449. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  25450. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  25451. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  25452. for ( var i = 0; i < formats.length; i ++ ) {
  25453. compressedTextureFormats.push( formats[ i ] );
  25454. }
  25455. }
  25456. }
  25457. return compressedTextureFormats;
  25458. }
  25459. function useProgram( program ) {
  25460. if ( currentProgram !== program ) {
  25461. gl.useProgram( program );
  25462. currentProgram = program;
  25463. return true;
  25464. }
  25465. return false;
  25466. }
  25467. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  25468. if ( blending !== NoBlending ) {
  25469. enable( gl.BLEND );
  25470. } else {
  25471. disable( gl.BLEND );
  25472. }
  25473. if ( blending !== CustomBlending ) {
  25474. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  25475. switch ( blending ) {
  25476. case AdditiveBlending:
  25477. if ( premultipliedAlpha ) {
  25478. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  25479. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  25480. } else {
  25481. gl.blendEquation( gl.FUNC_ADD );
  25482. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  25483. }
  25484. break;
  25485. case SubtractiveBlending:
  25486. if ( premultipliedAlpha ) {
  25487. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  25488. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  25489. } else {
  25490. gl.blendEquation( gl.FUNC_ADD );
  25491. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  25492. }
  25493. break;
  25494. case MultiplyBlending:
  25495. if ( premultipliedAlpha ) {
  25496. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  25497. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  25498. } else {
  25499. gl.blendEquation( gl.FUNC_ADD );
  25500. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  25501. }
  25502. break;
  25503. default:
  25504. if ( premultipliedAlpha ) {
  25505. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  25506. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  25507. } else {
  25508. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  25509. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  25510. }
  25511. }
  25512. }
  25513. currentBlendEquation = null;
  25514. currentBlendSrc = null;
  25515. currentBlendDst = null;
  25516. currentBlendEquationAlpha = null;
  25517. currentBlendSrcAlpha = null;
  25518. currentBlendDstAlpha = null;
  25519. } else {
  25520. blendEquationAlpha = blendEquationAlpha || blendEquation;
  25521. blendSrcAlpha = blendSrcAlpha || blendSrc;
  25522. blendDstAlpha = blendDstAlpha || blendDst;
  25523. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  25524. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  25525. currentBlendEquation = blendEquation;
  25526. currentBlendEquationAlpha = blendEquationAlpha;
  25527. }
  25528. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  25529. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  25530. currentBlendSrc = blendSrc;
  25531. currentBlendDst = blendDst;
  25532. currentBlendSrcAlpha = blendSrcAlpha;
  25533. currentBlendDstAlpha = blendDstAlpha;
  25534. }
  25535. }
  25536. currentBlending = blending;
  25537. currentPremultipledAlpha = premultipliedAlpha;
  25538. }
  25539. function setMaterial( material ) {
  25540. material.side === DoubleSide
  25541. ? disable( gl.CULL_FACE )
  25542. : enable( gl.CULL_FACE );
  25543. setFlipSided( material.side === BackSide );
  25544. material.transparent === true
  25545. ? setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha )
  25546. : setBlending( NoBlending );
  25547. depthBuffer.setFunc( material.depthFunc );
  25548. depthBuffer.setTest( material.depthTest );
  25549. depthBuffer.setMask( material.depthWrite );
  25550. colorBuffer.setMask( material.colorWrite );
  25551. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  25552. }
  25553. //
  25554. function setFlipSided( flipSided ) {
  25555. if ( currentFlipSided !== flipSided ) {
  25556. if ( flipSided ) {
  25557. gl.frontFace( gl.CW );
  25558. } else {
  25559. gl.frontFace( gl.CCW );
  25560. }
  25561. currentFlipSided = flipSided;
  25562. }
  25563. }
  25564. function setCullFace( cullFace ) {
  25565. if ( cullFace !== CullFaceNone ) {
  25566. enable( gl.CULL_FACE );
  25567. if ( cullFace !== currentCullFace ) {
  25568. if ( cullFace === CullFaceBack ) {
  25569. gl.cullFace( gl.BACK );
  25570. } else if ( cullFace === CullFaceFront ) {
  25571. gl.cullFace( gl.FRONT );
  25572. } else {
  25573. gl.cullFace( gl.FRONT_AND_BACK );
  25574. }
  25575. }
  25576. } else {
  25577. disable( gl.CULL_FACE );
  25578. }
  25579. currentCullFace = cullFace;
  25580. }
  25581. function setLineWidth( width ) {
  25582. if ( width !== currentLineWidth ) {
  25583. if ( lineWidthAvailable ) gl.lineWidth( width );
  25584. currentLineWidth = width;
  25585. }
  25586. }
  25587. function setPolygonOffset( polygonOffset, factor, units ) {
  25588. if ( polygonOffset ) {
  25589. enable( gl.POLYGON_OFFSET_FILL );
  25590. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  25591. gl.polygonOffset( factor, units );
  25592. currentPolygonOffsetFactor = factor;
  25593. currentPolygonOffsetUnits = units;
  25594. }
  25595. } else {
  25596. disable( gl.POLYGON_OFFSET_FILL );
  25597. }
  25598. }
  25599. function setScissorTest( scissorTest ) {
  25600. if ( scissorTest ) {
  25601. enable( gl.SCISSOR_TEST );
  25602. } else {
  25603. disable( gl.SCISSOR_TEST );
  25604. }
  25605. }
  25606. // texture
  25607. function activeTexture( webglSlot ) {
  25608. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  25609. if ( currentTextureSlot !== webglSlot ) {
  25610. gl.activeTexture( webglSlot );
  25611. currentTextureSlot = webglSlot;
  25612. }
  25613. }
  25614. function bindTexture( webglType, webglTexture ) {
  25615. if ( currentTextureSlot === null ) {
  25616. activeTexture();
  25617. }
  25618. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  25619. if ( boundTexture === undefined ) {
  25620. boundTexture = { type: undefined, texture: undefined };
  25621. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  25622. }
  25623. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  25624. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  25625. boundTexture.type = webglType;
  25626. boundTexture.texture = webglTexture;
  25627. }
  25628. }
  25629. function compressedTexImage2D() {
  25630. try {
  25631. gl.compressedTexImage2D.apply( gl, arguments );
  25632. } catch ( error ) {
  25633. console.error( 'THREE.WebGLState:', error );
  25634. }
  25635. }
  25636. function texImage2D() {
  25637. try {
  25638. gl.texImage2D.apply( gl, arguments );
  25639. } catch ( error ) {
  25640. console.error( 'THREE.WebGLState:', error );
  25641. }
  25642. }
  25643. //
  25644. function scissor( scissor ) {
  25645. if ( currentScissor.equals( scissor ) === false ) {
  25646. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  25647. currentScissor.copy( scissor );
  25648. }
  25649. }
  25650. function viewport( viewport ) {
  25651. if ( currentViewport.equals( viewport ) === false ) {
  25652. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  25653. currentViewport.copy( viewport );
  25654. }
  25655. }
  25656. //
  25657. function reset() {
  25658. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  25659. if ( enabledAttributes[ i ] === 1 ) {
  25660. gl.disableVertexAttribArray( i );
  25661. enabledAttributes[ i ] = 0;
  25662. }
  25663. }
  25664. capabilities = {};
  25665. compressedTextureFormats = null;
  25666. currentTextureSlot = null;
  25667. currentBoundTextures = {};
  25668. currentProgram = null;
  25669. currentBlending = null;
  25670. currentFlipSided = null;
  25671. currentCullFace = null;
  25672. colorBuffer.reset();
  25673. depthBuffer.reset();
  25674. stencilBuffer.reset();
  25675. }
  25676. return {
  25677. buffers: {
  25678. color: colorBuffer,
  25679. depth: depthBuffer,
  25680. stencil: stencilBuffer
  25681. },
  25682. initAttributes: initAttributes,
  25683. enableAttribute: enableAttribute,
  25684. enableAttributeAndDivisor: enableAttributeAndDivisor,
  25685. disableUnusedAttributes: disableUnusedAttributes,
  25686. enable: enable,
  25687. disable: disable,
  25688. getCompressedTextureFormats: getCompressedTextureFormats,
  25689. useProgram: useProgram,
  25690. setBlending: setBlending,
  25691. setMaterial: setMaterial,
  25692. setFlipSided: setFlipSided,
  25693. setCullFace: setCullFace,
  25694. setLineWidth: setLineWidth,
  25695. setPolygonOffset: setPolygonOffset,
  25696. setScissorTest: setScissorTest,
  25697. activeTexture: activeTexture,
  25698. bindTexture: bindTexture,
  25699. compressedTexImage2D: compressedTexImage2D,
  25700. texImage2D: texImage2D,
  25701. scissor: scissor,
  25702. viewport: viewport,
  25703. reset: reset
  25704. };
  25705. }
  25706. /**
  25707. * @author mrdoob / http://mrdoob.com/
  25708. */
  25709. function WebGLCapabilities( gl, extensions, parameters ) {
  25710. var maxAnisotropy;
  25711. function getMaxAnisotropy() {
  25712. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  25713. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  25714. if ( extension !== null ) {
  25715. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  25716. } else {
  25717. maxAnisotropy = 0;
  25718. }
  25719. return maxAnisotropy;
  25720. }
  25721. function getMaxPrecision( precision ) {
  25722. if ( precision === 'highp' ) {
  25723. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  25724. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  25725. return 'highp';
  25726. }
  25727. precision = 'mediump';
  25728. }
  25729. if ( precision === 'mediump' ) {
  25730. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  25731. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  25732. return 'mediump';
  25733. }
  25734. }
  25735. return 'lowp';
  25736. }
  25737. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  25738. var maxPrecision = getMaxPrecision( precision );
  25739. if ( maxPrecision !== precision ) {
  25740. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  25741. precision = maxPrecision;
  25742. }
  25743. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  25744. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  25745. var maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  25746. var maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  25747. var maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  25748. var maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  25749. var maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  25750. var maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  25751. var maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  25752. var vertexTextures = maxVertexTextures > 0;
  25753. var floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  25754. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  25755. return {
  25756. getMaxAnisotropy: getMaxAnisotropy,
  25757. getMaxPrecision: getMaxPrecision,
  25758. precision: precision,
  25759. logarithmicDepthBuffer: logarithmicDepthBuffer,
  25760. maxTextures: maxTextures,
  25761. maxVertexTextures: maxVertexTextures,
  25762. maxTextureSize: maxTextureSize,
  25763. maxCubemapSize: maxCubemapSize,
  25764. maxAttributes: maxAttributes,
  25765. maxVertexUniforms: maxVertexUniforms,
  25766. maxVaryings: maxVaryings,
  25767. maxFragmentUniforms: maxFragmentUniforms,
  25768. vertexTextures: vertexTextures,
  25769. floatFragmentTextures: floatFragmentTextures,
  25770. floatVertexTextures: floatVertexTextures
  25771. };
  25772. }
  25773. /**
  25774. * @author mrdoob / http://mrdoob.com/
  25775. */
  25776. function WebVRManager( renderer ) {
  25777. var scope = this;
  25778. var device = null;
  25779. var frameData = null;
  25780. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  25781. frameData = new window.VRFrameData();
  25782. }
  25783. var matrixWorldInverse = new Matrix4();
  25784. var standingMatrix = new Matrix4();
  25785. var standingMatrixInverse = new Matrix4();
  25786. var cameraL = new PerspectiveCamera();
  25787. cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
  25788. cameraL.layers.enable( 1 );
  25789. var cameraR = new PerspectiveCamera();
  25790. cameraR.bounds = new Vector4( 0.5, 0.0, 0.5, 1.0 );
  25791. cameraR.layers.enable( 2 );
  25792. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  25793. cameraVR.layers.enable( 1 );
  25794. cameraVR.layers.enable( 2 );
  25795. //
  25796. var currentSize, currentPixelRatio;
  25797. function onVRDisplayPresentChange() {
  25798. if ( device !== null && device.isPresenting ) {
  25799. var eyeParameters = device.getEyeParameters( 'left' );
  25800. var renderWidth = eyeParameters.renderWidth;
  25801. var renderHeight = eyeParameters.renderHeight;
  25802. currentPixelRatio = renderer.getPixelRatio();
  25803. currentSize = renderer.getSize();
  25804. renderer.setDrawingBufferSize( renderWidth * 2, renderHeight, 1 );
  25805. } else if ( scope.enabled ) {
  25806. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  25807. }
  25808. }
  25809. if ( typeof window !== 'undefined' ) {
  25810. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  25811. }
  25812. //
  25813. this.enabled = false;
  25814. this.standing = false;
  25815. this.getDevice = function () {
  25816. return device;
  25817. };
  25818. this.setDevice = function ( value ) {
  25819. if ( value !== undefined ) device = value;
  25820. };
  25821. this.getCamera = function ( camera ) {
  25822. if ( device === null ) return camera;
  25823. device.depthNear = camera.near;
  25824. device.depthFar = camera.far;
  25825. device.getFrameData( frameData );
  25826. //
  25827. var pose = frameData.pose;
  25828. if ( pose.position !== null ) {
  25829. camera.position.fromArray( pose.position );
  25830. } else {
  25831. camera.position.set( 0, 0, 0 );
  25832. }
  25833. if ( pose.orientation !== null ) {
  25834. camera.quaternion.fromArray( pose.orientation );
  25835. }
  25836. camera.updateMatrixWorld();
  25837. var stageParameters = device.stageParameters;
  25838. if ( this.standing && stageParameters ) {
  25839. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  25840. standingMatrixInverse.getInverse( standingMatrix );
  25841. camera.matrixWorld.multiply( standingMatrix );
  25842. camera.matrixWorldInverse.multiply( standingMatrixInverse );
  25843. }
  25844. if ( device.isPresenting === false ) return camera;
  25845. //
  25846. cameraL.near = camera.near;
  25847. cameraR.near = camera.near;
  25848. cameraL.far = camera.far;
  25849. cameraR.far = camera.far;
  25850. cameraVR.matrixWorld.copy( camera.matrixWorld );
  25851. cameraVR.matrixWorldInverse.copy( camera.matrixWorldInverse );
  25852. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  25853. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  25854. if ( this.standing && stageParameters ) {
  25855. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  25856. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  25857. }
  25858. var parent = camera.parent;
  25859. if ( parent !== null ) {
  25860. matrixWorldInverse.getInverse( parent.matrixWorld );
  25861. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  25862. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  25863. }
  25864. // envMap and Mirror needs camera.matrixWorld
  25865. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  25866. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  25867. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  25868. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  25869. // HACK @mrdoob
  25870. // https://github.com/w3c/webvr/issues/203
  25871. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  25872. //
  25873. var layers = device.getLayers();
  25874. if ( layers.length ) {
  25875. var layer = layers[ 0 ];
  25876. if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {
  25877. cameraL.bounds.fromArray( layer.leftBounds );
  25878. }
  25879. if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {
  25880. cameraR.bounds.fromArray( layer.rightBounds );
  25881. }
  25882. }
  25883. return cameraVR;
  25884. };
  25885. this.getStandingMatrix = function () {
  25886. return standingMatrix;
  25887. };
  25888. this.submitFrame = function () {
  25889. if ( device && device.isPresenting ) device.submitFrame();
  25890. };
  25891. this.dispose = function () {
  25892. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  25893. };
  25894. }
  25895. /**
  25896. * @author mrdoob / http://mrdoob.com/
  25897. */
  25898. function WebGLExtensions( gl ) {
  25899. var extensions = {};
  25900. return {
  25901. get: function ( name ) {
  25902. if ( extensions[ name ] !== undefined ) {
  25903. return extensions[ name ];
  25904. }
  25905. var extension;
  25906. switch ( name ) {
  25907. case 'WEBGL_depth_texture':
  25908. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  25909. break;
  25910. case 'EXT_texture_filter_anisotropic':
  25911. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  25912. break;
  25913. case 'WEBGL_compressed_texture_s3tc':
  25914. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  25915. break;
  25916. case 'WEBGL_compressed_texture_pvrtc':
  25917. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  25918. break;
  25919. case 'WEBGL_compressed_texture_etc1':
  25920. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  25921. break;
  25922. default:
  25923. extension = gl.getExtension( name );
  25924. }
  25925. if ( extension === null ) {
  25926. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  25927. }
  25928. extensions[ name ] = extension;
  25929. return extension;
  25930. }
  25931. };
  25932. }
  25933. /**
  25934. * @author tschw
  25935. */
  25936. function WebGLClipping() {
  25937. var scope = this,
  25938. globalState = null,
  25939. numGlobalPlanes = 0,
  25940. localClippingEnabled = false,
  25941. renderingShadows = false,
  25942. plane = new Plane(),
  25943. viewNormalMatrix = new Matrix3(),
  25944. uniform = { value: null, needsUpdate: false };
  25945. this.uniform = uniform;
  25946. this.numPlanes = 0;
  25947. this.numIntersection = 0;
  25948. this.init = function ( planes, enableLocalClipping, camera ) {
  25949. var enabled =
  25950. planes.length !== 0 ||
  25951. enableLocalClipping ||
  25952. // enable state of previous frame - the clipping code has to
  25953. // run another frame in order to reset the state:
  25954. numGlobalPlanes !== 0 ||
  25955. localClippingEnabled;
  25956. localClippingEnabled = enableLocalClipping;
  25957. globalState = projectPlanes( planes, camera, 0 );
  25958. numGlobalPlanes = planes.length;
  25959. return enabled;
  25960. };
  25961. this.beginShadows = function () {
  25962. renderingShadows = true;
  25963. projectPlanes( null );
  25964. };
  25965. this.endShadows = function () {
  25966. renderingShadows = false;
  25967. resetGlobalState();
  25968. };
  25969. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  25970. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  25971. // there's no local clipping
  25972. if ( renderingShadows ) {
  25973. // there's no global clipping
  25974. projectPlanes( null );
  25975. } else {
  25976. resetGlobalState();
  25977. }
  25978. } else {
  25979. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  25980. lGlobal = nGlobal * 4,
  25981. dstArray = cache.clippingState || null;
  25982. uniform.value = dstArray; // ensure unique state
  25983. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  25984. for ( var i = 0; i !== lGlobal; ++ i ) {
  25985. dstArray[ i ] = globalState[ i ];
  25986. }
  25987. cache.clippingState = dstArray;
  25988. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  25989. this.numPlanes += nGlobal;
  25990. }
  25991. };
  25992. function resetGlobalState() {
  25993. if ( uniform.value !== globalState ) {
  25994. uniform.value = globalState;
  25995. uniform.needsUpdate = numGlobalPlanes > 0;
  25996. }
  25997. scope.numPlanes = numGlobalPlanes;
  25998. scope.numIntersection = 0;
  25999. }
  26000. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  26001. var nPlanes = planes !== null ? planes.length : 0,
  26002. dstArray = null;
  26003. if ( nPlanes !== 0 ) {
  26004. dstArray = uniform.value;
  26005. if ( skipTransform !== true || dstArray === null ) {
  26006. var flatSize = dstOffset + nPlanes * 4,
  26007. viewMatrix = camera.matrixWorldInverse;
  26008. viewNormalMatrix.getNormalMatrix( viewMatrix );
  26009. if ( dstArray === null || dstArray.length < flatSize ) {
  26010. dstArray = new Float32Array( flatSize );
  26011. }
  26012. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  26013. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  26014. plane.normal.toArray( dstArray, i4 );
  26015. dstArray[ i4 + 3 ] = plane.constant;
  26016. }
  26017. }
  26018. uniform.value = dstArray;
  26019. uniform.needsUpdate = true;
  26020. }
  26021. scope.numPlanes = nPlanes;
  26022. return dstArray;
  26023. }
  26024. }
  26025. /**
  26026. * @author thespite / http://www.twitter.com/thespite
  26027. */
  26028. function WebGLUtils( gl, extensions ) {
  26029. function convert( p ) {
  26030. var extension;
  26031. if ( p === RepeatWrapping ) return gl.REPEAT;
  26032. if ( p === ClampToEdgeWrapping ) return gl.CLAMP_TO_EDGE;
  26033. if ( p === MirroredRepeatWrapping ) return gl.MIRRORED_REPEAT;
  26034. if ( p === NearestFilter ) return gl.NEAREST;
  26035. if ( p === NearestMipMapNearestFilter ) return gl.NEAREST_MIPMAP_NEAREST;
  26036. if ( p === NearestMipMapLinearFilter ) return gl.NEAREST_MIPMAP_LINEAR;
  26037. if ( p === LinearFilter ) return gl.LINEAR;
  26038. if ( p === LinearMipMapNearestFilter ) return gl.LINEAR_MIPMAP_NEAREST;
  26039. if ( p === LinearMipMapLinearFilter ) return gl.LINEAR_MIPMAP_LINEAR;
  26040. if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;
  26041. if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;
  26042. if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1;
  26043. if ( p === UnsignedShort565Type ) return gl.UNSIGNED_SHORT_5_6_5;
  26044. if ( p === ByteType ) return gl.BYTE;
  26045. if ( p === ShortType ) return gl.SHORT;
  26046. if ( p === UnsignedShortType ) return gl.UNSIGNED_SHORT;
  26047. if ( p === IntType ) return gl.INT;
  26048. if ( p === UnsignedIntType ) return gl.UNSIGNED_INT;
  26049. if ( p === FloatType ) return gl.FLOAT;
  26050. if ( p === HalfFloatType ) {
  26051. extension = extensions.get( 'OES_texture_half_float' );
  26052. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  26053. }
  26054. if ( p === AlphaFormat ) return gl.ALPHA;
  26055. if ( p === RGBFormat ) return gl.RGB;
  26056. if ( p === RGBAFormat ) return gl.RGBA;
  26057. if ( p === LuminanceFormat ) return gl.LUMINANCE;
  26058. if ( p === LuminanceAlphaFormat ) return gl.LUMINANCE_ALPHA;
  26059. if ( p === DepthFormat ) return gl.DEPTH_COMPONENT;
  26060. if ( p === DepthStencilFormat ) return gl.DEPTH_STENCIL;
  26061. if ( p === AddEquation ) return gl.FUNC_ADD;
  26062. if ( p === SubtractEquation ) return gl.FUNC_SUBTRACT;
  26063. if ( p === ReverseSubtractEquation ) return gl.FUNC_REVERSE_SUBTRACT;
  26064. if ( p === ZeroFactor ) return gl.ZERO;
  26065. if ( p === OneFactor ) return gl.ONE;
  26066. if ( p === SrcColorFactor ) return gl.SRC_COLOR;
  26067. if ( p === OneMinusSrcColorFactor ) return gl.ONE_MINUS_SRC_COLOR;
  26068. if ( p === SrcAlphaFactor ) return gl.SRC_ALPHA;
  26069. if ( p === OneMinusSrcAlphaFactor ) return gl.ONE_MINUS_SRC_ALPHA;
  26070. if ( p === DstAlphaFactor ) return gl.DST_ALPHA;
  26071. if ( p === OneMinusDstAlphaFactor ) return gl.ONE_MINUS_DST_ALPHA;
  26072. if ( p === DstColorFactor ) return gl.DST_COLOR;
  26073. if ( p === OneMinusDstColorFactor ) return gl.ONE_MINUS_DST_COLOR;
  26074. if ( p === SrcAlphaSaturateFactor ) return gl.SRC_ALPHA_SATURATE;
  26075. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  26076. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  26077. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  26078. if ( extension !== null ) {
  26079. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  26080. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  26081. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  26082. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  26083. }
  26084. }
  26085. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  26086. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  26087. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  26088. if ( extension !== null ) {
  26089. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  26090. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  26091. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  26092. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  26093. }
  26094. }
  26095. if ( p === RGB_ETC1_Format ) {
  26096. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  26097. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  26098. }
  26099. if ( p === MinEquation || p === MaxEquation ) {
  26100. extension = extensions.get( 'EXT_blend_minmax' );
  26101. if ( extension !== null ) {
  26102. if ( p === MinEquation ) return extension.MIN_EXT;
  26103. if ( p === MaxEquation ) return extension.MAX_EXT;
  26104. }
  26105. }
  26106. if ( p === UnsignedInt248Type ) {
  26107. extension = extensions.get( 'WEBGL_depth_texture' );
  26108. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  26109. }
  26110. return 0;
  26111. }
  26112. return { convert: convert };
  26113. }
  26114. /**
  26115. * @author supereggbert / http://www.paulbrunt.co.uk/
  26116. * @author mrdoob / http://mrdoob.com/
  26117. * @author alteredq / http://alteredqualia.com/
  26118. * @author szimek / https://github.com/szimek/
  26119. * @author tschw
  26120. */
  26121. function WebGLRenderer( parameters ) {
  26122. console.log( 'THREE.WebGLRenderer', REVISION );
  26123. parameters = parameters || {};
  26124. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  26125. _context = parameters.context !== undefined ? parameters.context : null,
  26126. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  26127. _depth = parameters.depth !== undefined ? parameters.depth : true,
  26128. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  26129. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  26130. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  26131. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  26132. var lightsArray = [];
  26133. var shadowsArray = [];
  26134. var currentRenderList = null;
  26135. var spritesArray = [];
  26136. var flaresArray = [];
  26137. // public properties
  26138. this.domElement = _canvas;
  26139. this.context = null;
  26140. // clearing
  26141. this.autoClear = true;
  26142. this.autoClearColor = true;
  26143. this.autoClearDepth = true;
  26144. this.autoClearStencil = true;
  26145. // scene graph
  26146. this.sortObjects = true;
  26147. // user-defined clipping
  26148. this.clippingPlanes = [];
  26149. this.localClippingEnabled = false;
  26150. // physically based shading
  26151. this.gammaFactor = 2.0; // for backwards compatibility
  26152. this.gammaInput = false;
  26153. this.gammaOutput = false;
  26154. // physical lights
  26155. this.physicallyCorrectLights = false;
  26156. // tone mapping
  26157. this.toneMapping = LinearToneMapping;
  26158. this.toneMappingExposure = 1.0;
  26159. this.toneMappingWhitePoint = 1.0;
  26160. // morphs
  26161. this.maxMorphTargets = 8;
  26162. this.maxMorphNormals = 4;
  26163. // internal properties
  26164. var _this = this,
  26165. _isContextLost = false,
  26166. // internal state cache
  26167. _currentRenderTarget = null,
  26168. _currentFramebuffer = null,
  26169. _currentMaterialId = - 1,
  26170. _currentGeometryProgram = '',
  26171. _currentCamera = null,
  26172. _currentArrayCamera = null,
  26173. _currentViewport = new Vector4(),
  26174. _currentScissor = new Vector4(),
  26175. _currentScissorTest = null,
  26176. //
  26177. _usedTextureUnits = 0,
  26178. //
  26179. _width = _canvas.width,
  26180. _height = _canvas.height,
  26181. _pixelRatio = 1,
  26182. _viewport = new Vector4( 0, 0, _width, _height ),
  26183. _scissor = new Vector4( 0, 0, _width, _height ),
  26184. _scissorTest = false,
  26185. // frustum
  26186. _frustum = new Frustum(),
  26187. // clipping
  26188. _clipping = new WebGLClipping(),
  26189. _clippingEnabled = false,
  26190. _localClippingEnabled = false,
  26191. // camera matrices cache
  26192. _projScreenMatrix = new Matrix4(),
  26193. _vector3 = new Vector3(),
  26194. // info
  26195. _infoMemory = {
  26196. geometries: 0,
  26197. textures: 0
  26198. },
  26199. _infoRender = {
  26200. frame: 0,
  26201. calls: 0,
  26202. vertices: 0,
  26203. faces: 0,
  26204. points: 0
  26205. };
  26206. this.info = {
  26207. render: _infoRender,
  26208. memory: _infoMemory,
  26209. programs: null
  26210. };
  26211. function getTargetPixelRatio() {
  26212. return _currentRenderTarget === null ? _pixelRatio : 1;
  26213. }
  26214. // initialize
  26215. var _gl;
  26216. try {
  26217. var contextAttributes = {
  26218. alpha: _alpha,
  26219. depth: _depth,
  26220. stencil: _stencil,
  26221. antialias: _antialias,
  26222. premultipliedAlpha: _premultipliedAlpha,
  26223. preserveDrawingBuffer: _preserveDrawingBuffer
  26224. };
  26225. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  26226. if ( _gl === null ) {
  26227. if ( _canvas.getContext( 'webgl' ) !== null ) {
  26228. throw 'Error creating WebGL context with your selected attributes.';
  26229. } else {
  26230. throw 'Error creating WebGL context.';
  26231. }
  26232. }
  26233. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  26234. if ( _gl.getShaderPrecisionFormat === undefined ) {
  26235. _gl.getShaderPrecisionFormat = function () {
  26236. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  26237. };
  26238. }
  26239. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  26240. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  26241. } catch ( error ) {
  26242. console.error( 'THREE.WebGLRenderer: ' + error );
  26243. }
  26244. var extensions, capabilities, state;
  26245. var properties, textures, attributes, geometries, objects, lights;
  26246. var programCache, renderLists;
  26247. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  26248. var flareRenderer, spriteRenderer;
  26249. var utils;
  26250. function initGLContext() {
  26251. extensions = new WebGLExtensions( _gl );
  26252. extensions.get( 'WEBGL_depth_texture' );
  26253. extensions.get( 'OES_texture_float' );
  26254. extensions.get( 'OES_texture_float_linear' );
  26255. extensions.get( 'OES_texture_half_float' );
  26256. extensions.get( 'OES_texture_half_float_linear' );
  26257. extensions.get( 'OES_standard_derivatives' );
  26258. extensions.get( 'OES_element_index_uint' );
  26259. extensions.get( 'ANGLE_instanced_arrays' );
  26260. utils = new WebGLUtils( _gl, extensions );
  26261. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  26262. state = new WebGLState( _gl, extensions, utils );
  26263. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  26264. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  26265. properties = new WebGLProperties();
  26266. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, _infoMemory );
  26267. attributes = new WebGLAttributes( _gl );
  26268. geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
  26269. objects = new WebGLObjects( geometries, _infoRender );
  26270. morphtargets = new WebGLMorphtargets( _gl );
  26271. programCache = new WebGLPrograms( _this, extensions, capabilities );
  26272. lights = new WebGLLights();
  26273. renderLists = new WebGLRenderLists();
  26274. background = new WebGLBackground( _this, state, geometries, _premultipliedAlpha );
  26275. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, _infoRender );
  26276. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  26277. flareRenderer = new WebGLFlareRenderer( _this, _gl, state, textures, capabilities );
  26278. spriteRenderer = new WebGLSpriteRenderer( _this, _gl, state, textures, capabilities );
  26279. _this.info.programs = programCache.programs;
  26280. _this.context = _gl;
  26281. _this.capabilities = capabilities;
  26282. _this.extensions = extensions;
  26283. _this.properties = properties;
  26284. _this.renderLists = renderLists;
  26285. _this.state = state;
  26286. }
  26287. initGLContext();
  26288. // vr
  26289. var vr = new WebVRManager( _this );
  26290. this.vr = vr;
  26291. // shadow map
  26292. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  26293. this.shadowMap = shadowMap;
  26294. // API
  26295. this.getContext = function () {
  26296. return _gl;
  26297. };
  26298. this.getContextAttributes = function () {
  26299. return _gl.getContextAttributes();
  26300. };
  26301. this.forceContextLoss = function () {
  26302. var extension = extensions.get( 'WEBGL_lose_context' );
  26303. if ( extension ) extension.loseContext();
  26304. };
  26305. this.forceContextRestore = function () {
  26306. var extension = extensions.get( 'WEBGL_lose_context' );
  26307. if ( extension ) extension.restoreContext();
  26308. };
  26309. this.getPixelRatio = function () {
  26310. return _pixelRatio;
  26311. };
  26312. this.setPixelRatio = function ( value ) {
  26313. if ( value === undefined ) return;
  26314. _pixelRatio = value;
  26315. this.setSize( _width, _height, false );
  26316. };
  26317. this.getSize = function () {
  26318. return {
  26319. width: _width,
  26320. height: _height
  26321. };
  26322. };
  26323. this.setSize = function ( width, height, updateStyle ) {
  26324. var device = vr.getDevice();
  26325. if ( device && device.isPresenting ) {
  26326. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  26327. return;
  26328. }
  26329. _width = width;
  26330. _height = height;
  26331. _canvas.width = width * _pixelRatio;
  26332. _canvas.height = height * _pixelRatio;
  26333. if ( updateStyle !== false ) {
  26334. _canvas.style.width = width + 'px';
  26335. _canvas.style.height = height + 'px';
  26336. }
  26337. this.setViewport( 0, 0, width, height );
  26338. };
  26339. this.getDrawingBufferSize = function () {
  26340. return {
  26341. width: _width * _pixelRatio,
  26342. height: _height * _pixelRatio
  26343. };
  26344. };
  26345. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  26346. _width = width;
  26347. _height = height;
  26348. _pixelRatio = pixelRatio;
  26349. _canvas.width = width * pixelRatio;
  26350. _canvas.height = height * pixelRatio;
  26351. this.setViewport( 0, 0, width, height );
  26352. };
  26353. this.setViewport = function ( x, y, width, height ) {
  26354. _viewport.set( x, _height - y - height, width, height );
  26355. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  26356. };
  26357. this.setScissor = function ( x, y, width, height ) {
  26358. _scissor.set( x, _height - y - height, width, height );
  26359. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  26360. };
  26361. this.setScissorTest = function ( boolean ) {
  26362. state.setScissorTest( _scissorTest = boolean );
  26363. };
  26364. // Clearing
  26365. this.getClearColor = function () {
  26366. return background.getClearColor();
  26367. };
  26368. this.setClearColor = function () {
  26369. background.setClearColor.apply( background, arguments );
  26370. };
  26371. this.getClearAlpha = function () {
  26372. return background.getClearAlpha();
  26373. };
  26374. this.setClearAlpha = function () {
  26375. background.setClearAlpha.apply( background, arguments );
  26376. };
  26377. this.clear = function ( color, depth, stencil ) {
  26378. var bits = 0;
  26379. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  26380. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  26381. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  26382. _gl.clear( bits );
  26383. };
  26384. this.clearColor = function () {
  26385. this.clear( true, false, false );
  26386. };
  26387. this.clearDepth = function () {
  26388. this.clear( false, true, false );
  26389. };
  26390. this.clearStencil = function () {
  26391. this.clear( false, false, true );
  26392. };
  26393. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  26394. this.setRenderTarget( renderTarget );
  26395. this.clear( color, depth, stencil );
  26396. };
  26397. //
  26398. this.dispose = function () {
  26399. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  26400. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  26401. renderLists.dispose();
  26402. vr.dispose();
  26403. };
  26404. // Events
  26405. function onContextLost( event ) {
  26406. event.preventDefault();
  26407. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  26408. _isContextLost = true;
  26409. }
  26410. function onContextRestore( /* event */ ) {
  26411. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  26412. _isContextLost = false;
  26413. initGLContext();
  26414. }
  26415. function onMaterialDispose( event ) {
  26416. var material = event.target;
  26417. material.removeEventListener( 'dispose', onMaterialDispose );
  26418. deallocateMaterial( material );
  26419. }
  26420. // Buffer deallocation
  26421. function deallocateMaterial( material ) {
  26422. releaseMaterialProgramReference( material );
  26423. properties.remove( material );
  26424. }
  26425. function releaseMaterialProgramReference( material ) {
  26426. var programInfo = properties.get( material ).program;
  26427. material.program = undefined;
  26428. if ( programInfo !== undefined ) {
  26429. programCache.releaseProgram( programInfo );
  26430. }
  26431. }
  26432. // Buffer rendering
  26433. function renderObjectImmediate( object, program, material ) {
  26434. object.render( function ( object ) {
  26435. _this.renderBufferImmediate( object, program, material );
  26436. } );
  26437. }
  26438. this.renderBufferImmediate = function ( object, program, material ) {
  26439. state.initAttributes();
  26440. var buffers = properties.get( object );
  26441. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  26442. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  26443. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  26444. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  26445. var programAttributes = program.getAttributes();
  26446. if ( object.hasPositions ) {
  26447. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  26448. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  26449. state.enableAttribute( programAttributes.position );
  26450. _gl.vertexAttribPointer( programAttributes.position, 3, _gl.FLOAT, false, 0, 0 );
  26451. }
  26452. if ( object.hasNormals ) {
  26453. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  26454. if ( ! material.isMeshPhongMaterial &&
  26455. ! material.isMeshStandardMaterial &&
  26456. ! material.isMeshNormalMaterial &&
  26457. material.flatShading === true ) {
  26458. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  26459. var array = object.normalArray;
  26460. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  26461. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  26462. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  26463. array[ i + 0 ] = nx;
  26464. array[ i + 1 ] = ny;
  26465. array[ i + 2 ] = nz;
  26466. array[ i + 3 ] = nx;
  26467. array[ i + 4 ] = ny;
  26468. array[ i + 5 ] = nz;
  26469. array[ i + 6 ] = nx;
  26470. array[ i + 7 ] = ny;
  26471. array[ i + 8 ] = nz;
  26472. }
  26473. }
  26474. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  26475. state.enableAttribute( programAttributes.normal );
  26476. _gl.vertexAttribPointer( programAttributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  26477. }
  26478. if ( object.hasUvs && material.map ) {
  26479. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  26480. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  26481. state.enableAttribute( programAttributes.uv );
  26482. _gl.vertexAttribPointer( programAttributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  26483. }
  26484. if ( object.hasColors && material.vertexColors !== NoColors ) {
  26485. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  26486. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  26487. state.enableAttribute( programAttributes.color );
  26488. _gl.vertexAttribPointer( programAttributes.color, 3, _gl.FLOAT, false, 0, 0 );
  26489. }
  26490. state.disableUnusedAttributes();
  26491. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  26492. object.count = 0;
  26493. };
  26494. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  26495. state.setMaterial( material );
  26496. var program = setProgram( camera, fog, material, object );
  26497. var geometryProgram = geometry.id + '_' + program.id + '_' + ( material.wireframe === true );
  26498. var updateBuffers = false;
  26499. if ( geometryProgram !== _currentGeometryProgram ) {
  26500. _currentGeometryProgram = geometryProgram;
  26501. updateBuffers = true;
  26502. }
  26503. if ( object.morphTargetInfluences ) {
  26504. morphtargets.update( object, geometry, material, program );
  26505. updateBuffers = true;
  26506. }
  26507. //
  26508. var index = geometry.index;
  26509. var position = geometry.attributes.position;
  26510. var rangeFactor = 1;
  26511. if ( material.wireframe === true ) {
  26512. index = geometries.getWireframeAttribute( geometry );
  26513. rangeFactor = 2;
  26514. }
  26515. var attribute;
  26516. var renderer = bufferRenderer;
  26517. if ( index !== null ) {
  26518. attribute = attributes.get( index );
  26519. renderer = indexedBufferRenderer;
  26520. renderer.setIndex( attribute );
  26521. }
  26522. if ( updateBuffers ) {
  26523. setupVertexAttributes( material, program, geometry );
  26524. if ( index !== null ) {
  26525. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attribute.buffer );
  26526. }
  26527. }
  26528. //
  26529. var dataCount = 0;
  26530. if ( index !== null ) {
  26531. dataCount = index.count;
  26532. } else if ( position !== undefined ) {
  26533. dataCount = position.count;
  26534. }
  26535. var rangeStart = geometry.drawRange.start * rangeFactor;
  26536. var rangeCount = geometry.drawRange.count * rangeFactor;
  26537. var groupStart = group !== null ? group.start * rangeFactor : 0;
  26538. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  26539. var drawStart = Math.max( rangeStart, groupStart );
  26540. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  26541. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  26542. if ( drawCount === 0 ) return;
  26543. //
  26544. if ( object.isMesh ) {
  26545. if ( material.wireframe === true ) {
  26546. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  26547. renderer.setMode( _gl.LINES );
  26548. } else {
  26549. switch ( object.drawMode ) {
  26550. case TrianglesDrawMode:
  26551. renderer.setMode( _gl.TRIANGLES );
  26552. break;
  26553. case TriangleStripDrawMode:
  26554. renderer.setMode( _gl.TRIANGLE_STRIP );
  26555. break;
  26556. case TriangleFanDrawMode:
  26557. renderer.setMode( _gl.TRIANGLE_FAN );
  26558. break;
  26559. }
  26560. }
  26561. } else if ( object.isLine ) {
  26562. var lineWidth = material.linewidth;
  26563. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  26564. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  26565. if ( object.isLineSegments ) {
  26566. renderer.setMode( _gl.LINES );
  26567. } else if ( object.isLineLoop ) {
  26568. renderer.setMode( _gl.LINE_LOOP );
  26569. } else {
  26570. renderer.setMode( _gl.LINE_STRIP );
  26571. }
  26572. } else if ( object.isPoints ) {
  26573. renderer.setMode( _gl.POINTS );
  26574. }
  26575. if ( geometry && geometry.isInstancedBufferGeometry ) {
  26576. if ( geometry.maxInstancedCount > 0 ) {
  26577. renderer.renderInstances( geometry, drawStart, drawCount );
  26578. }
  26579. } else {
  26580. renderer.render( drawStart, drawCount );
  26581. }
  26582. };
  26583. function setupVertexAttributes( material, program, geometry, startIndex ) {
  26584. if ( geometry && geometry.isInstancedBufferGeometry ) {
  26585. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  26586. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  26587. return;
  26588. }
  26589. }
  26590. if ( startIndex === undefined ) startIndex = 0;
  26591. state.initAttributes();
  26592. var geometryAttributes = geometry.attributes;
  26593. var programAttributes = program.getAttributes();
  26594. var materialDefaultAttributeValues = material.defaultAttributeValues;
  26595. for ( var name in programAttributes ) {
  26596. var programAttribute = programAttributes[ name ];
  26597. if ( programAttribute >= 0 ) {
  26598. var geometryAttribute = geometryAttributes[ name ];
  26599. if ( geometryAttribute !== undefined ) {
  26600. var normalized = geometryAttribute.normalized;
  26601. var size = geometryAttribute.itemSize;
  26602. var attribute = attributes.get( geometryAttribute );
  26603. // TODO Attribute may not be available on context restore
  26604. if ( attribute === undefined ) continue;
  26605. var buffer = attribute.buffer;
  26606. var type = attribute.type;
  26607. var bytesPerElement = attribute.bytesPerElement;
  26608. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  26609. var data = geometryAttribute.data;
  26610. var stride = data.stride;
  26611. var offset = geometryAttribute.offset;
  26612. if ( data && data.isInstancedInterleavedBuffer ) {
  26613. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  26614. if ( geometry.maxInstancedCount === undefined ) {
  26615. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  26616. }
  26617. } else {
  26618. state.enableAttribute( programAttribute );
  26619. }
  26620. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  26621. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, ( startIndex * stride + offset ) * bytesPerElement );
  26622. } else {
  26623. if ( geometryAttribute.isInstancedBufferAttribute ) {
  26624. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  26625. if ( geometry.maxInstancedCount === undefined ) {
  26626. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  26627. }
  26628. } else {
  26629. state.enableAttribute( programAttribute );
  26630. }
  26631. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  26632. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * bytesPerElement );
  26633. }
  26634. } else if ( materialDefaultAttributeValues !== undefined ) {
  26635. var value = materialDefaultAttributeValues[ name ];
  26636. if ( value !== undefined ) {
  26637. switch ( value.length ) {
  26638. case 2:
  26639. _gl.vertexAttrib2fv( programAttribute, value );
  26640. break;
  26641. case 3:
  26642. _gl.vertexAttrib3fv( programAttribute, value );
  26643. break;
  26644. case 4:
  26645. _gl.vertexAttrib4fv( programAttribute, value );
  26646. break;
  26647. default:
  26648. _gl.vertexAttrib1fv( programAttribute, value );
  26649. }
  26650. }
  26651. }
  26652. }
  26653. }
  26654. state.disableUnusedAttributes();
  26655. }
  26656. // Compile
  26657. this.compile = function ( scene, camera ) {
  26658. lightsArray.length = 0;
  26659. shadowsArray.length = 0;
  26660. scene.traverse( function ( object ) {
  26661. if ( object.isLight ) {
  26662. lightsArray.push( object );
  26663. if ( object.castShadow ) {
  26664. shadowsArray.push( object );
  26665. }
  26666. }
  26667. } );
  26668. lights.setup( lightsArray, shadowsArray, camera );
  26669. scene.traverse( function ( object ) {
  26670. if ( object.material ) {
  26671. if ( Array.isArray( object.material ) ) {
  26672. for ( var i = 0; i < object.material.length; i ++ ) {
  26673. initMaterial( object.material[ i ], scene.fog, object );
  26674. }
  26675. } else {
  26676. initMaterial( object.material, scene.fog, object );
  26677. }
  26678. }
  26679. } );
  26680. };
  26681. // Animation Loop
  26682. var isAnimating = false;
  26683. var onAnimationFrame = null;
  26684. function start() {
  26685. if ( isAnimating ) return;
  26686. var device = vr.getDevice();
  26687. if ( device && device.isPresenting ) {
  26688. device.requestAnimationFrame( loop );
  26689. } else {
  26690. window.requestAnimationFrame( loop );
  26691. }
  26692. isAnimating = true;
  26693. }
  26694. function loop( time ) {
  26695. if ( onAnimationFrame !== null ) onAnimationFrame( time );
  26696. var device = vr.getDevice();
  26697. if ( device && device.isPresenting ) {
  26698. device.requestAnimationFrame( loop );
  26699. } else {
  26700. window.requestAnimationFrame( loop );
  26701. }
  26702. }
  26703. this.animate = function ( callback ) {
  26704. onAnimationFrame = callback;
  26705. start();
  26706. };
  26707. // Rendering
  26708. this.render = function ( scene, camera, renderTarget, forceClear ) {
  26709. if ( ! ( camera && camera.isCamera ) ) {
  26710. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  26711. return;
  26712. }
  26713. if ( _isContextLost ) return;
  26714. // reset caching for this frame
  26715. _currentGeometryProgram = '';
  26716. _currentMaterialId = - 1;
  26717. _currentCamera = null;
  26718. // update scene graph
  26719. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  26720. // update camera matrices and frustum
  26721. if ( camera.parent === null ) camera.updateMatrixWorld();
  26722. if ( vr.enabled ) {
  26723. camera = vr.getCamera( camera );
  26724. }
  26725. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  26726. _frustum.setFromMatrix( _projScreenMatrix );
  26727. lightsArray.length = 0;
  26728. shadowsArray.length = 0;
  26729. spritesArray.length = 0;
  26730. flaresArray.length = 0;
  26731. _localClippingEnabled = this.localClippingEnabled;
  26732. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  26733. currentRenderList = renderLists.get( scene, camera );
  26734. currentRenderList.init();
  26735. projectObject( scene, camera, _this.sortObjects );
  26736. if ( _this.sortObjects === true ) {
  26737. currentRenderList.sort();
  26738. }
  26739. //
  26740. if ( _clippingEnabled ) _clipping.beginShadows();
  26741. shadowMap.render( shadowsArray, scene, camera );
  26742. lights.setup( lightsArray, shadowsArray, camera );
  26743. if ( _clippingEnabled ) _clipping.endShadows();
  26744. //
  26745. _infoRender.frame ++;
  26746. _infoRender.calls = 0;
  26747. _infoRender.vertices = 0;
  26748. _infoRender.faces = 0;
  26749. _infoRender.points = 0;
  26750. if ( renderTarget === undefined ) {
  26751. renderTarget = null;
  26752. }
  26753. this.setRenderTarget( renderTarget );
  26754. //
  26755. background.render( currentRenderList, scene, camera, forceClear );
  26756. // render scene
  26757. var opaqueObjects = currentRenderList.opaque;
  26758. var transparentObjects = currentRenderList.transparent;
  26759. if ( scene.overrideMaterial ) {
  26760. var overrideMaterial = scene.overrideMaterial;
  26761. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  26762. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  26763. } else {
  26764. // opaque pass (front-to-back order)
  26765. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  26766. // transparent pass (back-to-front order)
  26767. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  26768. }
  26769. // custom renderers
  26770. spriteRenderer.render( spritesArray, scene, camera );
  26771. flareRenderer.render( flaresArray, scene, camera, _currentViewport );
  26772. // Generate mipmap if we're using any kind of mipmap filtering
  26773. if ( renderTarget ) {
  26774. textures.updateRenderTargetMipmap( renderTarget );
  26775. }
  26776. // Ensure depth buffer writing is enabled so it can be cleared on next render
  26777. state.buffers.depth.setTest( true );
  26778. state.buffers.depth.setMask( true );
  26779. state.buffers.color.setMask( true );
  26780. state.setPolygonOffset( false );
  26781. if ( vr.enabled ) {
  26782. vr.submitFrame();
  26783. }
  26784. // _gl.finish();
  26785. };
  26786. /*
  26787. // TODO Duplicated code (Frustum)
  26788. var _sphere = new Sphere();
  26789. function isObjectViewable( object ) {
  26790. var geometry = object.geometry;
  26791. if ( geometry.boundingSphere === null )
  26792. geometry.computeBoundingSphere();
  26793. _sphere.copy( geometry.boundingSphere ).
  26794. applyMatrix4( object.matrixWorld );
  26795. return isSphereViewable( _sphere );
  26796. }
  26797. function isSpriteViewable( sprite ) {
  26798. _sphere.center.set( 0, 0, 0 );
  26799. _sphere.radius = 0.7071067811865476;
  26800. _sphere.applyMatrix4( sprite.matrixWorld );
  26801. return isSphereViewable( _sphere );
  26802. }
  26803. function isSphereViewable( sphere ) {
  26804. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  26805. var numPlanes = _clipping.numPlanes;
  26806. if ( numPlanes === 0 ) return true;
  26807. var planes = _this.clippingPlanes,
  26808. center = sphere.center,
  26809. negRad = - sphere.radius,
  26810. i = 0;
  26811. do {
  26812. // out when deeper than radius in the negative halfspace
  26813. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  26814. } while ( ++ i !== numPlanes );
  26815. return true;
  26816. }
  26817. */
  26818. function projectObject( object, camera, sortObjects ) {
  26819. if ( object.visible === false ) return;
  26820. var visible = object.layers.test( camera.layers );
  26821. if ( visible ) {
  26822. if ( object.isLight ) {
  26823. lightsArray.push( object );
  26824. if ( object.castShadow ) {
  26825. shadowsArray.push( object );
  26826. }
  26827. } else if ( object.isSprite ) {
  26828. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  26829. spritesArray.push( object );
  26830. }
  26831. } else if ( object.isLensFlare ) {
  26832. flaresArray.push( object );
  26833. } else if ( object.isImmediateRenderObject ) {
  26834. if ( sortObjects ) {
  26835. _vector3.setFromMatrixPosition( object.matrixWorld )
  26836. .applyMatrix4( _projScreenMatrix );
  26837. }
  26838. currentRenderList.push( object, null, object.material, _vector3.z, null );
  26839. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  26840. if ( object.isSkinnedMesh ) {
  26841. object.skeleton.update();
  26842. }
  26843. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  26844. if ( sortObjects ) {
  26845. _vector3.setFromMatrixPosition( object.matrixWorld )
  26846. .applyMatrix4( _projScreenMatrix );
  26847. }
  26848. var geometry = objects.update( object );
  26849. var material = object.material;
  26850. if ( Array.isArray( material ) ) {
  26851. var groups = geometry.groups;
  26852. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  26853. var group = groups[ i ];
  26854. var groupMaterial = material[ group.materialIndex ];
  26855. if ( groupMaterial && groupMaterial.visible ) {
  26856. currentRenderList.push( object, geometry, groupMaterial, _vector3.z, group );
  26857. }
  26858. }
  26859. } else if ( material.visible ) {
  26860. currentRenderList.push( object, geometry, material, _vector3.z, null );
  26861. }
  26862. }
  26863. }
  26864. }
  26865. var children = object.children;
  26866. for ( var i = 0, l = children.length; i < l; i ++ ) {
  26867. projectObject( children[ i ], camera, sortObjects );
  26868. }
  26869. }
  26870. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  26871. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  26872. var renderItem = renderList[ i ];
  26873. var object = renderItem.object;
  26874. var geometry = renderItem.geometry;
  26875. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  26876. var group = renderItem.group;
  26877. if ( camera.isArrayCamera ) {
  26878. _currentArrayCamera = camera;
  26879. var cameras = camera.cameras;
  26880. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  26881. var camera2 = cameras[ j ];
  26882. if ( object.layers.test( camera2.layers ) ) {
  26883. var bounds = camera2.bounds;
  26884. var x = bounds.x * _width;
  26885. var y = bounds.y * _height;
  26886. var width = bounds.z * _width;
  26887. var height = bounds.w * _height;
  26888. state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
  26889. renderObject( object, scene, camera2, geometry, material, group );
  26890. }
  26891. }
  26892. } else {
  26893. _currentArrayCamera = null;
  26894. renderObject( object, scene, camera, geometry, material, group );
  26895. }
  26896. }
  26897. }
  26898. function renderObject( object, scene, camera, geometry, material, group ) {
  26899. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  26900. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  26901. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  26902. if ( object.isImmediateRenderObject ) {
  26903. state.setMaterial( material );
  26904. var program = setProgram( camera, scene.fog, material, object );
  26905. _currentGeometryProgram = '';
  26906. renderObjectImmediate( object, program, material );
  26907. } else {
  26908. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  26909. }
  26910. object.onAfterRender( _this, scene, camera, geometry, material, group );
  26911. }
  26912. function initMaterial( material, fog, object ) {
  26913. var materialProperties = properties.get( material );
  26914. var parameters = programCache.getParameters(
  26915. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  26916. var code = programCache.getProgramCode( material, parameters );
  26917. var program = materialProperties.program;
  26918. var programChange = true;
  26919. if ( program === undefined ) {
  26920. // new material
  26921. material.addEventListener( 'dispose', onMaterialDispose );
  26922. } else if ( program.code !== code ) {
  26923. // changed glsl or parameters
  26924. releaseMaterialProgramReference( material );
  26925. } else if ( parameters.shaderID !== undefined ) {
  26926. // same glsl and uniform list
  26927. return;
  26928. } else {
  26929. // only rebuild uniform list
  26930. programChange = false;
  26931. }
  26932. if ( programChange ) {
  26933. if ( parameters.shaderID ) {
  26934. var shader = ShaderLib[ parameters.shaderID ];
  26935. materialProperties.shader = {
  26936. name: material.type,
  26937. uniforms: UniformsUtils.clone( shader.uniforms ),
  26938. vertexShader: shader.vertexShader,
  26939. fragmentShader: shader.fragmentShader
  26940. };
  26941. } else {
  26942. materialProperties.shader = {
  26943. name: material.type,
  26944. uniforms: material.uniforms,
  26945. vertexShader: material.vertexShader,
  26946. fragmentShader: material.fragmentShader
  26947. };
  26948. }
  26949. material.onBeforeCompile( materialProperties.shader );
  26950. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  26951. materialProperties.program = program;
  26952. material.program = program;
  26953. }
  26954. var programAttributes = program.getAttributes();
  26955. if ( material.morphTargets ) {
  26956. material.numSupportedMorphTargets = 0;
  26957. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  26958. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  26959. material.numSupportedMorphTargets ++;
  26960. }
  26961. }
  26962. }
  26963. if ( material.morphNormals ) {
  26964. material.numSupportedMorphNormals = 0;
  26965. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  26966. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  26967. material.numSupportedMorphNormals ++;
  26968. }
  26969. }
  26970. }
  26971. var uniforms = materialProperties.shader.uniforms;
  26972. if ( ! material.isShaderMaterial &&
  26973. ! material.isRawShaderMaterial ||
  26974. material.clipping === true ) {
  26975. materialProperties.numClippingPlanes = _clipping.numPlanes;
  26976. materialProperties.numIntersection = _clipping.numIntersection;
  26977. uniforms.clippingPlanes = _clipping.uniform;
  26978. }
  26979. materialProperties.fog = fog;
  26980. // store the light setup it was created for
  26981. materialProperties.lightsHash = lights.state.hash;
  26982. if ( material.lights ) {
  26983. // wire up the material to this renderer's lighting state
  26984. uniforms.ambientLightColor.value = lights.state.ambient;
  26985. uniforms.directionalLights.value = lights.state.directional;
  26986. uniforms.spotLights.value = lights.state.spot;
  26987. uniforms.rectAreaLights.value = lights.state.rectArea;
  26988. uniforms.pointLights.value = lights.state.point;
  26989. uniforms.hemisphereLights.value = lights.state.hemi;
  26990. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  26991. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  26992. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  26993. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  26994. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  26995. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  26996. // TODO (abelnation): add area lights shadow info to uniforms
  26997. }
  26998. var progUniforms = materialProperties.program.getUniforms(),
  26999. uniformsList =
  27000. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  27001. materialProperties.uniformsList = uniformsList;
  27002. }
  27003. function setProgram( camera, fog, material, object ) {
  27004. _usedTextureUnits = 0;
  27005. var materialProperties = properties.get( material );
  27006. if ( _clippingEnabled ) {
  27007. if ( _localClippingEnabled || camera !== _currentCamera ) {
  27008. var useCache =
  27009. camera === _currentCamera &&
  27010. material.id === _currentMaterialId;
  27011. // we might want to call this function with some ClippingGroup
  27012. // object instead of the material, once it becomes feasible
  27013. // (#8465, #8379)
  27014. _clipping.setState(
  27015. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  27016. camera, materialProperties, useCache );
  27017. }
  27018. }
  27019. if ( material.needsUpdate === false ) {
  27020. if ( materialProperties.program === undefined ) {
  27021. material.needsUpdate = true;
  27022. } else if ( material.fog && materialProperties.fog !== fog ) {
  27023. material.needsUpdate = true;
  27024. } else if ( material.lights && materialProperties.lightsHash !== lights.state.hash ) {
  27025. material.needsUpdate = true;
  27026. } else if ( materialProperties.numClippingPlanes !== undefined &&
  27027. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  27028. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  27029. material.needsUpdate = true;
  27030. }
  27031. }
  27032. if ( material.needsUpdate ) {
  27033. initMaterial( material, fog, object );
  27034. material.needsUpdate = false;
  27035. }
  27036. var refreshProgram = false;
  27037. var refreshMaterial = false;
  27038. var refreshLights = false;
  27039. var program = materialProperties.program,
  27040. p_uniforms = program.getUniforms(),
  27041. m_uniforms = materialProperties.shader.uniforms;
  27042. if ( state.useProgram( program.program ) ) {
  27043. refreshProgram = true;
  27044. refreshMaterial = true;
  27045. refreshLights = true;
  27046. }
  27047. if ( material.id !== _currentMaterialId ) {
  27048. _currentMaterialId = material.id;
  27049. refreshMaterial = true;
  27050. }
  27051. if ( refreshProgram || camera !== _currentCamera ) {
  27052. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  27053. if ( capabilities.logarithmicDepthBuffer ) {
  27054. p_uniforms.setValue( _gl, 'logDepthBufFC',
  27055. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  27056. }
  27057. // Avoid unneeded uniform updates per ArrayCamera's sub-camera
  27058. if ( _currentCamera !== ( _currentArrayCamera || camera ) ) {
  27059. _currentCamera = ( _currentArrayCamera || camera );
  27060. // lighting uniforms depend on the camera so enforce an update
  27061. // now, in case this material supports lights - or later, when
  27062. // the next material that does gets activated:
  27063. refreshMaterial = true; // set to true on material change
  27064. refreshLights = true; // remains set until update done
  27065. }
  27066. // load material specific uniforms
  27067. // (shader material also gets them for the sake of genericity)
  27068. if ( material.isShaderMaterial ||
  27069. material.isMeshPhongMaterial ||
  27070. material.isMeshStandardMaterial ||
  27071. material.envMap ) {
  27072. var uCamPos = p_uniforms.map.cameraPosition;
  27073. if ( uCamPos !== undefined ) {
  27074. uCamPos.setValue( _gl,
  27075. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  27076. }
  27077. }
  27078. if ( material.isMeshPhongMaterial ||
  27079. material.isMeshLambertMaterial ||
  27080. material.isMeshBasicMaterial ||
  27081. material.isMeshStandardMaterial ||
  27082. material.isShaderMaterial ||
  27083. material.skinning ) {
  27084. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  27085. }
  27086. }
  27087. // skinning uniforms must be set even if material didn't change
  27088. // auto-setting of texture unit for bone texture must go before other textures
  27089. // not sure why, but otherwise weird things happen
  27090. if ( material.skinning ) {
  27091. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  27092. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  27093. var skeleton = object.skeleton;
  27094. if ( skeleton ) {
  27095. var bones = skeleton.bones;
  27096. if ( capabilities.floatVertexTextures ) {
  27097. if ( skeleton.boneTexture === undefined ) {
  27098. // layout (1 matrix = 4 pixels)
  27099. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  27100. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  27101. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  27102. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  27103. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  27104. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  27105. size = _Math.ceilPowerOfTwo( size );
  27106. size = Math.max( size, 4 );
  27107. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  27108. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  27109. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  27110. skeleton.boneMatrices = boneMatrices;
  27111. skeleton.boneTexture = boneTexture;
  27112. skeleton.boneTextureSize = size;
  27113. }
  27114. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture );
  27115. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  27116. } else {
  27117. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  27118. }
  27119. }
  27120. }
  27121. if ( refreshMaterial ) {
  27122. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  27123. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  27124. if ( material.lights ) {
  27125. // the current material requires lighting info
  27126. // note: all lighting uniforms are always set correctly
  27127. // they simply reference the renderer's state for their
  27128. // values
  27129. //
  27130. // use the current material's .needsUpdate flags to set
  27131. // the GL state when required
  27132. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  27133. }
  27134. // refresh uniforms common to several materials
  27135. if ( fog && material.fog ) {
  27136. refreshUniformsFog( m_uniforms, fog );
  27137. }
  27138. if ( material.isMeshBasicMaterial ) {
  27139. refreshUniformsCommon( m_uniforms, material );
  27140. } else if ( material.isMeshLambertMaterial ) {
  27141. refreshUniformsCommon( m_uniforms, material );
  27142. refreshUniformsLambert( m_uniforms, material );
  27143. } else if ( material.isMeshPhongMaterial ) {
  27144. refreshUniformsCommon( m_uniforms, material );
  27145. if ( material.isMeshToonMaterial ) {
  27146. refreshUniformsToon( m_uniforms, material );
  27147. } else {
  27148. refreshUniformsPhong( m_uniforms, material );
  27149. }
  27150. } else if ( material.isMeshStandardMaterial ) {
  27151. refreshUniformsCommon( m_uniforms, material );
  27152. if ( material.isMeshPhysicalMaterial ) {
  27153. refreshUniformsPhysical( m_uniforms, material );
  27154. } else {
  27155. refreshUniformsStandard( m_uniforms, material );
  27156. }
  27157. } else if ( material.isMeshDepthMaterial ) {
  27158. refreshUniformsCommon( m_uniforms, material );
  27159. refreshUniformsDepth( m_uniforms, material );
  27160. } else if ( material.isMeshDistanceMaterial ) {
  27161. refreshUniformsCommon( m_uniforms, material );
  27162. refreshUniformsDistance( m_uniforms, material );
  27163. } else if ( material.isMeshNormalMaterial ) {
  27164. refreshUniformsCommon( m_uniforms, material );
  27165. refreshUniformsNormal( m_uniforms, material );
  27166. } else if ( material.isLineBasicMaterial ) {
  27167. refreshUniformsLine( m_uniforms, material );
  27168. if ( material.isLineDashedMaterial ) {
  27169. refreshUniformsDash( m_uniforms, material );
  27170. }
  27171. } else if ( material.isPointsMaterial ) {
  27172. refreshUniformsPoints( m_uniforms, material );
  27173. } else if ( material.isShadowMaterial ) {
  27174. m_uniforms.color.value = material.color;
  27175. m_uniforms.opacity.value = material.opacity;
  27176. }
  27177. // RectAreaLight Texture
  27178. // TODO (mrdoob): Find a nicer implementation
  27179. if ( m_uniforms.ltcMat !== undefined ) m_uniforms.ltcMat.value = UniformsLib.LTC_MAT_TEXTURE;
  27180. if ( m_uniforms.ltcMag !== undefined ) m_uniforms.ltcMag.value = UniformsLib.LTC_MAG_TEXTURE;
  27181. WebGLUniforms.upload(
  27182. _gl, materialProperties.uniformsList, m_uniforms, _this );
  27183. }
  27184. // common matrices
  27185. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  27186. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  27187. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  27188. return program;
  27189. }
  27190. // Uniforms (refresh uniforms objects)
  27191. function refreshUniformsCommon( uniforms, material ) {
  27192. uniforms.opacity.value = material.opacity;
  27193. if ( material.color ) {
  27194. uniforms.diffuse.value = material.color;
  27195. }
  27196. if ( material.emissive ) {
  27197. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  27198. }
  27199. if ( material.map ) {
  27200. uniforms.map.value = material.map;
  27201. }
  27202. if ( material.alphaMap ) {
  27203. uniforms.alphaMap.value = material.alphaMap;
  27204. }
  27205. if ( material.specularMap ) {
  27206. uniforms.specularMap.value = material.specularMap;
  27207. }
  27208. if ( material.envMap ) {
  27209. uniforms.envMap.value = material.envMap;
  27210. // don't flip CubeTexture envMaps, flip everything else:
  27211. // WebGLRenderTargetCube will be flipped for backwards compatibility
  27212. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  27213. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  27214. uniforms.flipEnvMap.value = ( ! ( material.envMap && material.envMap.isCubeTexture ) ) ? 1 : - 1;
  27215. uniforms.reflectivity.value = material.reflectivity;
  27216. uniforms.refractionRatio.value = material.refractionRatio;
  27217. }
  27218. if ( material.lightMap ) {
  27219. uniforms.lightMap.value = material.lightMap;
  27220. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  27221. }
  27222. if ( material.aoMap ) {
  27223. uniforms.aoMap.value = material.aoMap;
  27224. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  27225. }
  27226. // uv repeat and offset setting priorities
  27227. // 1. color map
  27228. // 2. specular map
  27229. // 3. normal map
  27230. // 4. bump map
  27231. // 5. alpha map
  27232. // 6. emissive map
  27233. var uvScaleMap;
  27234. if ( material.map ) {
  27235. uvScaleMap = material.map;
  27236. } else if ( material.specularMap ) {
  27237. uvScaleMap = material.specularMap;
  27238. } else if ( material.displacementMap ) {
  27239. uvScaleMap = material.displacementMap;
  27240. } else if ( material.normalMap ) {
  27241. uvScaleMap = material.normalMap;
  27242. } else if ( material.bumpMap ) {
  27243. uvScaleMap = material.bumpMap;
  27244. } else if ( material.roughnessMap ) {
  27245. uvScaleMap = material.roughnessMap;
  27246. } else if ( material.metalnessMap ) {
  27247. uvScaleMap = material.metalnessMap;
  27248. } else if ( material.alphaMap ) {
  27249. uvScaleMap = material.alphaMap;
  27250. } else if ( material.emissiveMap ) {
  27251. uvScaleMap = material.emissiveMap;
  27252. }
  27253. if ( uvScaleMap !== undefined ) {
  27254. // backwards compatibility
  27255. if ( uvScaleMap.isWebGLRenderTarget ) {
  27256. uvScaleMap = uvScaleMap.texture;
  27257. }
  27258. if ( uvScaleMap.matrixAutoUpdate === true ) {
  27259. var offset = uvScaleMap.offset;
  27260. var repeat = uvScaleMap.repeat;
  27261. var rotation = uvScaleMap.rotation;
  27262. var center = uvScaleMap.center;
  27263. uvScaleMap.matrix.setUvTransform( offset.x, offset.y, repeat.x, repeat.y, rotation, center.x, center.y );
  27264. }
  27265. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  27266. }
  27267. }
  27268. function refreshUniformsLine( uniforms, material ) {
  27269. uniforms.diffuse.value = material.color;
  27270. uniforms.opacity.value = material.opacity;
  27271. }
  27272. function refreshUniformsDash( uniforms, material ) {
  27273. uniforms.dashSize.value = material.dashSize;
  27274. uniforms.totalSize.value = material.dashSize + material.gapSize;
  27275. uniforms.scale.value = material.scale;
  27276. }
  27277. function refreshUniformsPoints( uniforms, material ) {
  27278. uniforms.diffuse.value = material.color;
  27279. uniforms.opacity.value = material.opacity;
  27280. uniforms.size.value = material.size * _pixelRatio;
  27281. uniforms.scale.value = _height * 0.5;
  27282. uniforms.map.value = material.map;
  27283. if ( material.map !== null ) {
  27284. if ( material.map.matrixAutoUpdate === true ) {
  27285. var offset = material.map.offset;
  27286. var repeat = material.map.repeat;
  27287. var rotation = material.map.rotation;
  27288. var center = material.map.center;
  27289. material.map.matrix.setUvTransform( offset.x, offset.y, repeat.x, repeat.y, rotation, center.x, center.y );
  27290. }
  27291. uniforms.uvTransform.value.copy( material.map.matrix );
  27292. }
  27293. }
  27294. function refreshUniformsFog( uniforms, fog ) {
  27295. uniforms.fogColor.value = fog.color;
  27296. if ( fog.isFog ) {
  27297. uniforms.fogNear.value = fog.near;
  27298. uniforms.fogFar.value = fog.far;
  27299. } else if ( fog.isFogExp2 ) {
  27300. uniforms.fogDensity.value = fog.density;
  27301. }
  27302. }
  27303. function refreshUniformsLambert( uniforms, material ) {
  27304. if ( material.emissiveMap ) {
  27305. uniforms.emissiveMap.value = material.emissiveMap;
  27306. }
  27307. }
  27308. function refreshUniformsPhong( uniforms, material ) {
  27309. uniforms.specular.value = material.specular;
  27310. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  27311. if ( material.emissiveMap ) {
  27312. uniforms.emissiveMap.value = material.emissiveMap;
  27313. }
  27314. if ( material.bumpMap ) {
  27315. uniforms.bumpMap.value = material.bumpMap;
  27316. uniforms.bumpScale.value = material.bumpScale;
  27317. }
  27318. if ( material.normalMap ) {
  27319. uniforms.normalMap.value = material.normalMap;
  27320. uniforms.normalScale.value.copy( material.normalScale );
  27321. }
  27322. if ( material.displacementMap ) {
  27323. uniforms.displacementMap.value = material.displacementMap;
  27324. uniforms.displacementScale.value = material.displacementScale;
  27325. uniforms.displacementBias.value = material.displacementBias;
  27326. }
  27327. }
  27328. function refreshUniformsToon( uniforms, material ) {
  27329. refreshUniformsPhong( uniforms, material );
  27330. if ( material.gradientMap ) {
  27331. uniforms.gradientMap.value = material.gradientMap;
  27332. }
  27333. }
  27334. function refreshUniformsStandard( uniforms, material ) {
  27335. uniforms.roughness.value = material.roughness;
  27336. uniforms.metalness.value = material.metalness;
  27337. if ( material.roughnessMap ) {
  27338. uniforms.roughnessMap.value = material.roughnessMap;
  27339. }
  27340. if ( material.metalnessMap ) {
  27341. uniforms.metalnessMap.value = material.metalnessMap;
  27342. }
  27343. if ( material.emissiveMap ) {
  27344. uniforms.emissiveMap.value = material.emissiveMap;
  27345. }
  27346. if ( material.bumpMap ) {
  27347. uniforms.bumpMap.value = material.bumpMap;
  27348. uniforms.bumpScale.value = material.bumpScale;
  27349. }
  27350. if ( material.normalMap ) {
  27351. uniforms.normalMap.value = material.normalMap;
  27352. uniforms.normalScale.value.copy( material.normalScale );
  27353. }
  27354. if ( material.displacementMap ) {
  27355. uniforms.displacementMap.value = material.displacementMap;
  27356. uniforms.displacementScale.value = material.displacementScale;
  27357. uniforms.displacementBias.value = material.displacementBias;
  27358. }
  27359. if ( material.envMap ) {
  27360. //uniforms.envMap.value = material.envMap; // part of uniforms common
  27361. uniforms.envMapIntensity.value = material.envMapIntensity;
  27362. }
  27363. }
  27364. function refreshUniformsPhysical( uniforms, material ) {
  27365. uniforms.clearCoat.value = material.clearCoat;
  27366. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  27367. refreshUniformsStandard( uniforms, material );
  27368. }
  27369. function refreshUniformsDepth( uniforms, material ) {
  27370. if ( material.displacementMap ) {
  27371. uniforms.displacementMap.value = material.displacementMap;
  27372. uniforms.displacementScale.value = material.displacementScale;
  27373. uniforms.displacementBias.value = material.displacementBias;
  27374. }
  27375. }
  27376. function refreshUniformsDistance( uniforms, material ) {
  27377. if ( material.displacementMap ) {
  27378. uniforms.displacementMap.value = material.displacementMap;
  27379. uniforms.displacementScale.value = material.displacementScale;
  27380. uniforms.displacementBias.value = material.displacementBias;
  27381. }
  27382. uniforms.referencePosition.value.copy( material.referencePosition );
  27383. uniforms.nearDistance.value = material.nearDistance;
  27384. uniforms.farDistance.value = material.farDistance;
  27385. }
  27386. function refreshUniformsNormal( uniforms, material ) {
  27387. if ( material.bumpMap ) {
  27388. uniforms.bumpMap.value = material.bumpMap;
  27389. uniforms.bumpScale.value = material.bumpScale;
  27390. }
  27391. if ( material.normalMap ) {
  27392. uniforms.normalMap.value = material.normalMap;
  27393. uniforms.normalScale.value.copy( material.normalScale );
  27394. }
  27395. if ( material.displacementMap ) {
  27396. uniforms.displacementMap.value = material.displacementMap;
  27397. uniforms.displacementScale.value = material.displacementScale;
  27398. uniforms.displacementBias.value = material.displacementBias;
  27399. }
  27400. }
  27401. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  27402. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  27403. uniforms.ambientLightColor.needsUpdate = value;
  27404. uniforms.directionalLights.needsUpdate = value;
  27405. uniforms.pointLights.needsUpdate = value;
  27406. uniforms.spotLights.needsUpdate = value;
  27407. uniforms.rectAreaLights.needsUpdate = value;
  27408. uniforms.hemisphereLights.needsUpdate = value;
  27409. }
  27410. // GL state setting
  27411. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  27412. state.setCullFace( cullFace );
  27413. state.setFlipSided( frontFaceDirection === FrontFaceDirectionCW );
  27414. };
  27415. // Textures
  27416. function allocTextureUnit() {
  27417. var textureUnit = _usedTextureUnits;
  27418. if ( textureUnit >= capabilities.maxTextures ) {
  27419. console.warn( 'THREE.WebGLRenderer: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  27420. }
  27421. _usedTextureUnits += 1;
  27422. return textureUnit;
  27423. }
  27424. this.allocTextureUnit = allocTextureUnit;
  27425. // this.setTexture2D = setTexture2D;
  27426. this.setTexture2D = ( function () {
  27427. var warned = false;
  27428. // backwards compatibility: peel texture.texture
  27429. return function setTexture2D( texture, slot ) {
  27430. if ( texture && texture.isWebGLRenderTarget ) {
  27431. if ( ! warned ) {
  27432. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  27433. warned = true;
  27434. }
  27435. texture = texture.texture;
  27436. }
  27437. textures.setTexture2D( texture, slot );
  27438. };
  27439. }() );
  27440. this.setTexture = ( function () {
  27441. var warned = false;
  27442. return function setTexture( texture, slot ) {
  27443. if ( ! warned ) {
  27444. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  27445. warned = true;
  27446. }
  27447. textures.setTexture2D( texture, slot );
  27448. };
  27449. }() );
  27450. this.setTextureCube = ( function () {
  27451. var warned = false;
  27452. return function setTextureCube( texture, slot ) {
  27453. // backwards compatibility: peel texture.texture
  27454. if ( texture && texture.isWebGLRenderTargetCube ) {
  27455. if ( ! warned ) {
  27456. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  27457. warned = true;
  27458. }
  27459. texture = texture.texture;
  27460. }
  27461. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  27462. // TODO: unify these code paths
  27463. if ( ( texture && texture.isCubeTexture ) ||
  27464. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  27465. // CompressedTexture can have Array in image :/
  27466. // this function alone should take care of cube textures
  27467. textures.setTextureCube( texture, slot );
  27468. } else {
  27469. // assumed: texture property of THREE.WebGLRenderTargetCube
  27470. textures.setTextureCubeDynamic( texture, slot );
  27471. }
  27472. };
  27473. }() );
  27474. this.getRenderTarget = function () {
  27475. return _currentRenderTarget;
  27476. };
  27477. this.setRenderTarget = function ( renderTarget ) {
  27478. _currentRenderTarget = renderTarget;
  27479. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  27480. textures.setupRenderTarget( renderTarget );
  27481. }
  27482. var framebuffer = null;
  27483. var isCube = false;
  27484. if ( renderTarget ) {
  27485. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  27486. if ( renderTarget.isWebGLRenderTargetCube ) {
  27487. framebuffer = __webglFramebuffer[ renderTarget.activeCubeFace ];
  27488. isCube = true;
  27489. } else {
  27490. framebuffer = __webglFramebuffer;
  27491. }
  27492. _currentViewport.copy( renderTarget.viewport );
  27493. _currentScissor.copy( renderTarget.scissor );
  27494. _currentScissorTest = renderTarget.scissorTest;
  27495. } else {
  27496. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  27497. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  27498. _currentScissorTest = _scissorTest;
  27499. }
  27500. if ( _currentFramebuffer !== framebuffer ) {
  27501. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  27502. _currentFramebuffer = framebuffer;
  27503. }
  27504. state.viewport( _currentViewport );
  27505. state.scissor( _currentScissor );
  27506. state.setScissorTest( _currentScissorTest );
  27507. if ( isCube ) {
  27508. var textureProperties = properties.get( renderTarget.texture );
  27509. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  27510. }
  27511. };
  27512. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  27513. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  27514. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  27515. return;
  27516. }
  27517. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  27518. if ( framebuffer ) {
  27519. var restore = false;
  27520. if ( framebuffer !== _currentFramebuffer ) {
  27521. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  27522. restore = true;
  27523. }
  27524. try {
  27525. var texture = renderTarget.texture;
  27526. var textureFormat = texture.format;
  27527. var textureType = texture.type;
  27528. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  27529. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  27530. return;
  27531. }
  27532. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  27533. ! ( textureType === FloatType && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  27534. ! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  27535. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  27536. return;
  27537. }
  27538. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  27539. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  27540. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  27541. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  27542. }
  27543. } else {
  27544. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  27545. }
  27546. } finally {
  27547. if ( restore ) {
  27548. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  27549. }
  27550. }
  27551. }
  27552. };
  27553. }
  27554. /**
  27555. * @author TristanVALCKE / https://github.com/Itee
  27556. * @author Anonymous
  27557. */
  27558. /* global QUnit */
  27559. // DEBUGGING
  27560. //
  27561. // HELPERS
  27562. //
  27563. function testEdges( vertList, idxList, numAfter, assert ) {
  27564. var geoms = createGeometries( vertList, idxList );
  27565. for ( var i = 0; i < geoms.length; i ++ ) {
  27566. var geom = geoms[ i ];
  27567. var numBefore = idxList.length;
  27568. assert.equal( countEdges( geom ), numBefore, "Edges before!" );
  27569. var egeom = new EdgesGeometry( geom );
  27570. assert.equal( countEdges( egeom ), numAfter, "Edges after!" );
  27571. output( geom, egeom );
  27572. }
  27573. }
  27574. function createGeometries( vertList, idxList ) {
  27575. var geomIB = createIndexedBufferGeometry( vertList, idxList );
  27576. var geom = new Geometry().fromBufferGeometry( geomIB );
  27577. var geomB = new BufferGeometry().fromGeometry( geom );
  27578. var geomDC = addDrawCalls( geomIB.clone() );
  27579. return [ geom, geomB, geomIB, geomDC ];
  27580. }
  27581. function createIndexedBufferGeometry( vertList, idxList ) {
  27582. var geom = new BufferGeometry();
  27583. var indexTable = [];
  27584. var numTris = idxList.length / 3;
  27585. var numVerts = 0;
  27586. var indices = new Uint32Array( numTris * 3 );
  27587. var vertices = new Float32Array( vertList.length * 3 );
  27588. for ( var i = 0; i < numTris; i ++ ) {
  27589. for ( var j = 0; j < 3; j ++ ) {
  27590. var idx = idxList[ 3 * i + j ];
  27591. if ( indexTable[ idx ] === undefined ) {
  27592. var v = vertList[ idx ];
  27593. vertices[ 3 * numVerts ] = v.x;
  27594. vertices[ 3 * numVerts + 1 ] = v.y;
  27595. vertices[ 3 * numVerts + 2 ] = v.z;
  27596. indexTable[ idx ] = numVerts;
  27597. numVerts ++;
  27598. }
  27599. indices[ 3 * i + j ] = indexTable[ idx ];
  27600. }
  27601. }
  27602. vertices = vertices.subarray( 0, 3 * numVerts );
  27603. geom.setIndex( new BufferAttribute( indices, 1 ) );
  27604. geom.addAttribute( 'position', new BufferAttribute( vertices, 3 ) );
  27605. geom.computeFaceNormals();
  27606. return geom;
  27607. }
  27608. function addDrawCalls( geometry ) {
  27609. var numTris = geometry.index.count / 3;
  27610. for ( var i = 0; i < numTris; i ++ ) {
  27611. var start = i * 3;
  27612. var count = 3;
  27613. geometry.addGroup( start, count );
  27614. }
  27615. return geometry;
  27616. }
  27617. function countEdges( geom ) {
  27618. if ( geom instanceof EdgesGeometry ) {
  27619. return geom.getAttribute( 'position' ).count / 2;
  27620. }
  27621. if ( geom.faces !== undefined ) {
  27622. return geom.faces.length * 3;
  27623. }
  27624. var indices = geom.index;
  27625. if ( indices ) {
  27626. return indices.count;
  27627. }
  27628. return geom.getAttribute( 'position' ).count;
  27629. }
  27630. //
  27631. // DEBUGGING
  27632. //
  27633. var DEBUG = false;
  27634. var renderer;
  27635. var camera;
  27636. var scene = new Scene();
  27637. var xoffset = 0;
  27638. function output( geom, egeom ) {
  27639. if ( DEBUG !== true ) return;
  27640. if ( ! renderer ) initDebug();
  27641. var mesh = new Mesh( geom, undefined );
  27642. var edges = new LineSegments( egeom, new LineBasicMaterial( { color: 'black' } ) );
  27643. mesh.position.setX( xoffset );
  27644. edges.position.setX( xoffset ++ );
  27645. scene.add( mesh );
  27646. scene.add( edges );
  27647. if ( scene.children.length % 8 === 0 ) {
  27648. xoffset += 2;
  27649. }
  27650. }
  27651. function initDebug() {
  27652. renderer = new WebGLRenderer( {
  27653. antialias: true
  27654. } );
  27655. var width = 600;
  27656. var height = 480;
  27657. renderer.setSize( width, height );
  27658. renderer.setClearColor( 0xCCCCCC );
  27659. camera = new PerspectiveCamera( 45, width / height, 1, 100 );
  27660. camera.position.x = 30;
  27661. camera.position.z = 40;
  27662. camera.lookAt( new Vector3( 30, 0, 0 ) );
  27663. document.body.appendChild( renderer.domElement );
  27664. var controls = new THREE.OrbitControls( camera, renderer.domElement ); // TODO: please do somethings for that -_-'
  27665. controls.target = new Vector3( 30, 0, 0 );
  27666. animate();
  27667. function animate() {
  27668. requestAnimationFrame( animate );
  27669. controls.update();
  27670. renderer.render( scene, camera );
  27671. }
  27672. }
  27673. QUnit.module( 'Geometries', () => {
  27674. QUnit.module.todo( 'EdgesGeometry', () => {
  27675. var vertList = [
  27676. new Vector3( 0, 0, 0 ),
  27677. new Vector3( 1, 0, 0 ),
  27678. new Vector3( 1, 1, 0 ),
  27679. new Vector3( 0, 1, 0 ),
  27680. new Vector3( 1, 1, 1 ),
  27681. ];
  27682. // INHERITANCE
  27683. QUnit.test( "Extending", ( assert ) => {
  27684. assert.ok( false, "everything's gonna be alright" );
  27685. } );
  27686. // INSTANCING
  27687. QUnit.test( "Instancing", ( assert ) => {
  27688. assert.ok( false, "everything's gonna be alright" );
  27689. } );
  27690. // OTHERS
  27691. QUnit.test( "singularity", ( assert ) => {
  27692. testEdges( vertList, [ 1, 1, 1 ], 0, assert );
  27693. } );
  27694. QUnit.test( "needle", ( assert ) => {
  27695. testEdges( vertList, [ 0, 0, 1 ], 0, assert );
  27696. } );
  27697. QUnit.test( "single triangle", ( assert ) => {
  27698. testEdges( vertList, [ 0, 1, 2 ], 3, assert );
  27699. } );
  27700. QUnit.test( "two isolated triangles", ( assert ) => {
  27701. var vertList = [
  27702. new Vector3( 0, 0, 0 ),
  27703. new Vector3( 1, 0, 0 ),
  27704. new Vector3( 1, 1, 0 ),
  27705. new Vector3( 0, 0, 1 ),
  27706. new Vector3( 1, 0, 1 ),
  27707. new Vector3( 1, 1, 1 ),
  27708. ];
  27709. testEdges( vertList, [ 0, 1, 2, 3, 4, 5 ], 6, assert );
  27710. } );
  27711. QUnit.test( "two flat triangles", ( assert ) => {
  27712. testEdges( vertList, [ 0, 1, 2, 0, 2, 3 ], 4, assert );
  27713. } );
  27714. QUnit.test( "two flat triangles, inverted", ( assert ) => {
  27715. testEdges( vertList, [ 0, 1, 2, 0, 3, 2 ], 5, assert );
  27716. } );
  27717. QUnit.test( "two non-coplanar triangles", ( assert ) => {
  27718. testEdges( vertList, [ 0, 1, 2, 0, 4, 2 ], 5, assert );
  27719. } );
  27720. QUnit.test( "three triangles, coplanar first", ( assert ) => {
  27721. testEdges( vertList, [ 0, 1, 2, 0, 2, 3, 0, 4, 2 ], 7, assert );
  27722. } );
  27723. QUnit.test( "three triangles, coplanar last", ( assert ) => {
  27724. testEdges( vertList, [ 0, 1, 2, 0, 4, 2, 0, 2, 3 ], 6, assert ); // Should be 7
  27725. } );
  27726. QUnit.test( "tetrahedron", ( assert ) => {
  27727. testEdges( vertList, [ 0, 1, 2, 0, 1, 4, 0, 4, 2, 1, 2, 4 ], 6, assert );
  27728. } );
  27729. } );
  27730. } );
  27731. /**
  27732. * @author zz85 / http://www.lab4games.net/zz85/blog
  27733. *
  27734. * Creates extruded geometry from a path shape.
  27735. *
  27736. * parameters = {
  27737. *
  27738. * curveSegments: <int>, // number of points on the curves
  27739. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  27740. * amount: <int>, // Depth to extrude the shape
  27741. *
  27742. * bevelEnabled: <bool>, // turn on bevel
  27743. * bevelThickness: <float>, // how deep into the original shape bevel goes
  27744. * bevelSize: <float>, // how far from shape outline is bevel
  27745. * bevelSegments: <int>, // number of bevel layers
  27746. *
  27747. * extrudePath: <THREE.Curve> // curve to extrude shape along
  27748. * frames: <Object> // containing arrays of tangents, normals, binormals
  27749. *
  27750. * UVGenerator: <Object> // object that provides UV generator functions
  27751. *
  27752. * }
  27753. */
  27754. // ExtrudeGeometry
  27755. function ExtrudeGeometry( shapes, options ) {
  27756. Geometry.call( this );
  27757. this.type = 'ExtrudeGeometry';
  27758. this.parameters = {
  27759. shapes: shapes,
  27760. options: options
  27761. };
  27762. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  27763. this.mergeVertices();
  27764. }
  27765. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  27766. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  27767. // ExtrudeBufferGeometry
  27768. function ExtrudeBufferGeometry( shapes, options ) {
  27769. if ( typeof ( shapes ) === "undefined" ) {
  27770. return;
  27771. }
  27772. BufferGeometry.call( this );
  27773. this.type = 'ExtrudeBufferGeometry';
  27774. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  27775. this.addShapeList( shapes, options );
  27776. this.computeVertexNormals();
  27777. // can't really use automatic vertex normals
  27778. // as then front and back sides get smoothed too
  27779. // should do separate smoothing just for sides
  27780. //this.computeVertexNormals();
  27781. //console.log( "took", ( Date.now() - startTime ) );
  27782. }
  27783. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  27784. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  27785. ExtrudeBufferGeometry.prototype.getArrays = function () {
  27786. var positionAttribute = this.getAttribute( "position" );
  27787. var verticesArray = positionAttribute ? Array.prototype.slice.call( positionAttribute.array ) : [];
  27788. var uvAttribute = this.getAttribute( "uv" );
  27789. var uvArray = uvAttribute ? Array.prototype.slice.call( uvAttribute.array ) : [];
  27790. var IndexAttribute = this.index;
  27791. var indicesArray = IndexAttribute ? Array.prototype.slice.call( IndexAttribute.array ) : [];
  27792. return {
  27793. position: verticesArray,
  27794. uv: uvArray,
  27795. index: indicesArray
  27796. };
  27797. };
  27798. ExtrudeBufferGeometry.prototype.addShapeList = function ( shapes, options ) {
  27799. var sl = shapes.length;
  27800. options.arrays = this.getArrays();
  27801. for ( var s = 0; s < sl; s ++ ) {
  27802. var shape = shapes[ s ];
  27803. this.addShape( shape, options );
  27804. }
  27805. this.setIndex( options.arrays.index );
  27806. this.addAttribute( 'position', new Float32BufferAttribute( options.arrays.position, 3 ) );
  27807. this.addAttribute( 'uv', new Float32BufferAttribute( options.arrays.uv, 2 ) );
  27808. };
  27809. ExtrudeBufferGeometry.prototype.addShape = function ( shape, options ) {
  27810. var arrays = options.arrays ? options.arrays : this.getArrays();
  27811. var verticesArray = arrays.position;
  27812. var indicesArray = arrays.index;
  27813. var uvArray = arrays.uv;
  27814. var placeholder = [];
  27815. var amount = options.amount !== undefined ? options.amount : 100;
  27816. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  27817. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  27818. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  27819. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  27820. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  27821. var steps = options.steps !== undefined ? options.steps : 1;
  27822. var extrudePath = options.extrudePath;
  27823. var extrudePts, extrudeByPath = false;
  27824. // Use default WorldUVGenerator if no UV generators are specified.
  27825. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : ExtrudeGeometry.WorldUVGenerator;
  27826. var splineTube, binormal, normal, position2;
  27827. if ( extrudePath ) {
  27828. extrudePts = extrudePath.getSpacedPoints( steps );
  27829. extrudeByPath = true;
  27830. bevelEnabled = false; // bevels not supported for path extrusion
  27831. // SETUP TNB variables
  27832. // TODO1 - have a .isClosed in spline?
  27833. splineTube = options.frames !== undefined ? options.frames : extrudePath.computeFrenetFrames( steps, false );
  27834. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  27835. binormal = new Vector3();
  27836. normal = new Vector3();
  27837. position2 = new Vector3();
  27838. }
  27839. // Safeguards if bevels are not enabled
  27840. if ( ! bevelEnabled ) {
  27841. bevelSegments = 0;
  27842. bevelThickness = 0;
  27843. bevelSize = 0;
  27844. }
  27845. // Variables initialization
  27846. var ahole, h, hl; // looping of holes
  27847. var scope = this;
  27848. var shapePoints = shape.extractPoints( curveSegments );
  27849. var vertices = shapePoints.shape;
  27850. var holes = shapePoints.holes;
  27851. var reverse = ! ShapeUtils.isClockWise( vertices );
  27852. if ( reverse ) {
  27853. vertices = vertices.reverse();
  27854. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  27855. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27856. ahole = holes[ h ];
  27857. if ( ShapeUtils.isClockWise( ahole ) ) {
  27858. holes[ h ] = ahole.reverse();
  27859. }
  27860. }
  27861. }
  27862. var faces = ShapeUtils.triangulateShape( vertices, holes );
  27863. /* Vertices */
  27864. var contour = vertices; // vertices has all points but contour has only points of circumference
  27865. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27866. ahole = holes[ h ];
  27867. vertices = vertices.concat( ahole );
  27868. }
  27869. function scalePt2( pt, vec, size ) {
  27870. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  27871. return vec.clone().multiplyScalar( size ).add( pt );
  27872. }
  27873. var b, bs, t, z,
  27874. vert, vlen = vertices.length,
  27875. face, flen = faces.length;
  27876. // Find directions for point movement
  27877. function getBevelVec( inPt, inPrev, inNext ) {
  27878. // computes for inPt the corresponding point inPt' on a new contour
  27879. // shifted by 1 unit (length of normalized vector) to the left
  27880. // if we walk along contour clockwise, this new contour is outside the old one
  27881. //
  27882. // inPt' is the intersection of the two lines parallel to the two
  27883. // adjacent edges of inPt at a distance of 1 unit on the left side.
  27884. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  27885. // good reading for geometry algorithms (here: line-line intersection)
  27886. // http://geomalgorithms.com/a05-_intersect-1.html
  27887. var v_prev_x = inPt.x - inPrev.x,
  27888. v_prev_y = inPt.y - inPrev.y;
  27889. var v_next_x = inNext.x - inPt.x,
  27890. v_next_y = inNext.y - inPt.y;
  27891. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  27892. // check for collinear edges
  27893. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  27894. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  27895. // not collinear
  27896. // length of vectors for normalizing
  27897. var v_prev_len = Math.sqrt( v_prev_lensq );
  27898. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  27899. // shift adjacent points by unit vectors to the left
  27900. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  27901. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  27902. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  27903. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  27904. // scaling factor for v_prev to intersection point
  27905. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  27906. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  27907. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  27908. // vector from inPt to intersection point
  27909. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  27910. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  27911. // Don't normalize!, otherwise sharp corners become ugly
  27912. // but prevent crazy spikes
  27913. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  27914. if ( v_trans_lensq <= 2 ) {
  27915. return new Vector2( v_trans_x, v_trans_y );
  27916. } else {
  27917. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  27918. }
  27919. } else {
  27920. // handle special case of collinear edges
  27921. var direction_eq = false; // assumes: opposite
  27922. if ( v_prev_x > Number.EPSILON ) {
  27923. if ( v_next_x > Number.EPSILON ) {
  27924. direction_eq = true;
  27925. }
  27926. } else {
  27927. if ( v_prev_x < - Number.EPSILON ) {
  27928. if ( v_next_x < - Number.EPSILON ) {
  27929. direction_eq = true;
  27930. }
  27931. } else {
  27932. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  27933. direction_eq = true;
  27934. }
  27935. }
  27936. }
  27937. if ( direction_eq ) {
  27938. // console.log("Warning: lines are a straight sequence");
  27939. v_trans_x = - v_prev_y;
  27940. v_trans_y = v_prev_x;
  27941. shrink_by = Math.sqrt( v_prev_lensq );
  27942. } else {
  27943. // console.log("Warning: lines are a straight spike");
  27944. v_trans_x = v_prev_x;
  27945. v_trans_y = v_prev_y;
  27946. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  27947. }
  27948. }
  27949. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  27950. }
  27951. var contourMovements = [];
  27952. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  27953. if ( j === il ) j = 0;
  27954. if ( k === il ) k = 0;
  27955. // (j)---(i)---(k)
  27956. // console.log('i,j,k', i, j , k)
  27957. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  27958. }
  27959. var holesMovements = [],
  27960. oneHoleMovements, verticesMovements = contourMovements.concat();
  27961. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27962. ahole = holes[ h ];
  27963. oneHoleMovements = [];
  27964. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  27965. if ( j === il ) j = 0;
  27966. if ( k === il ) k = 0;
  27967. // (j)---(i)---(k)
  27968. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  27969. }
  27970. holesMovements.push( oneHoleMovements );
  27971. verticesMovements = verticesMovements.concat( oneHoleMovements );
  27972. }
  27973. // Loop bevelSegments, 1 for the front, 1 for the back
  27974. for ( b = 0; b < bevelSegments; b ++ ) {
  27975. //for ( b = bevelSegments; b > 0; b -- ) {
  27976. t = b / bevelSegments;
  27977. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  27978. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  27979. // contract shape
  27980. for ( i = 0, il = contour.length; i < il; i ++ ) {
  27981. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  27982. v( vert.x, vert.y, - z );
  27983. }
  27984. // expand holes
  27985. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27986. ahole = holes[ h ];
  27987. oneHoleMovements = holesMovements[ h ];
  27988. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  27989. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  27990. v( vert.x, vert.y, - z );
  27991. }
  27992. }
  27993. }
  27994. bs = bevelSize;
  27995. // Back facing vertices
  27996. for ( i = 0; i < vlen; i ++ ) {
  27997. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  27998. if ( ! extrudeByPath ) {
  27999. v( vert.x, vert.y, 0 );
  28000. } else {
  28001. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  28002. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  28003. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  28004. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  28005. v( position2.x, position2.y, position2.z );
  28006. }
  28007. }
  28008. // Add stepped vertices...
  28009. // Including front facing vertices
  28010. var s;
  28011. for ( s = 1; s <= steps; s ++ ) {
  28012. for ( i = 0; i < vlen; i ++ ) {
  28013. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  28014. if ( ! extrudeByPath ) {
  28015. v( vert.x, vert.y, amount / steps * s );
  28016. } else {
  28017. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  28018. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  28019. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  28020. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  28021. v( position2.x, position2.y, position2.z );
  28022. }
  28023. }
  28024. }
  28025. // Add bevel segments planes
  28026. //for ( b = 1; b <= bevelSegments; b ++ ) {
  28027. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  28028. t = b / bevelSegments;
  28029. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  28030. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  28031. // contract shape
  28032. for ( i = 0, il = contour.length; i < il; i ++ ) {
  28033. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  28034. v( vert.x, vert.y, amount + z );
  28035. }
  28036. // expand holes
  28037. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  28038. ahole = holes[ h ];
  28039. oneHoleMovements = holesMovements[ h ];
  28040. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  28041. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  28042. if ( ! extrudeByPath ) {
  28043. v( vert.x, vert.y, amount + z );
  28044. } else {
  28045. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  28046. }
  28047. }
  28048. }
  28049. }
  28050. /* Faces */
  28051. // Top and bottom faces
  28052. buildLidFaces();
  28053. // Sides faces
  28054. buildSideFaces();
  28055. ///// Internal functions
  28056. function buildLidFaces() {
  28057. var start = verticesArray.length / 3;
  28058. if ( bevelEnabled ) {
  28059. var layer = 0; // steps + 1
  28060. var offset = vlen * layer;
  28061. // Bottom faces
  28062. for ( i = 0; i < flen; i ++ ) {
  28063. face = faces[ i ];
  28064. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  28065. }
  28066. layer = steps + bevelSegments * 2;
  28067. offset = vlen * layer;
  28068. // Top faces
  28069. for ( i = 0; i < flen; i ++ ) {
  28070. face = faces[ i ];
  28071. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  28072. }
  28073. } else {
  28074. // Bottom faces
  28075. for ( i = 0; i < flen; i ++ ) {
  28076. face = faces[ i ];
  28077. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  28078. }
  28079. // Top faces
  28080. for ( i = 0; i < flen; i ++ ) {
  28081. face = faces[ i ];
  28082. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  28083. }
  28084. }
  28085. scope.addGroup( start, verticesArray.length / 3 - start, options.material !== undefined ? options.material : 0 );
  28086. }
  28087. // Create faces for the z-sides of the shape
  28088. function buildSideFaces() {
  28089. var start = verticesArray.length / 3;
  28090. var layeroffset = 0;
  28091. sidewalls( contour, layeroffset );
  28092. layeroffset += contour.length;
  28093. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  28094. ahole = holes[ h ];
  28095. sidewalls( ahole, layeroffset );
  28096. //, true
  28097. layeroffset += ahole.length;
  28098. }
  28099. scope.addGroup( start, verticesArray.length / 3 - start, options.extrudeMaterial !== undefined ? options.extrudeMaterial : 1 );
  28100. }
  28101. function sidewalls( contour, layeroffset ) {
  28102. var j, k;
  28103. i = contour.length;
  28104. while ( -- i >= 0 ) {
  28105. j = i;
  28106. k = i - 1;
  28107. if ( k < 0 ) k = contour.length - 1;
  28108. //console.log('b', i,j, i-1, k,vertices.length);
  28109. var s = 0,
  28110. sl = steps + bevelSegments * 2;
  28111. for ( s = 0; s < sl; s ++ ) {
  28112. var slen1 = vlen * s;
  28113. var slen2 = vlen * ( s + 1 );
  28114. var a = layeroffset + j + slen1,
  28115. b = layeroffset + k + slen1,
  28116. c = layeroffset + k + slen2,
  28117. d = layeroffset + j + slen2;
  28118. f4( a, b, c, d );
  28119. }
  28120. }
  28121. }
  28122. function v( x, y, z ) {
  28123. placeholder.push( x );
  28124. placeholder.push( y );
  28125. placeholder.push( z );
  28126. }
  28127. function f3( a, b, c ) {
  28128. addVertex( a );
  28129. addVertex( b );
  28130. addVertex( c );
  28131. var nextIndex = verticesArray.length / 3;
  28132. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  28133. addUV( uvs[ 0 ] );
  28134. addUV( uvs[ 1 ] );
  28135. addUV( uvs[ 2 ] );
  28136. }
  28137. function f4( a, b, c, d ) {
  28138. addVertex( a );
  28139. addVertex( b );
  28140. addVertex( d );
  28141. addVertex( b );
  28142. addVertex( c );
  28143. addVertex( d );
  28144. var nextIndex = verticesArray.length / 3;
  28145. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  28146. addUV( uvs[ 0 ] );
  28147. addUV( uvs[ 1 ] );
  28148. addUV( uvs[ 3 ] );
  28149. addUV( uvs[ 1 ] );
  28150. addUV( uvs[ 2 ] );
  28151. addUV( uvs[ 3 ] );
  28152. }
  28153. function addVertex( index ) {
  28154. indicesArray.push( verticesArray.length / 3 );
  28155. verticesArray.push( placeholder[ index * 3 + 0 ] );
  28156. verticesArray.push( placeholder[ index * 3 + 1 ] );
  28157. verticesArray.push( placeholder[ index * 3 + 2 ] );
  28158. }
  28159. function addUV( vector2 ) {
  28160. uvArray.push( vector2.x );
  28161. uvArray.push( vector2.y );
  28162. }
  28163. if ( ! options.arrays ) {
  28164. this.setIndex( indicesArray );
  28165. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  28166. this.addAttribute( 'uv', new Float32BufferAttribute( options.arrays.uv, 2 ) );
  28167. }
  28168. };
  28169. ExtrudeGeometry.WorldUVGenerator = {
  28170. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  28171. var a_x = vertices[ indexA * 3 ];
  28172. var a_y = vertices[ indexA * 3 + 1 ];
  28173. var b_x = vertices[ indexB * 3 ];
  28174. var b_y = vertices[ indexB * 3 + 1 ];
  28175. var c_x = vertices[ indexC * 3 ];
  28176. var c_y = vertices[ indexC * 3 + 1 ];
  28177. return [
  28178. new Vector2( a_x, a_y ),
  28179. new Vector2( b_x, b_y ),
  28180. new Vector2( c_x, c_y )
  28181. ];
  28182. },
  28183. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  28184. var a_x = vertices[ indexA * 3 ];
  28185. var a_y = vertices[ indexA * 3 + 1 ];
  28186. var a_z = vertices[ indexA * 3 + 2 ];
  28187. var b_x = vertices[ indexB * 3 ];
  28188. var b_y = vertices[ indexB * 3 + 1 ];
  28189. var b_z = vertices[ indexB * 3 + 2 ];
  28190. var c_x = vertices[ indexC * 3 ];
  28191. var c_y = vertices[ indexC * 3 + 1 ];
  28192. var c_z = vertices[ indexC * 3 + 2 ];
  28193. var d_x = vertices[ indexD * 3 ];
  28194. var d_y = vertices[ indexD * 3 + 1 ];
  28195. var d_z = vertices[ indexD * 3 + 2 ];
  28196. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  28197. return [
  28198. new Vector2( a_x, 1 - a_z ),
  28199. new Vector2( b_x, 1 - b_z ),
  28200. new Vector2( c_x, 1 - c_z ),
  28201. new Vector2( d_x, 1 - d_z )
  28202. ];
  28203. } else {
  28204. return [
  28205. new Vector2( a_y, 1 - a_z ),
  28206. new Vector2( b_y, 1 - b_z ),
  28207. new Vector2( c_y, 1 - c_z ),
  28208. new Vector2( d_y, 1 - d_z )
  28209. ];
  28210. }
  28211. }
  28212. };
  28213. /**
  28214. * @author TristanVALCKE / https://github.com/Itee
  28215. */
  28216. /* global QUnit */
  28217. QUnit.module( 'Geometries', () => {
  28218. QUnit.module.todo( 'ExtrudeGeometry', () => {
  28219. // INHERITANCE
  28220. QUnit.test( "Extending", ( assert ) => {
  28221. assert.ok( false, "everything's gonna be alright" );
  28222. } );
  28223. // INSTANCING
  28224. QUnit.test( "Instancing", ( assert ) => {
  28225. assert.ok( false, "everything's gonna be alright" );
  28226. } );
  28227. } );
  28228. QUnit.module.todo( 'ExtrudeBufferGeometry', () => {
  28229. // INHERITANCE
  28230. QUnit.test( "Extending", ( assert ) => {
  28231. assert.ok( false, "everything's gonna be alright" );
  28232. } );
  28233. // INSTANCING
  28234. QUnit.test( "Instancing", ( assert ) => {
  28235. assert.ok( false, "everything's gonna be alright" );
  28236. } );
  28237. // STATIC STUFF
  28238. QUnit.test( "WorldUVGenerator.generateTopUV", ( assert ) => {
  28239. assert.ok( false, "everything's gonna be alright" );
  28240. } );
  28241. QUnit.test( "WorldUVGenerator.generateSideWallUV", ( assert ) => {
  28242. assert.ok( false, "everything's gonna be alright" );
  28243. } );
  28244. // OTHERS
  28245. QUnit.test( "getArrays", ( assert ) => {
  28246. assert.ok( false, "everything's gonna be alright" );
  28247. } );
  28248. QUnit.test( "addShapeList", ( assert ) => {
  28249. assert.ok( false, "everything's gonna be alright" );
  28250. } );
  28251. QUnit.test( "addShape", ( assert ) => {
  28252. assert.ok( false, "everything's gonna be alright" );
  28253. } );
  28254. } );
  28255. } );
  28256. /**
  28257. * @author timothypratley / https://github.com/timothypratley
  28258. * @author Mugen87 / https://github.com/Mugen87
  28259. */
  28260. // IcosahedronGeometry
  28261. function IcosahedronGeometry( radius, detail ) {
  28262. Geometry.call( this );
  28263. this.type = 'IcosahedronGeometry';
  28264. this.parameters = {
  28265. radius: radius,
  28266. detail: detail
  28267. };
  28268. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  28269. this.mergeVertices();
  28270. }
  28271. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  28272. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  28273. // IcosahedronBufferGeometry
  28274. function IcosahedronBufferGeometry( radius, detail ) {
  28275. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  28276. var vertices = [
  28277. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  28278. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  28279. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  28280. ];
  28281. var indices = [
  28282. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  28283. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  28284. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  28285. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  28286. ];
  28287. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  28288. this.type = 'IcosahedronBufferGeometry';
  28289. this.parameters = {
  28290. radius: radius,
  28291. detail: detail
  28292. };
  28293. }
  28294. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  28295. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  28296. /**
  28297. * @author TristanVALCKE / https://github.com/Itee
  28298. * @author Anonymous
  28299. */
  28300. /* global QUnit */
  28301. QUnit.module( 'Geometries', () => {
  28302. QUnit.module.todo( 'IcosahedronGeometry', ( hooks ) => {
  28303. var geometries = undefined;
  28304. hooks.beforeEach( function () {
  28305. const parameters = {
  28306. radius: 10,
  28307. detail: undefined
  28308. };
  28309. geometries = [
  28310. new IcosahedronGeometry(),
  28311. new IcosahedronGeometry( parameters.radius ),
  28312. new IcosahedronGeometry( parameters.radius, parameters.detail ),
  28313. ];
  28314. } );
  28315. // INHERITANCE
  28316. QUnit.test( "Extending", ( assert ) => {
  28317. assert.ok( false, "everything's gonna be alright" );
  28318. } );
  28319. // INSTANCING
  28320. QUnit.test( "Instancing", ( assert ) => {
  28321. assert.ok( false, "everything's gonna be alright" );
  28322. } );
  28323. // OTHERS
  28324. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28325. runStdGeometryTests( assert, geometries );
  28326. } );
  28327. } );
  28328. QUnit.module.todo( 'IcosahedronBufferGeometry', ( hooks ) => {
  28329. var geometries = undefined;
  28330. hooks.beforeEach( function () {
  28331. const parameters = {
  28332. radius: 10,
  28333. detail: undefined
  28334. };
  28335. geometries = [
  28336. new IcosahedronBufferGeometry(),
  28337. new IcosahedronBufferGeometry( parameters.radius ),
  28338. new IcosahedronBufferGeometry( parameters.radius, parameters.detail ),
  28339. ];
  28340. } );
  28341. // INHERITANCE
  28342. QUnit.test( "Extending", ( assert ) => {
  28343. assert.ok( false, "everything's gonna be alright" );
  28344. } );
  28345. // INSTANCING
  28346. QUnit.test( "Instancing", ( assert ) => {
  28347. assert.ok( false, "everything's gonna be alright" );
  28348. } );
  28349. // OTHERS
  28350. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28351. runStdGeometryTests( assert, geometries );
  28352. } );
  28353. } );
  28354. } );
  28355. /**
  28356. * @author astrodud / http://astrodud.isgreat.org/
  28357. * @author zz85 / https://github.com/zz85
  28358. * @author bhouston / http://clara.io
  28359. * @author Mugen87 / https://github.com/Mugen87
  28360. */
  28361. // LatheGeometry
  28362. function LatheGeometry( points, segments, phiStart, phiLength ) {
  28363. Geometry.call( this );
  28364. this.type = 'LatheGeometry';
  28365. this.parameters = {
  28366. points: points,
  28367. segments: segments,
  28368. phiStart: phiStart,
  28369. phiLength: phiLength
  28370. };
  28371. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  28372. this.mergeVertices();
  28373. }
  28374. LatheGeometry.prototype = Object.create( Geometry.prototype );
  28375. LatheGeometry.prototype.constructor = LatheGeometry;
  28376. // LatheBufferGeometry
  28377. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  28378. BufferGeometry.call( this );
  28379. this.type = 'LatheBufferGeometry';
  28380. this.parameters = {
  28381. points: points,
  28382. segments: segments,
  28383. phiStart: phiStart,
  28384. phiLength: phiLength
  28385. };
  28386. segments = Math.floor( segments ) || 12;
  28387. phiStart = phiStart || 0;
  28388. phiLength = phiLength || Math.PI * 2;
  28389. // clamp phiLength so it's in range of [ 0, 2PI ]
  28390. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  28391. // buffers
  28392. var indices = [];
  28393. var vertices = [];
  28394. var uvs = [];
  28395. // helper variables
  28396. var base;
  28397. var inverseSegments = 1.0 / segments;
  28398. var vertex = new Vector3();
  28399. var uv = new Vector2();
  28400. var i, j;
  28401. // generate vertices and uvs
  28402. for ( i = 0; i <= segments; i ++ ) {
  28403. var phi = phiStart + i * inverseSegments * phiLength;
  28404. var sin = Math.sin( phi );
  28405. var cos = Math.cos( phi );
  28406. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  28407. // vertex
  28408. vertex.x = points[ j ].x * sin;
  28409. vertex.y = points[ j ].y;
  28410. vertex.z = points[ j ].x * cos;
  28411. vertices.push( vertex.x, vertex.y, vertex.z );
  28412. // uv
  28413. uv.x = i / segments;
  28414. uv.y = j / ( points.length - 1 );
  28415. uvs.push( uv.x, uv.y );
  28416. }
  28417. }
  28418. // indices
  28419. for ( i = 0; i < segments; i ++ ) {
  28420. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  28421. base = j + i * points.length;
  28422. var a = base;
  28423. var b = base + points.length;
  28424. var c = base + points.length + 1;
  28425. var d = base + 1;
  28426. // faces
  28427. indices.push( a, b, d );
  28428. indices.push( b, c, d );
  28429. }
  28430. }
  28431. // build geometry
  28432. this.setIndex( indices );
  28433. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28434. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  28435. // generate normals
  28436. this.computeVertexNormals();
  28437. // if the geometry is closed, we need to average the normals along the seam.
  28438. // because the corresponding vertices are identical (but still have different UVs).
  28439. if ( phiLength === Math.PI * 2 ) {
  28440. var normals = this.attributes.normal.array;
  28441. var n1 = new Vector3();
  28442. var n2 = new Vector3();
  28443. var n = new Vector3();
  28444. // this is the buffer offset for the last line of vertices
  28445. base = segments * points.length * 3;
  28446. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  28447. // select the normal of the vertex in the first line
  28448. n1.x = normals[ j + 0 ];
  28449. n1.y = normals[ j + 1 ];
  28450. n1.z = normals[ j + 2 ];
  28451. // select the normal of the vertex in the last line
  28452. n2.x = normals[ base + j + 0 ];
  28453. n2.y = normals[ base + j + 1 ];
  28454. n2.z = normals[ base + j + 2 ];
  28455. // average normals
  28456. n.addVectors( n1, n2 ).normalize();
  28457. // assign the new values to both normals
  28458. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  28459. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  28460. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  28461. }
  28462. }
  28463. }
  28464. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  28465. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  28466. /**
  28467. * @author TristanVALCKE / https://github.com/Itee
  28468. */
  28469. /* global QUnit */
  28470. QUnit.module( 'Geometries', () => {
  28471. QUnit.module.todo( 'LatheGeometry', ( hooks ) => {
  28472. var geometries = undefined;
  28473. hooks.beforeEach( function () {
  28474. const parameters = {
  28475. points: [],
  28476. segments: 0,
  28477. phiStart: 0,
  28478. phiLength: 0
  28479. };
  28480. geometries = [
  28481. // new LatheGeometry(), // Todo: error for undefined point
  28482. new LatheGeometry( parameters.points )
  28483. ];
  28484. } );
  28485. // INHERITANCE
  28486. QUnit.test( "Extending", ( assert ) => {
  28487. assert.ok( false, "everything's gonna be alright" );
  28488. } );
  28489. // INSTANCING
  28490. QUnit.test( "Instancing", ( assert ) => {
  28491. assert.ok( false, "everything's gonna be alright" );
  28492. } );
  28493. // OTHERS
  28494. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28495. runStdGeometryTests( assert, geometries );
  28496. } );
  28497. } );
  28498. QUnit.module.todo( 'LatheBufferGeometry', ( hooks ) => {
  28499. var geometries = undefined;
  28500. hooks.beforeEach( function () {
  28501. const parameters = {
  28502. points: [],
  28503. segments: 0,
  28504. phiStart: 0,
  28505. phiLength: 0
  28506. };
  28507. geometries = [
  28508. // new LatheBufferGeometry(), // Todo: error for undefined point
  28509. new LatheBufferGeometry( parameters.points )
  28510. ];
  28511. } );
  28512. // INHERITANCE
  28513. QUnit.test( "Extending", ( assert ) => {
  28514. assert.ok( false, "everything's gonna be alright" );
  28515. } );
  28516. // INSTANCING
  28517. QUnit.test( "Instancing", ( assert ) => {
  28518. assert.ok( false, "everything's gonna be alright" );
  28519. } );
  28520. // OTHERS
  28521. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28522. runStdGeometryTests( assert, geometries );
  28523. } );
  28524. } );
  28525. } );
  28526. /**
  28527. * @author timothypratley / https://github.com/timothypratley
  28528. * @author Mugen87 / https://github.com/Mugen87
  28529. */
  28530. // OctahedronGeometry
  28531. function OctahedronGeometry( radius, detail ) {
  28532. Geometry.call( this );
  28533. this.type = 'OctahedronGeometry';
  28534. this.parameters = {
  28535. radius: radius,
  28536. detail: detail
  28537. };
  28538. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  28539. this.mergeVertices();
  28540. }
  28541. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  28542. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  28543. // OctahedronBufferGeometry
  28544. function OctahedronBufferGeometry( radius, detail ) {
  28545. var vertices = [
  28546. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  28547. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  28548. ];
  28549. var indices = [
  28550. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  28551. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  28552. 1, 3, 4, 1, 4, 2
  28553. ];
  28554. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  28555. this.type = 'OctahedronBufferGeometry';
  28556. this.parameters = {
  28557. radius: radius,
  28558. detail: detail
  28559. };
  28560. }
  28561. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  28562. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  28563. /**
  28564. * @author TristanVALCKE / https://github.com/Itee
  28565. * @author Anonymous
  28566. */
  28567. /* global QUnit */
  28568. QUnit.module( 'Geometries', () => {
  28569. QUnit.module.todo( 'OctahedronGeometry', ( hooks ) => {
  28570. var geometries = undefined;
  28571. hooks.beforeEach( function () {
  28572. const parameters = {
  28573. radius: 10,
  28574. detail: undefined
  28575. };
  28576. geometries = [
  28577. new OctahedronGeometry(),
  28578. new OctahedronGeometry( parameters.radius ),
  28579. new OctahedronGeometry( parameters.radius, parameters.detail ),
  28580. ];
  28581. } );
  28582. // INHERITANCE
  28583. QUnit.test( "Extending", ( assert ) => {
  28584. assert.ok( false, "everything's gonna be alright" );
  28585. } );
  28586. // INSTANCING
  28587. QUnit.test( "Instancing", ( assert ) => {
  28588. assert.ok( false, "everything's gonna be alright" );
  28589. } );
  28590. // OTHERS
  28591. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28592. runStdGeometryTests( assert, geometries );
  28593. } );
  28594. } );
  28595. QUnit.module.todo( 'OctahedronBufferGeometry', ( hooks ) => {
  28596. var geometries = undefined;
  28597. hooks.beforeEach( function () {
  28598. const parameters = {
  28599. radius: 10,
  28600. detail: undefined
  28601. };
  28602. geometries = [
  28603. new OctahedronBufferGeometry(),
  28604. new OctahedronBufferGeometry( parameters.radius ),
  28605. new OctahedronBufferGeometry( parameters.radius, parameters.detail ),
  28606. ];
  28607. } );
  28608. // INHERITANCE
  28609. QUnit.test( "Extending", ( assert ) => {
  28610. assert.ok( false, "everything's gonna be alright" );
  28611. } );
  28612. // INSTANCING
  28613. QUnit.test( "Instancing", ( assert ) => {
  28614. assert.ok( false, "everything's gonna be alright" );
  28615. } );
  28616. // OTHERS
  28617. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28618. runStdGeometryTests( assert, geometries );
  28619. } );
  28620. } );
  28621. } );
  28622. /**
  28623. * @author zz85 / https://github.com/zz85
  28624. * @author Mugen87 / https://github.com/Mugen87
  28625. *
  28626. * Parametric Surfaces Geometry
  28627. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  28628. */
  28629. // ParametricGeometry
  28630. function ParametricGeometry( func, slices, stacks ) {
  28631. Geometry.call( this );
  28632. this.type = 'ParametricGeometry';
  28633. this.parameters = {
  28634. func: func,
  28635. slices: slices,
  28636. stacks: stacks
  28637. };
  28638. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  28639. this.mergeVertices();
  28640. }
  28641. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  28642. ParametricGeometry.prototype.constructor = ParametricGeometry;
  28643. // ParametricBufferGeometry
  28644. function ParametricBufferGeometry( func, slices, stacks ) {
  28645. BufferGeometry.call( this );
  28646. this.type = 'ParametricBufferGeometry';
  28647. this.parameters = {
  28648. func: func,
  28649. slices: slices,
  28650. stacks: stacks
  28651. };
  28652. // buffers
  28653. var indices = [];
  28654. var vertices = [];
  28655. var normals = [];
  28656. var uvs = [];
  28657. var EPS = 0.00001;
  28658. var normal = new Vector3();
  28659. var p0 = new Vector3(), p1 = new Vector3();
  28660. var pu = new Vector3(), pv = new Vector3();
  28661. var i, j;
  28662. // generate vertices, normals and uvs
  28663. var sliceCount = slices + 1;
  28664. for ( i = 0; i <= stacks; i ++ ) {
  28665. var v = i / stacks;
  28666. for ( j = 0; j <= slices; j ++ ) {
  28667. var u = j / slices;
  28668. // vertex
  28669. p0 = func( u, v, p0 );
  28670. vertices.push( p0.x, p0.y, p0.z );
  28671. // normal
  28672. // approximate tangent vectors via finite differences
  28673. if ( u - EPS >= 0 ) {
  28674. p1 = func( u - EPS, v, p1 );
  28675. pu.subVectors( p0, p1 );
  28676. } else {
  28677. p1 = func( u + EPS, v, p1 );
  28678. pu.subVectors( p1, p0 );
  28679. }
  28680. if ( v - EPS >= 0 ) {
  28681. p1 = func( u, v - EPS, p1 );
  28682. pv.subVectors( p0, p1 );
  28683. } else {
  28684. p1 = func( u, v + EPS, p1 );
  28685. pv.subVectors( p1, p0 );
  28686. }
  28687. // cross product of tangent vectors returns surface normal
  28688. normal.crossVectors( pu, pv ).normalize();
  28689. normals.push( normal.x, normal.y, normal.z );
  28690. // uv
  28691. uvs.push( u, v );
  28692. }
  28693. }
  28694. // generate indices
  28695. for ( i = 0; i < stacks; i ++ ) {
  28696. for ( j = 0; j < slices; j ++ ) {
  28697. var a = i * sliceCount + j;
  28698. var b = i * sliceCount + j + 1;
  28699. var c = ( i + 1 ) * sliceCount + j + 1;
  28700. var d = ( i + 1 ) * sliceCount + j;
  28701. // faces one and two
  28702. indices.push( a, b, d );
  28703. indices.push( b, c, d );
  28704. }
  28705. }
  28706. // build geometry
  28707. this.setIndex( indices );
  28708. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28709. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  28710. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  28711. }
  28712. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  28713. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  28714. /**
  28715. * @author TristanVALCKE / https://github.com/Itee
  28716. */
  28717. /* global QUnit */
  28718. QUnit.module( 'Geometries', () => {
  28719. QUnit.module.todo( 'ParametricGeometry', ( hooks ) => {
  28720. var geometries = undefined;
  28721. hooks.beforeEach( function () {
  28722. const parameters = {};
  28723. geometries = [
  28724. new ParametricGeometry()
  28725. ];
  28726. } );
  28727. // INHERITANCE
  28728. QUnit.test( "Extending", ( assert ) => {
  28729. assert.ok( false, "everything's gonna be alright" );
  28730. } );
  28731. // INSTANCING
  28732. QUnit.test( "Instancing", ( assert ) => {
  28733. assert.ok( false, "everything's gonna be alright" );
  28734. } );
  28735. // OTHERS
  28736. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28737. runStdGeometryTests( assert, geometries );
  28738. } );
  28739. } );
  28740. QUnit.module.todo( 'ParametricBufferGeometry', ( hooks ) => {
  28741. var geometries = undefined;
  28742. hooks.beforeEach( function () {
  28743. const parameters = {};
  28744. geometries = [
  28745. new ParametricBufferGeometry()
  28746. ];
  28747. } );
  28748. // INHERITANCE
  28749. QUnit.test( "Extending", ( assert ) => {
  28750. assert.ok( false, "everything's gonna be alright" );
  28751. } );
  28752. // INSTANCING
  28753. QUnit.test( "Instancing", ( assert ) => {
  28754. assert.ok( false, "everything's gonna be alright" );
  28755. } );
  28756. // OTHERS
  28757. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28758. runStdGeometryTests( assert, geometries );
  28759. } );
  28760. } );
  28761. } );
  28762. /**
  28763. * @author TristanVALCKE / https://github.com/Itee
  28764. * @author Anonymous
  28765. */
  28766. /* global QUnit */
  28767. QUnit.module( 'Geometries', () => {
  28768. QUnit.module.todo( 'PlaneGeometry', ( hooks ) => {
  28769. var geometries = undefined;
  28770. hooks.beforeEach( function () {
  28771. const parameters = {
  28772. width: 10,
  28773. height: 30,
  28774. widthSegments: 3,
  28775. heightSegments: 5
  28776. };
  28777. geometries = [
  28778. new PlaneGeometry(),
  28779. new PlaneGeometry( parameters.width ),
  28780. new PlaneGeometry( parameters.width, parameters.height ),
  28781. new PlaneGeometry( parameters.width, parameters.height, parameters.widthSegments ),
  28782. new PlaneGeometry( parameters.width, parameters.height, parameters.widthSegments, parameters.heightSegments ),
  28783. ];
  28784. } );
  28785. // INHERITANCE
  28786. QUnit.test( "Extending", ( assert ) => {
  28787. assert.ok( false, "everything's gonna be alright" );
  28788. } );
  28789. // INSTANCING
  28790. QUnit.test( "Instancing", ( assert ) => {
  28791. assert.ok( false, "everything's gonna be alright" );
  28792. } );
  28793. // OTHERS
  28794. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28795. runStdGeometryTests( assert, geometries );
  28796. } );
  28797. } );
  28798. QUnit.module.todo( 'PlaneBufferGeometry', ( hooks ) => {
  28799. var geometries = undefined;
  28800. hooks.beforeEach( function () {
  28801. const parameters = {
  28802. width: 10,
  28803. height: 30,
  28804. widthSegments: 3,
  28805. heightSegments: 5
  28806. };
  28807. geometries = [
  28808. new PlaneBufferGeometry(),
  28809. new PlaneBufferGeometry( parameters.width ),
  28810. new PlaneBufferGeometry( parameters.width, parameters.height ),
  28811. new PlaneBufferGeometry( parameters.width, parameters.height, parameters.widthSegments ),
  28812. new PlaneBufferGeometry( parameters.width, parameters.height, parameters.widthSegments, parameters.heightSegments ),
  28813. ];
  28814. } );
  28815. // INHERITANCE
  28816. QUnit.test( "Extending", ( assert ) => {
  28817. assert.ok( false, "everything's gonna be alright" );
  28818. } );
  28819. // INSTANCING
  28820. QUnit.test( "Instancing", ( assert ) => {
  28821. assert.ok( false, "everything's gonna be alright" );
  28822. } );
  28823. // OTHERS
  28824. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28825. runStdGeometryTests( assert, geometries );
  28826. } );
  28827. } );
  28828. } );
  28829. /**
  28830. * @author TristanVALCKE / https://github.com/Itee
  28831. */
  28832. /* global QUnit */
  28833. QUnit.module( 'Geometries', () => {
  28834. QUnit.module.todo( 'PolyhedronGeometry', ( hooks ) => {
  28835. var geometries = undefined;
  28836. hooks.beforeEach( function () {
  28837. const parameters = {};
  28838. geometries = [
  28839. new PolyhedronGeometry()
  28840. ];
  28841. } );
  28842. // INHERITANCE
  28843. QUnit.test( "Extending", ( assert ) => {
  28844. assert.ok( false, "everything's gonna be alright" );
  28845. } );
  28846. // INSTANCING
  28847. QUnit.test( "Instancing", ( assert ) => {
  28848. assert.ok( false, "everything's gonna be alright" );
  28849. } );
  28850. // OTHERS
  28851. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28852. runStdGeometryTests( assert, geometries );
  28853. } );
  28854. } );
  28855. QUnit.module.todo( 'PolyhedronBufferGeometry', ( hooks ) => {
  28856. var geometries = undefined;
  28857. hooks.beforeEach( function () {
  28858. const parameters = {};
  28859. geometries = [
  28860. new PolyhedronBufferGeometry()
  28861. ];
  28862. } );
  28863. // INHERITANCE
  28864. QUnit.test( "Extending", ( assert ) => {
  28865. assert.ok( false, "everything's gonna be alright" );
  28866. } );
  28867. // INSTANCING
  28868. QUnit.test( "Instancing", ( assert ) => {
  28869. assert.ok( false, "everything's gonna be alright" );
  28870. } );
  28871. // OTHERS
  28872. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28873. runStdGeometryTests( assert, geometries );
  28874. } );
  28875. } );
  28876. } );
  28877. /**
  28878. * @author Kaleb Murphy
  28879. * @author Mugen87 / https://github.com/Mugen87
  28880. */
  28881. // RingGeometry
  28882. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  28883. Geometry.call( this );
  28884. this.type = 'RingGeometry';
  28885. this.parameters = {
  28886. innerRadius: innerRadius,
  28887. outerRadius: outerRadius,
  28888. thetaSegments: thetaSegments,
  28889. phiSegments: phiSegments,
  28890. thetaStart: thetaStart,
  28891. thetaLength: thetaLength
  28892. };
  28893. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  28894. this.mergeVertices();
  28895. }
  28896. RingGeometry.prototype = Object.create( Geometry.prototype );
  28897. RingGeometry.prototype.constructor = RingGeometry;
  28898. // RingBufferGeometry
  28899. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  28900. BufferGeometry.call( this );
  28901. this.type = 'RingBufferGeometry';
  28902. this.parameters = {
  28903. innerRadius: innerRadius,
  28904. outerRadius: outerRadius,
  28905. thetaSegments: thetaSegments,
  28906. phiSegments: phiSegments,
  28907. thetaStart: thetaStart,
  28908. thetaLength: thetaLength
  28909. };
  28910. innerRadius = innerRadius || 0.5;
  28911. outerRadius = outerRadius || 1;
  28912. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  28913. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  28914. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  28915. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  28916. // buffers
  28917. var indices = [];
  28918. var vertices = [];
  28919. var normals = [];
  28920. var uvs = [];
  28921. // some helper variables
  28922. var segment;
  28923. var radius = innerRadius;
  28924. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  28925. var vertex = new Vector3();
  28926. var uv = new Vector2();
  28927. var j, i;
  28928. // generate vertices, normals and uvs
  28929. for ( j = 0; j <= phiSegments; j ++ ) {
  28930. for ( i = 0; i <= thetaSegments; i ++ ) {
  28931. // values are generate from the inside of the ring to the outside
  28932. segment = thetaStart + i / thetaSegments * thetaLength;
  28933. // vertex
  28934. vertex.x = radius * Math.cos( segment );
  28935. vertex.y = radius * Math.sin( segment );
  28936. vertices.push( vertex.x, vertex.y, vertex.z );
  28937. // normal
  28938. normals.push( 0, 0, 1 );
  28939. // uv
  28940. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  28941. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  28942. uvs.push( uv.x, uv.y );
  28943. }
  28944. // increase the radius for next row of vertices
  28945. radius += radiusStep;
  28946. }
  28947. // indices
  28948. for ( j = 0; j < phiSegments; j ++ ) {
  28949. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  28950. for ( i = 0; i < thetaSegments; i ++ ) {
  28951. segment = i + thetaSegmentLevel;
  28952. var a = segment;
  28953. var b = segment + thetaSegments + 1;
  28954. var c = segment + thetaSegments + 2;
  28955. var d = segment + 1;
  28956. // faces
  28957. indices.push( a, b, d );
  28958. indices.push( b, c, d );
  28959. }
  28960. }
  28961. // build geometry
  28962. this.setIndex( indices );
  28963. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28964. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  28965. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  28966. }
  28967. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  28968. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  28969. /**
  28970. * @author TristanVALCKE / https://github.com/Itee
  28971. * @author Anonymous
  28972. */
  28973. /* global QUnit */
  28974. QUnit.module( 'Geometries', () => {
  28975. QUnit.module.todo( 'RingGeometry', ( hooks ) => {
  28976. var geometries = undefined;
  28977. hooks.beforeEach( function () {
  28978. const parameters = {
  28979. innerRadius: 10,
  28980. outerRadius: 60,
  28981. thetaSegments: 12,
  28982. phiSegments: 14,
  28983. thetaStart: 0.1,
  28984. thetaLength: 2.0
  28985. };
  28986. geometries = [
  28987. new RingGeometry(),
  28988. new RingGeometry( parameters.innerRadius ),
  28989. new RingGeometry( parameters.innerRadius, parameters.outerRadius ),
  28990. new RingGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments ),
  28991. new RingGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments ),
  28992. new RingGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments, parameters.thetaStart ),
  28993. new RingGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments, parameters.thetaStart, parameters.thetaLength ),
  28994. ];
  28995. } );
  28996. // INHERITANCE
  28997. QUnit.test( "Extending", ( assert ) => {
  28998. assert.ok( false, "everything's gonna be alright" );
  28999. } );
  29000. // INSTANCING
  29001. QUnit.test( "Instancing", ( assert ) => {
  29002. assert.ok( false, "everything's gonna be alright" );
  29003. } );
  29004. // OTHERS
  29005. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29006. runStdGeometryTests( assert, geometries );
  29007. } );
  29008. } );
  29009. QUnit.module.todo( 'RingBufferGeometry', ( hooks ) => {
  29010. var geometries = undefined;
  29011. hooks.beforeEach( function () {
  29012. const parameters = {
  29013. innerRadius: 10,
  29014. outerRadius: 60,
  29015. thetaSegments: 12,
  29016. phiSegments: 14,
  29017. thetaStart: 0.1,
  29018. thetaLength: 2.0
  29019. };
  29020. geometries = [
  29021. new RingBufferGeometry(),
  29022. new RingBufferGeometry( parameters.innerRadius ),
  29023. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius ),
  29024. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments ),
  29025. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments ),
  29026. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments, parameters.thetaStart ),
  29027. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments, parameters.thetaStart, parameters.thetaLength ),
  29028. ];
  29029. } );
  29030. // INHERITANCE
  29031. QUnit.test( "Extending", ( assert ) => {
  29032. assert.ok( false, "everything's gonna be alright" );
  29033. } );
  29034. // INSTANCING
  29035. QUnit.test( "Instancing", ( assert ) => {
  29036. assert.ok( false, "everything's gonna be alright" );
  29037. } );
  29038. // OTHERS
  29039. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29040. runStdGeometryTests( assert, geometries );
  29041. } );
  29042. } );
  29043. } );
  29044. /**
  29045. * @author jonobr1 / http://jonobr1.com
  29046. * @author Mugen87 / https://github.com/Mugen87
  29047. */
  29048. // ShapeGeometry
  29049. function ShapeGeometry( shapes, curveSegments ) {
  29050. Geometry.call( this );
  29051. this.type = 'ShapeGeometry';
  29052. if ( typeof curveSegments === 'object' ) {
  29053. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  29054. curveSegments = curveSegments.curveSegments;
  29055. }
  29056. this.parameters = {
  29057. shapes: shapes,
  29058. curveSegments: curveSegments
  29059. };
  29060. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  29061. this.mergeVertices();
  29062. }
  29063. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  29064. ShapeGeometry.prototype.constructor = ShapeGeometry;
  29065. // ShapeBufferGeometry
  29066. function ShapeBufferGeometry( shapes, curveSegments ) {
  29067. BufferGeometry.call( this );
  29068. this.type = 'ShapeBufferGeometry';
  29069. this.parameters = {
  29070. shapes: shapes,
  29071. curveSegments: curveSegments
  29072. };
  29073. curveSegments = curveSegments || 12;
  29074. // buffers
  29075. var indices = [];
  29076. var vertices = [];
  29077. var normals = [];
  29078. var uvs = [];
  29079. // helper variables
  29080. var groupStart = 0;
  29081. var groupCount = 0;
  29082. // allow single and array values for "shapes" parameter
  29083. if ( Array.isArray( shapes ) === false ) {
  29084. addShape( shapes );
  29085. } else {
  29086. for ( var i = 0; i < shapes.length; i ++ ) {
  29087. addShape( shapes[ i ] );
  29088. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  29089. groupStart += groupCount;
  29090. groupCount = 0;
  29091. }
  29092. }
  29093. // build geometry
  29094. this.setIndex( indices );
  29095. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  29096. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  29097. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  29098. // helper functions
  29099. function addShape( shape ) {
  29100. var i, l, shapeHole;
  29101. var indexOffset = vertices.length / 3;
  29102. var points = shape.extractPoints( curveSegments );
  29103. var shapeVertices = points.shape;
  29104. var shapeHoles = points.holes;
  29105. // check direction of vertices
  29106. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  29107. shapeVertices = shapeVertices.reverse();
  29108. // also check if holes are in the opposite direction
  29109. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  29110. shapeHole = shapeHoles[ i ];
  29111. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  29112. shapeHoles[ i ] = shapeHole.reverse();
  29113. }
  29114. }
  29115. }
  29116. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  29117. // join vertices of inner and outer paths to a single array
  29118. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  29119. shapeHole = shapeHoles[ i ];
  29120. shapeVertices = shapeVertices.concat( shapeHole );
  29121. }
  29122. // vertices, normals, uvs
  29123. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  29124. var vertex = shapeVertices[ i ];
  29125. vertices.push( vertex.x, vertex.y, 0 );
  29126. normals.push( 0, 0, 1 );
  29127. uvs.push( vertex.x, vertex.y ); // world uvs
  29128. }
  29129. // incides
  29130. for ( i = 0, l = faces.length; i < l; i ++ ) {
  29131. var face = faces[ i ];
  29132. var a = face[ 0 ] + indexOffset;
  29133. var b = face[ 1 ] + indexOffset;
  29134. var c = face[ 2 ] + indexOffset;
  29135. indices.push( a, b, c );
  29136. groupCount += 3;
  29137. }
  29138. }
  29139. }
  29140. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  29141. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  29142. /**
  29143. * @author TristanVALCKE / https://github.com/Itee
  29144. */
  29145. /* global QUnit */
  29146. QUnit.module( 'Geometries', () => {
  29147. QUnit.module.todo( 'ShapeGeometry', ( hooks ) => {
  29148. var geometries = undefined;
  29149. hooks.beforeEach( function () {
  29150. const parameters = {};
  29151. geometries = [
  29152. new ShapeGeometry()
  29153. ];
  29154. } );
  29155. // INHERITANCE
  29156. QUnit.test( "Extending", ( assert ) => {
  29157. assert.ok( false, "everything's gonna be alright" );
  29158. } );
  29159. // INSTANCING
  29160. QUnit.test( "Instancing", ( assert ) => {
  29161. assert.ok( false, "everything's gonna be alright" );
  29162. } );
  29163. // OTHERS
  29164. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29165. runStdGeometryTests( assert, geometries );
  29166. } );
  29167. } );
  29168. QUnit.module.todo( 'ShapeBufferGeometry', ( hooks ) => {
  29169. var geometries = undefined;
  29170. hooks.beforeEach( function () {
  29171. const parameters = {};
  29172. geometries = [
  29173. new ShapeBufferGeometry()
  29174. ];
  29175. } );
  29176. // INHERITANCE
  29177. QUnit.test( "Extending", ( assert ) => {
  29178. assert.ok( false, "everything's gonna be alright" );
  29179. } );
  29180. // INSTANCING
  29181. QUnit.test( "Instancing", ( assert ) => {
  29182. assert.ok( false, "everything's gonna be alright" );
  29183. } );
  29184. // OTHERS
  29185. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29186. runStdGeometryTests( assert, geometries );
  29187. } );
  29188. } );
  29189. } );
  29190. /**
  29191. * @author TristanVALCKE / https://github.com/Itee
  29192. * @author Anonymous
  29193. */
  29194. /* global QUnit */
  29195. QUnit.module( 'Geometries', () => {
  29196. QUnit.module.todo( 'SphereGeometry', ( hooks ) => {
  29197. var geometries = undefined;
  29198. hooks.beforeEach( function () {
  29199. const parameters = {
  29200. radius: 10,
  29201. widthSegments: 20,
  29202. heightSegments: 30,
  29203. phiStart: 0.5,
  29204. phiLength: 1.0,
  29205. thetaStart: 0.4,
  29206. thetaLength: 2.0,
  29207. };
  29208. geometries = [
  29209. new SphereGeometry(),
  29210. new SphereGeometry( parameters.radius ),
  29211. new SphereGeometry( parameters.radius, parameters.widthSegments ),
  29212. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments ),
  29213. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart ),
  29214. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength ),
  29215. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart ),
  29216. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart, parameters.thetaLength ),
  29217. ];
  29218. } );
  29219. // INHERITANCE
  29220. QUnit.test( "Extending", ( assert ) => {
  29221. assert.ok( false, "everything's gonna be alright" );
  29222. } );
  29223. // INSTANCING
  29224. QUnit.test( "Instancing", ( assert ) => {
  29225. assert.ok( false, "everything's gonna be alright" );
  29226. } );
  29227. // OTHERS
  29228. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29229. runStdGeometryTests( assert, geometries );
  29230. } );
  29231. } );
  29232. QUnit.module.todo( 'SphereBufferGeometry', ( hooks ) => {
  29233. var geometries = undefined;
  29234. hooks.beforeEach( function () {
  29235. const parameters = {
  29236. radius: 10,
  29237. widthSegments: 20,
  29238. heightSegments: 30,
  29239. phiStart: 0.5,
  29240. phiLength: 1.0,
  29241. thetaStart: 0.4,
  29242. thetaLength: 2.0,
  29243. };
  29244. geometries = [
  29245. new SphereBufferGeometry(),
  29246. new SphereBufferGeometry( parameters.radius ),
  29247. new SphereBufferGeometry( parameters.radius, parameters.widthSegments ),
  29248. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments ),
  29249. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart ),
  29250. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength ),
  29251. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart ),
  29252. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart, parameters.thetaLength ),
  29253. ];
  29254. } );
  29255. // INHERITANCE
  29256. QUnit.test( "Extending", ( assert ) => {
  29257. assert.ok( false, "everything's gonna be alright" );
  29258. } );
  29259. // INSTANCING
  29260. QUnit.test( "Instancing", ( assert ) => {
  29261. assert.ok( false, "everything's gonna be alright" );
  29262. } );
  29263. // OTHERS
  29264. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29265. runStdGeometryTests( assert, geometries );
  29266. } );
  29267. } );
  29268. } );
  29269. /**
  29270. * @author timothypratley / https://github.com/timothypratley
  29271. * @author Mugen87 / https://github.com/Mugen87
  29272. */
  29273. // TetrahedronGeometry
  29274. function TetrahedronGeometry( radius, detail ) {
  29275. Geometry.call( this );
  29276. this.type = 'TetrahedronGeometry';
  29277. this.parameters = {
  29278. radius: radius,
  29279. detail: detail
  29280. };
  29281. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  29282. this.mergeVertices();
  29283. }
  29284. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  29285. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  29286. // TetrahedronBufferGeometry
  29287. function TetrahedronBufferGeometry( radius, detail ) {
  29288. var vertices = [
  29289. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  29290. ];
  29291. var indices = [
  29292. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  29293. ];
  29294. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  29295. this.type = 'TetrahedronBufferGeometry';
  29296. this.parameters = {
  29297. radius: radius,
  29298. detail: detail
  29299. };
  29300. }
  29301. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  29302. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  29303. /**
  29304. * @author TristanVALCKE / https://github.com/Itee
  29305. * @author Anonymous
  29306. */
  29307. /* global QUnit */
  29308. QUnit.module( 'Geometries', () => {
  29309. QUnit.module.todo( 'TetrahedronGeometry', ( hooks ) => {
  29310. var geometries = undefined;
  29311. hooks.beforeEach( function () {
  29312. const parameters = {
  29313. radius: 10,
  29314. detail: undefined
  29315. };
  29316. geometries = [
  29317. new TetrahedronGeometry(),
  29318. new TetrahedronGeometry( parameters.radius ),
  29319. new TetrahedronGeometry( parameters.radius, parameters.widthSegments ),
  29320. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments ),
  29321. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart ),
  29322. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength ),
  29323. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart ),
  29324. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart, parameters.thetaLength ),
  29325. ];
  29326. } );
  29327. // INHERITANCE
  29328. QUnit.test( "Extending", ( assert ) => {
  29329. assert.ok( false, "everything's gonna be alright" );
  29330. } );
  29331. // INSTANCING
  29332. QUnit.test( "Instancing", ( assert ) => {
  29333. assert.ok( false, "everything's gonna be alright" );
  29334. } );
  29335. // OTHERS
  29336. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29337. runStdGeometryTests( assert, geometries );
  29338. } );
  29339. } );
  29340. QUnit.module.todo( 'SphereBufferGeometry', ( hooks ) => {
  29341. var geometries = undefined;
  29342. hooks.beforeEach( function () {
  29343. const parameters = {
  29344. radius: 10,
  29345. detail: undefined
  29346. };
  29347. geometries = [
  29348. new TetrahedronBufferGeometry(),
  29349. new TetrahedronBufferGeometry( parameters.radius ),
  29350. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments ),
  29351. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments ),
  29352. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart ),
  29353. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength ),
  29354. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart ),
  29355. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart, parameters.thetaLength ),
  29356. ];
  29357. } );
  29358. // INHERITANCE
  29359. QUnit.test( "Extending", ( assert ) => {
  29360. assert.ok( false, "everything's gonna be alright" );
  29361. } );
  29362. // INSTANCING
  29363. QUnit.test( "Instancing", ( assert ) => {
  29364. assert.ok( false, "everything's gonna be alright" );
  29365. } );
  29366. // OTHERS
  29367. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29368. runStdGeometryTests( assert, geometries );
  29369. } );
  29370. } );
  29371. } );
  29372. /**
  29373. * @author zz85 / http://www.lab4games.net/zz85/blog
  29374. * @author alteredq / http://alteredqualia.com/
  29375. *
  29376. * Text = 3D Text
  29377. *
  29378. * parameters = {
  29379. * font: <THREE.Font>, // font
  29380. *
  29381. * size: <float>, // size of the text
  29382. * height: <float>, // thickness to extrude text
  29383. * curveSegments: <int>, // number of points on the curves
  29384. *
  29385. * bevelEnabled: <bool>, // turn on bevel
  29386. * bevelThickness: <float>, // how deep into text bevel goes
  29387. * bevelSize: <float> // how far from text outline is bevel
  29388. * }
  29389. */
  29390. // TextGeometry
  29391. function TextGeometry( text, parameters ) {
  29392. Geometry.call( this );
  29393. this.type = 'TextGeometry';
  29394. this.parameters = {
  29395. text: text,
  29396. parameters: parameters
  29397. };
  29398. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  29399. this.mergeVertices();
  29400. }
  29401. TextGeometry.prototype = Object.create( Geometry.prototype );
  29402. TextGeometry.prototype.constructor = TextGeometry;
  29403. // TextBufferGeometry
  29404. function TextBufferGeometry( text, parameters ) {
  29405. parameters = parameters || {};
  29406. var font = parameters.font;
  29407. if ( ! ( font && font.isFont ) ) {
  29408. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  29409. return new Geometry();
  29410. }
  29411. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  29412. // translate parameters to ExtrudeGeometry API
  29413. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  29414. // defaults
  29415. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  29416. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  29417. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  29418. ExtrudeBufferGeometry.call( this, shapes, parameters );
  29419. this.type = 'TextBufferGeometry';
  29420. }
  29421. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  29422. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  29423. /**
  29424. * @author TristanVALCKE / https://github.com/Itee
  29425. */
  29426. /* global QUnit */
  29427. QUnit.module( 'Geometries', () => {
  29428. QUnit.module.todo( 'TextGeometry', ( hooks ) => {
  29429. var geometries = undefined;
  29430. hooks.beforeEach( function () {
  29431. // TODO: we cannot load any font from Threejs package :S
  29432. const parameters = {
  29433. font: undefined
  29434. };
  29435. geometries = [
  29436. new TextGeometry()
  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( 'TextBufferGeometry', ( hooks ) => {
  29453. var geometries = undefined;
  29454. hooks.beforeEach( function () {
  29455. const parameters = {};
  29456. geometries = [
  29457. new TextBufferGeometry()
  29458. ];
  29459. } );
  29460. // INHERITANCE
  29461. QUnit.test( "Extending", ( assert ) => {
  29462. assert.ok( false, "everything's gonna be alright" );
  29463. } );
  29464. // INSTANCING
  29465. QUnit.test( "Instancing", ( assert ) => {
  29466. assert.ok( false, "everything's gonna be alright" );
  29467. } );
  29468. // OTHERS
  29469. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29470. runStdGeometryTests( assert, geometries );
  29471. } );
  29472. } );
  29473. } );
  29474. /**
  29475. * @author oosmoxiecode
  29476. * @author mrdoob / http://mrdoob.com/
  29477. * @author Mugen87 / https://github.com/Mugen87
  29478. */
  29479. // TorusGeometry
  29480. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  29481. Geometry.call( this );
  29482. this.type = 'TorusGeometry';
  29483. this.parameters = {
  29484. radius: radius,
  29485. tube: tube,
  29486. radialSegments: radialSegments,
  29487. tubularSegments: tubularSegments,
  29488. arc: arc
  29489. };
  29490. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  29491. this.mergeVertices();
  29492. }
  29493. TorusGeometry.prototype = Object.create( Geometry.prototype );
  29494. TorusGeometry.prototype.constructor = TorusGeometry;
  29495. // TorusBufferGeometry
  29496. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  29497. BufferGeometry.call( this );
  29498. this.type = 'TorusBufferGeometry';
  29499. this.parameters = {
  29500. radius: radius,
  29501. tube: tube,
  29502. radialSegments: radialSegments,
  29503. tubularSegments: tubularSegments,
  29504. arc: arc
  29505. };
  29506. radius = radius || 1;
  29507. tube = tube || 0.4;
  29508. radialSegments = Math.floor( radialSegments ) || 8;
  29509. tubularSegments = Math.floor( tubularSegments ) || 6;
  29510. arc = arc || Math.PI * 2;
  29511. // buffers
  29512. var indices = [];
  29513. var vertices = [];
  29514. var normals = [];
  29515. var uvs = [];
  29516. // helper variables
  29517. var center = new Vector3();
  29518. var vertex = new Vector3();
  29519. var normal = new Vector3();
  29520. var j, i;
  29521. // generate vertices, normals and uvs
  29522. for ( j = 0; j <= radialSegments; j ++ ) {
  29523. for ( i = 0; i <= tubularSegments; i ++ ) {
  29524. var u = i / tubularSegments * arc;
  29525. var v = j / radialSegments * Math.PI * 2;
  29526. // vertex
  29527. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  29528. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  29529. vertex.z = tube * Math.sin( v );
  29530. vertices.push( vertex.x, vertex.y, vertex.z );
  29531. // normal
  29532. center.x = radius * Math.cos( u );
  29533. center.y = radius * Math.sin( u );
  29534. normal.subVectors( vertex, center ).normalize();
  29535. normals.push( normal.x, normal.y, normal.z );
  29536. // uv
  29537. uvs.push( i / tubularSegments );
  29538. uvs.push( j / radialSegments );
  29539. }
  29540. }
  29541. // generate indices
  29542. for ( j = 1; j <= radialSegments; j ++ ) {
  29543. for ( i = 1; i <= tubularSegments; i ++ ) {
  29544. // indices
  29545. var a = ( tubularSegments + 1 ) * j + i - 1;
  29546. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  29547. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  29548. var d = ( tubularSegments + 1 ) * j + i;
  29549. // faces
  29550. indices.push( a, b, d );
  29551. indices.push( b, c, d );
  29552. }
  29553. }
  29554. // build geometry
  29555. this.setIndex( indices );
  29556. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  29557. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  29558. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  29559. }
  29560. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  29561. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  29562. /**
  29563. * @author TristanVALCKE / https://github.com/Itee
  29564. * @author Anonymous
  29565. */
  29566. /* global QUnit */
  29567. QUnit.module( 'Geometries', () => {
  29568. QUnit.module.todo( 'TorusGeometry', ( hooks ) => {
  29569. var geometries = undefined;
  29570. hooks.beforeEach( function () {
  29571. const parameters = {
  29572. radius: 10,
  29573. tube: 20,
  29574. radialSegments: 30,
  29575. tubularSegments: 10,
  29576. arc: 2.0,
  29577. };
  29578. geometries = [
  29579. new TorusGeometry(),
  29580. new TorusGeometry( parameters.radius ),
  29581. new TorusGeometry( parameters.radius, parameters.tube ),
  29582. new TorusGeometry( parameters.radius, parameters.tube, parameters.radialSegments ),
  29583. new TorusGeometry( parameters.radius, parameters.tube, parameters.radialSegments, parameters.tubularSegments ),
  29584. new TorusGeometry( parameters.radius, parameters.tube, parameters.radialSegments, parameters.tubularSegments, parameters.arc ),
  29585. ];
  29586. } );
  29587. // INHERITANCE
  29588. QUnit.test( "Extending", ( assert ) => {
  29589. assert.ok( false, "everything's gonna be alright" );
  29590. } );
  29591. // INSTANCING
  29592. QUnit.test( "Instancing", ( assert ) => {
  29593. assert.ok( false, "everything's gonna be alright" );
  29594. } );
  29595. // OTHERS
  29596. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29597. runStdGeometryTests( assert, geometries );
  29598. } );
  29599. } );
  29600. QUnit.module.todo( 'TorusBufferGeometry', ( hooks ) => {
  29601. var geometries = undefined;
  29602. hooks.beforeEach( function () {
  29603. const parameters = {
  29604. radius: 10,
  29605. tube: 20,
  29606. radialSegments: 30,
  29607. tubularSegments: 10,
  29608. arc: 2.0,
  29609. };
  29610. geometries = [
  29611. new TorusBufferGeometry(),
  29612. new TorusBufferGeometry( parameters.radius ),
  29613. new TorusBufferGeometry( parameters.radius, parameters.tube ),
  29614. new TorusBufferGeometry( parameters.radius, parameters.tube, parameters.radialSegments ),
  29615. new TorusBufferGeometry( parameters.radius, parameters.tube, parameters.radialSegments, parameters.tubularSegments ),
  29616. new TorusBufferGeometry( parameters.radius, parameters.tube, parameters.radialSegments, parameters.tubularSegments, parameters.arc ),
  29617. ];
  29618. } );
  29619. // INHERITANCE
  29620. QUnit.test( "Extending", ( assert ) => {
  29621. assert.ok( false, "everything's gonna be alright" );
  29622. } );
  29623. // INSTANCING
  29624. QUnit.test( "Instancing", ( assert ) => {
  29625. assert.ok( false, "everything's gonna be alright" );
  29626. } );
  29627. // OTHERS
  29628. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29629. runStdGeometryTests( assert, geometries );
  29630. } );
  29631. } );
  29632. } );
  29633. /**
  29634. * @author oosmoxiecode
  29635. * @author Mugen87 / https://github.com/Mugen87
  29636. *
  29637. * based on http://www.blackpawn.com/texts/pqtorus/
  29638. */
  29639. // TorusKnotGeometry
  29640. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  29641. Geometry.call( this );
  29642. this.type = 'TorusKnotGeometry';
  29643. this.parameters = {
  29644. radius: radius,
  29645. tube: tube,
  29646. tubularSegments: tubularSegments,
  29647. radialSegments: radialSegments,
  29648. p: p,
  29649. q: q
  29650. };
  29651. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  29652. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  29653. this.mergeVertices();
  29654. }
  29655. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  29656. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  29657. // TorusKnotBufferGeometry
  29658. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  29659. BufferGeometry.call( this );
  29660. this.type = 'TorusKnotBufferGeometry';
  29661. this.parameters = {
  29662. radius: radius,
  29663. tube: tube,
  29664. tubularSegments: tubularSegments,
  29665. radialSegments: radialSegments,
  29666. p: p,
  29667. q: q
  29668. };
  29669. radius = radius || 1;
  29670. tube = tube || 0.4;
  29671. tubularSegments = Math.floor( tubularSegments ) || 64;
  29672. radialSegments = Math.floor( radialSegments ) || 8;
  29673. p = p || 2;
  29674. q = q || 3;
  29675. // buffers
  29676. var indices = [];
  29677. var vertices = [];
  29678. var normals = [];
  29679. var uvs = [];
  29680. // helper variables
  29681. var i, j;
  29682. var vertex = new Vector3();
  29683. var normal = new Vector3();
  29684. var P1 = new Vector3();
  29685. var P2 = new Vector3();
  29686. var B = new Vector3();
  29687. var T = new Vector3();
  29688. var N = new Vector3();
  29689. // generate vertices, normals and uvs
  29690. for ( i = 0; i <= tubularSegments; ++ i ) {
  29691. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  29692. var u = i / tubularSegments * p * Math.PI * 2;
  29693. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  29694. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  29695. calculatePositionOnCurve( u, p, q, radius, P1 );
  29696. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  29697. // calculate orthonormal basis
  29698. T.subVectors( P2, P1 );
  29699. N.addVectors( P2, P1 );
  29700. B.crossVectors( T, N );
  29701. N.crossVectors( B, T );
  29702. // normalize B, N. T can be ignored, we don't use it
  29703. B.normalize();
  29704. N.normalize();
  29705. for ( j = 0; j <= radialSegments; ++ j ) {
  29706. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  29707. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  29708. var v = j / radialSegments * Math.PI * 2;
  29709. var cx = - tube * Math.cos( v );
  29710. var cy = tube * Math.sin( v );
  29711. // now calculate the final vertex position.
  29712. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  29713. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  29714. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  29715. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  29716. vertices.push( vertex.x, vertex.y, vertex.z );
  29717. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  29718. normal.subVectors( vertex, P1 ).normalize();
  29719. normals.push( normal.x, normal.y, normal.z );
  29720. // uv
  29721. uvs.push( i / tubularSegments );
  29722. uvs.push( j / radialSegments );
  29723. }
  29724. }
  29725. // generate indices
  29726. for ( j = 1; j <= tubularSegments; j ++ ) {
  29727. for ( i = 1; i <= radialSegments; i ++ ) {
  29728. // indices
  29729. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  29730. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  29731. var c = ( radialSegments + 1 ) * j + i;
  29732. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  29733. // faces
  29734. indices.push( a, b, d );
  29735. indices.push( b, c, d );
  29736. }
  29737. }
  29738. // build geometry
  29739. this.setIndex( indices );
  29740. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  29741. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  29742. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  29743. // this function calculates the current position on the torus curve
  29744. function calculatePositionOnCurve( u, p, q, radius, position ) {
  29745. var cu = Math.cos( u );
  29746. var su = Math.sin( u );
  29747. var quOverP = q / p * u;
  29748. var cs = Math.cos( quOverP );
  29749. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  29750. position.y = radius * ( 2 + cs ) * su * 0.5;
  29751. position.z = radius * Math.sin( quOverP ) * 0.5;
  29752. }
  29753. }
  29754. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  29755. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  29756. /**
  29757. * @author TristanVALCKE / https://github.com/Itee
  29758. * @author Anonymous
  29759. */
  29760. /* global QUnit */
  29761. QUnit.module( 'Geometries', () => {
  29762. QUnit.module.todo( 'SphereGeometry', ( hooks ) => {
  29763. var geometries = undefined;
  29764. hooks.beforeEach( function () {
  29765. const parameters = {
  29766. radius: 10,
  29767. tube: 20,
  29768. tubularSegments: 30,
  29769. radialSegments: 10,
  29770. p: 3,
  29771. q: 2
  29772. };
  29773. geometries = [
  29774. new TorusKnotGeometry(),
  29775. new TorusKnotGeometry( parameters.radius ),
  29776. new TorusKnotGeometry( parameters.radius, parameters.tube ),
  29777. new TorusKnotGeometry( parameters.radius, parameters.tube, parameters.tubularSegments ),
  29778. new TorusKnotGeometry( parameters.radius, parameters.tube, parameters.tubularSegments, parameters.radialSegments ),
  29779. new TorusKnotGeometry( parameters.radius, parameters.tube, parameters.tubularSegments, parameters.radialSegments, parameters.p, parameters.q ),
  29780. ];
  29781. } );
  29782. // INHERITANCE
  29783. QUnit.test( "Extending", ( assert ) => {
  29784. assert.ok( false, "everything's gonna be alright" );
  29785. } );
  29786. // INSTANCING
  29787. QUnit.test( "Instancing", ( assert ) => {
  29788. assert.ok( false, "everything's gonna be alright" );
  29789. } );
  29790. // OTHERS
  29791. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29792. runStdGeometryTests( assert, geometries );
  29793. } );
  29794. } );
  29795. QUnit.module.todo( 'TorusKnotBufferGeometry', ( hooks ) => {
  29796. var geometries = undefined;
  29797. hooks.beforeEach( function () {
  29798. const parameters = {
  29799. radius: 10,
  29800. tube: 20,
  29801. tubularSegments: 30,
  29802. radialSegments: 10,
  29803. p: 3,
  29804. q: 2
  29805. };
  29806. geometries = [
  29807. new TorusKnotBufferGeometry(),
  29808. new TorusKnotBufferGeometry( parameters.radius ),
  29809. new TorusKnotBufferGeometry( parameters.radius, parameters.tube ),
  29810. new TorusKnotBufferGeometry( parameters.radius, parameters.tube, parameters.tubularSegments ),
  29811. new TorusKnotBufferGeometry( parameters.radius, parameters.tube, parameters.tubularSegments, parameters.radialSegments ),
  29812. new TorusKnotBufferGeometry( parameters.radius, parameters.tube, parameters.tubularSegments, parameters.radialSegments, parameters.p, parameters.q ),
  29813. ];
  29814. } );
  29815. // INHERITANCE
  29816. QUnit.test( "Extending", ( assert ) => {
  29817. assert.ok( false, "everything's gonna be alright" );
  29818. } );
  29819. // INSTANCING
  29820. QUnit.test( "Instancing", ( assert ) => {
  29821. assert.ok( false, "everything's gonna be alright" );
  29822. } );
  29823. // OTHERS
  29824. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29825. runStdGeometryTests( assert, geometries );
  29826. } );
  29827. } );
  29828. } );
  29829. /**
  29830. * @author oosmoxiecode / https://github.com/oosmoxiecode
  29831. * @author WestLangley / https://github.com/WestLangley
  29832. * @author zz85 / https://github.com/zz85
  29833. * @author miningold / https://github.com/miningold
  29834. * @author jonobr1 / https://github.com/jonobr1
  29835. * @author Mugen87 / https://github.com/Mugen87
  29836. *
  29837. */
  29838. // TubeGeometry
  29839. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  29840. Geometry.call( this );
  29841. this.type = 'TubeGeometry';
  29842. this.parameters = {
  29843. path: path,
  29844. tubularSegments: tubularSegments,
  29845. radius: radius,
  29846. radialSegments: radialSegments,
  29847. closed: closed
  29848. };
  29849. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  29850. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  29851. // expose internals
  29852. this.tangents = bufferGeometry.tangents;
  29853. this.normals = bufferGeometry.normals;
  29854. this.binormals = bufferGeometry.binormals;
  29855. // create geometry
  29856. this.fromBufferGeometry( bufferGeometry );
  29857. this.mergeVertices();
  29858. }
  29859. TubeGeometry.prototype = Object.create( Geometry.prototype );
  29860. TubeGeometry.prototype.constructor = TubeGeometry;
  29861. // TubeBufferGeometry
  29862. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  29863. BufferGeometry.call( this );
  29864. this.type = 'TubeBufferGeometry';
  29865. this.parameters = {
  29866. path: path,
  29867. tubularSegments: tubularSegments,
  29868. radius: radius,
  29869. radialSegments: radialSegments,
  29870. closed: closed
  29871. };
  29872. tubularSegments = tubularSegments || 64;
  29873. radius = radius || 1;
  29874. radialSegments = radialSegments || 8;
  29875. closed = closed || false;
  29876. var frames = path.computeFrenetFrames( tubularSegments, closed );
  29877. // expose internals
  29878. this.tangents = frames.tangents;
  29879. this.normals = frames.normals;
  29880. this.binormals = frames.binormals;
  29881. // helper variables
  29882. var vertex = new Vector3();
  29883. var normal = new Vector3();
  29884. var uv = new Vector2();
  29885. var P = new Vector3();
  29886. var i, j;
  29887. // buffer
  29888. var vertices = [];
  29889. var normals = [];
  29890. var uvs = [];
  29891. var indices = [];
  29892. // create buffer data
  29893. generateBufferData();
  29894. // build geometry
  29895. this.setIndex( indices );
  29896. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  29897. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  29898. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  29899. // functions
  29900. function generateBufferData() {
  29901. for ( i = 0; i < tubularSegments; i ++ ) {
  29902. generateSegment( i );
  29903. }
  29904. // if the geometry is not closed, generate the last row of vertices and normals
  29905. // at the regular position on the given path
  29906. //
  29907. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  29908. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  29909. // uvs are generated in a separate function.
  29910. // this makes it easy compute correct values for closed geometries
  29911. generateUVs();
  29912. // finally create faces
  29913. generateIndices();
  29914. }
  29915. function generateSegment( i ) {
  29916. // we use getPointAt to sample evenly distributed points from the given path
  29917. P = path.getPointAt( i / tubularSegments, P );
  29918. // retrieve corresponding normal and binormal
  29919. var N = frames.normals[ i ];
  29920. var B = frames.binormals[ i ];
  29921. // generate normals and vertices for the current segment
  29922. for ( j = 0; j <= radialSegments; j ++ ) {
  29923. var v = j / radialSegments * Math.PI * 2;
  29924. var sin = Math.sin( v );
  29925. var cos = - Math.cos( v );
  29926. // normal
  29927. normal.x = ( cos * N.x + sin * B.x );
  29928. normal.y = ( cos * N.y + sin * B.y );
  29929. normal.z = ( cos * N.z + sin * B.z );
  29930. normal.normalize();
  29931. normals.push( normal.x, normal.y, normal.z );
  29932. // vertex
  29933. vertex.x = P.x + radius * normal.x;
  29934. vertex.y = P.y + radius * normal.y;
  29935. vertex.z = P.z + radius * normal.z;
  29936. vertices.push( vertex.x, vertex.y, vertex.z );
  29937. }
  29938. }
  29939. function generateIndices() {
  29940. for ( j = 1; j <= tubularSegments; j ++ ) {
  29941. for ( i = 1; i <= radialSegments; i ++ ) {
  29942. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  29943. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  29944. var c = ( radialSegments + 1 ) * j + i;
  29945. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  29946. // faces
  29947. indices.push( a, b, d );
  29948. indices.push( b, c, d );
  29949. }
  29950. }
  29951. }
  29952. function generateUVs() {
  29953. for ( i = 0; i <= tubularSegments; i ++ ) {
  29954. for ( j = 0; j <= radialSegments; j ++ ) {
  29955. uv.x = i / tubularSegments;
  29956. uv.y = j / radialSegments;
  29957. uvs.push( uv.x, uv.y );
  29958. }
  29959. }
  29960. }
  29961. }
  29962. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  29963. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  29964. /**
  29965. * @author TristanVALCKE / https://github.com/Itee
  29966. */
  29967. /* global QUnit */
  29968. QUnit.module( 'Geometries', () => {
  29969. QUnit.module.todo( 'TubeGeometry', ( hooks ) => {
  29970. var geometries = undefined;
  29971. hooks.beforeEach( function () {
  29972. const parameters = {};
  29973. geometries = [
  29974. new TubeGeometry()
  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. QUnit.module.todo( 'TubeBufferGeometry', ( hooks ) => {
  29991. var geometries = undefined;
  29992. hooks.beforeEach( function () {
  29993. const parameters = {};
  29994. geometries = [
  29995. new TubeBufferGeometry()
  29996. ];
  29997. } );
  29998. // INHERITANCE
  29999. QUnit.test( "Extending", ( assert ) => {
  30000. assert.ok( false, "everything's gonna be alright" );
  30001. } );
  30002. // INSTANCING
  30003. QUnit.test( "Instancing", ( assert ) => {
  30004. assert.ok( false, "everything's gonna be alright" );
  30005. } );
  30006. // OTHERS
  30007. QUnit.test( 'Standard geometry tests', ( assert ) => {
  30008. runStdGeometryTests( assert, geometries );
  30009. } );
  30010. } );
  30011. } );
  30012. /**
  30013. * @author mrdoob / http://mrdoob.com/
  30014. * @author Mugen87 / https://github.com/Mugen87
  30015. */
  30016. function WireframeGeometry( geometry ) {
  30017. BufferGeometry.call( this );
  30018. this.type = 'WireframeGeometry';
  30019. // buffer
  30020. var vertices = [];
  30021. // helper variables
  30022. var i, j, l, o, ol;
  30023. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  30024. var key, keys = [ 'a', 'b', 'c' ];
  30025. var vertex;
  30026. // different logic for Geometry and BufferGeometry
  30027. if ( geometry && geometry.isGeometry ) {
  30028. // create a data structure that contains all edges without duplicates
  30029. var faces = geometry.faces;
  30030. for ( i = 0, l = faces.length; i < l; i ++ ) {
  30031. var face = faces[ i ];
  30032. for ( j = 0; j < 3; j ++ ) {
  30033. edge1 = face[ keys[ j ] ];
  30034. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  30035. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  30036. edge[ 1 ] = Math.max( edge1, edge2 );
  30037. key = edge[ 0 ] + ',' + edge[ 1 ];
  30038. if ( edges[ key ] === undefined ) {
  30039. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  30040. }
  30041. }
  30042. }
  30043. // generate vertices
  30044. for ( key in edges ) {
  30045. e = edges[ key ];
  30046. vertex = geometry.vertices[ e.index1 ];
  30047. vertices.push( vertex.x, vertex.y, vertex.z );
  30048. vertex = geometry.vertices[ e.index2 ];
  30049. vertices.push( vertex.x, vertex.y, vertex.z );
  30050. }
  30051. } else if ( geometry && geometry.isBufferGeometry ) {
  30052. var position, indices, groups;
  30053. var group, start, count;
  30054. var index1, index2;
  30055. vertex = new Vector3();
  30056. if ( geometry.index !== null ) {
  30057. // indexed BufferGeometry
  30058. position = geometry.attributes.position;
  30059. indices = geometry.index;
  30060. groups = geometry.groups;
  30061. if ( groups.length === 0 ) {
  30062. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  30063. }
  30064. // create a data structure that contains all eges without duplicates
  30065. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  30066. group = groups[ o ];
  30067. start = group.start;
  30068. count = group.count;
  30069. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  30070. for ( j = 0; j < 3; j ++ ) {
  30071. edge1 = indices.getX( i + j );
  30072. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  30073. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  30074. edge[ 1 ] = Math.max( edge1, edge2 );
  30075. key = edge[ 0 ] + ',' + edge[ 1 ];
  30076. if ( edges[ key ] === undefined ) {
  30077. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  30078. }
  30079. }
  30080. }
  30081. }
  30082. // generate vertices
  30083. for ( key in edges ) {
  30084. e = edges[ key ];
  30085. vertex.fromBufferAttribute( position, e.index1 );
  30086. vertices.push( vertex.x, vertex.y, vertex.z );
  30087. vertex.fromBufferAttribute( position, e.index2 );
  30088. vertices.push( vertex.x, vertex.y, vertex.z );
  30089. }
  30090. } else {
  30091. // non-indexed BufferGeometry
  30092. position = geometry.attributes.position;
  30093. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  30094. for ( j = 0; j < 3; j ++ ) {
  30095. // three edges per triangle, an edge is represented as (index1, index2)
  30096. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  30097. index1 = 3 * i + j;
  30098. vertex.fromBufferAttribute( position, index1 );
  30099. vertices.push( vertex.x, vertex.y, vertex.z );
  30100. index2 = 3 * i + ( ( j + 1 ) % 3 );
  30101. vertex.fromBufferAttribute( position, index2 );
  30102. vertices.push( vertex.x, vertex.y, vertex.z );
  30103. }
  30104. }
  30105. }
  30106. }
  30107. // build geometry
  30108. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  30109. }
  30110. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  30111. WireframeGeometry.prototype.constructor = WireframeGeometry;
  30112. /**
  30113. * @author TristanVALCKE / https://github.com/Itee
  30114. */
  30115. /* global QUnit */
  30116. QUnit.module( 'Geometries', () => {
  30117. QUnit.module.todo( 'WireframeGeometry', ( hooks ) => {
  30118. var geometries = undefined;
  30119. hooks.beforeEach( function () {
  30120. const parameters = {};
  30121. geometries = [
  30122. new WireframeGeometry()
  30123. ];
  30124. } );
  30125. // INHERITANCE
  30126. QUnit.test( "Extending", ( assert ) => {
  30127. assert.ok( false, "everything's gonna be alright" );
  30128. } );
  30129. // INSTANCING
  30130. QUnit.test( "Instancing", ( assert ) => {
  30131. assert.ok( false, "everything's gonna be alright" );
  30132. } );
  30133. // OTHERS
  30134. QUnit.test( 'Standard geometry tests', ( assert ) => {
  30135. runStdGeometryTests( assert, geometries );
  30136. } );
  30137. } );
  30138. } );
  30139. /**
  30140. * @author WestLangley / http://github.com/WestLangley
  30141. * @author zz85 / http://github.com/zz85
  30142. * @author bhouston / http://clara.io
  30143. *
  30144. * Creates an arrow for visualizing directions
  30145. *
  30146. * Parameters:
  30147. * dir - Vector3
  30148. * origin - Vector3
  30149. * length - Number
  30150. * color - color in hex value
  30151. * headLength - Number
  30152. * headWidth - Number
  30153. */
  30154. /**
  30155. * @author TristanVALCKE / https://github.com/Itee
  30156. */
  30157. /* global QUnit */
  30158. QUnit.module( 'Helpers', () => {
  30159. QUnit.module.todo( 'ArrowHelper', () => {
  30160. // INHERITANCE
  30161. QUnit.test( "Extending", ( assert ) => {
  30162. assert.ok( false, "everything's gonna be alright" );
  30163. } );
  30164. // INSTANCING
  30165. QUnit.test( "Instancing", ( assert ) => {
  30166. assert.ok( false, "everything's gonna be alright" );
  30167. } );
  30168. // PUBLIC STUFF
  30169. QUnit.test( "setDirection", ( assert ) => {
  30170. assert.ok( false, "everything's gonna be alright" );
  30171. } );
  30172. QUnit.test( "setLength", ( assert ) => {
  30173. assert.ok( false, "everything's gonna be alright" );
  30174. } );
  30175. QUnit.test( "setColor", ( assert ) => {
  30176. assert.ok( false, "everything's gonna be alright" );
  30177. } );
  30178. } );
  30179. } );
  30180. /**
  30181. * @author sroucheray / http://sroucheray.org/
  30182. * @author mrdoob / http://mrdoob.com/
  30183. */
  30184. /**
  30185. * @author TristanVALCKE / https://github.com/Itee
  30186. */
  30187. /* global QUnit */
  30188. QUnit.module( 'Helpers', () => {
  30189. QUnit.module.todo( 'AxesHelper', () => {
  30190. // INHERITANCE
  30191. QUnit.test( "Extending", ( assert ) => {
  30192. assert.ok( false, "everything's gonna be alright" );
  30193. } );
  30194. // INSTANCING
  30195. QUnit.test( "Instancing", ( assert ) => {
  30196. assert.ok( false, "everything's gonna be alright" );
  30197. } );
  30198. } );
  30199. } );
  30200. /**
  30201. * @author WestLangley / http://github.com/WestLangley
  30202. */
  30203. /**
  30204. * @author TristanVALCKE / https://github.com/Itee
  30205. */
  30206. /* global QUnit */
  30207. QUnit.module( 'Helpers', () => {
  30208. QUnit.module.todo( 'Box3Helper', () => {
  30209. // INHERITANCE
  30210. QUnit.test( "Extending", ( assert ) => {
  30211. assert.ok( false, "everything's gonna be alright" );
  30212. } );
  30213. // INSTANCING
  30214. QUnit.test( "Instancing", ( assert ) => {
  30215. assert.ok( false, "everything's gonna be alright" );
  30216. } );
  30217. // PUBLIC STUFF
  30218. QUnit.test( "updateMatrixWorld", ( assert ) => {
  30219. assert.ok( false, "everything's gonna be alright" );
  30220. } );
  30221. } );
  30222. } );
  30223. /**
  30224. * @author mrdoob / http://mrdoob.com/
  30225. * @author Mugen87 / http://github.com/Mugen87
  30226. */
  30227. function BoxHelper( object, color ) {
  30228. this.object = object;
  30229. if ( color === undefined ) color = 0xffff00;
  30230. 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 ] );
  30231. var positions = new Float32Array( 8 * 3 );
  30232. var geometry = new BufferGeometry();
  30233. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  30234. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  30235. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  30236. this.matrixAutoUpdate = false;
  30237. this.update();
  30238. }
  30239. BoxHelper.prototype = Object.create( LineSegments.prototype );
  30240. BoxHelper.prototype.constructor = BoxHelper;
  30241. BoxHelper.prototype.update = ( function () {
  30242. var box = new Box3();
  30243. return function update( object ) {
  30244. if ( object !== undefined ) {
  30245. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  30246. }
  30247. if ( this.object !== undefined ) {
  30248. box.setFromObject( this.object );
  30249. }
  30250. if ( box.isEmpty() ) return;
  30251. var min = box.min;
  30252. var max = box.max;
  30253. /*
  30254. 5____4
  30255. 1/___0/|
  30256. | 6__|_7
  30257. 2/___3/
  30258. 0: max.x, max.y, max.z
  30259. 1: min.x, max.y, max.z
  30260. 2: min.x, min.y, max.z
  30261. 3: max.x, min.y, max.z
  30262. 4: max.x, max.y, min.z
  30263. 5: min.x, max.y, min.z
  30264. 6: min.x, min.y, min.z
  30265. 7: max.x, min.y, min.z
  30266. */
  30267. var position = this.geometry.attributes.position;
  30268. var array = position.array;
  30269. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  30270. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  30271. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  30272. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  30273. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  30274. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  30275. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  30276. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  30277. position.needsUpdate = true;
  30278. this.geometry.computeBoundingSphere();
  30279. };
  30280. } )();
  30281. BoxHelper.prototype.setFromObject = function ( object ) {
  30282. this.object = object;
  30283. this.update();
  30284. return this;
  30285. };
  30286. /**
  30287. * @author TristanVALCKE / https://github.com/Itee
  30288. * @author Anonymous
  30289. */
  30290. /* global QUnit */
  30291. QUnit.module( 'Helpers', () => {
  30292. QUnit.module.todo( 'BoxHelper', ( hooks ) => {
  30293. var geometries = undefined;
  30294. hooks.beforeEach( function () {
  30295. const parameters = {
  30296. radius: 10,
  30297. widthSegments: 20,
  30298. heightSegments: 30,
  30299. phiStart: 0.5,
  30300. phiLength: 1.0,
  30301. thetaStart: 0.4,
  30302. thetaLength: 2.0,
  30303. };
  30304. // Test with a normal cube and a box helper
  30305. var boxGeometry = new BoxGeometry( parameters.diameter );
  30306. var box = new Mesh( boxGeometry );
  30307. var boxHelper = new BoxHelper( box );
  30308. // The same should happen with a comparable sphere
  30309. var sphereGeometry = new SphereGeometry( parameters.diameter / 2 );
  30310. var sphere = new Mesh( sphereGeometry );
  30311. var sphereBoxHelper = new BoxHelper( sphere );
  30312. // Note that unlike what I'd like to, these doesn't check the equivalency of the two generated geometries
  30313. geometries = [ boxHelper.geometry, sphereBoxHelper.geometry ];
  30314. } );
  30315. // INHERITANCE
  30316. QUnit.test( "Extending", ( assert ) => {
  30317. assert.ok( false, "everything's gonna be alright" );
  30318. } );
  30319. // INSTANCING
  30320. QUnit.test( "Instancing", ( assert ) => {
  30321. assert.ok( false, "everything's gonna be alright" );
  30322. } );
  30323. // PUBLIC STUFF
  30324. QUnit.test( "update", ( assert ) => {
  30325. assert.ok( false, "everything's gonna be alright" );
  30326. } );
  30327. QUnit.test( "setFromObject", ( assert ) => {
  30328. assert.ok( false, "everything's gonna be alright" );
  30329. } );
  30330. // OTHERS
  30331. QUnit.test( 'Standard geometry tests', ( assert ) => {
  30332. runStdGeometryTests( assert, geometries );
  30333. } );
  30334. } );
  30335. } );
  30336. /**
  30337. * @author alteredq / http://alteredqualia.com/
  30338. * @author Mugen87 / https://github.com/Mugen87
  30339. *
  30340. * - shows frustum, line of sight and up of the camera
  30341. * - suitable for fast updates
  30342. * - based on frustum visualization in lightgl.js shadowmap example
  30343. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  30344. */
  30345. function CameraHelper( camera ) {
  30346. var geometry = new BufferGeometry();
  30347. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  30348. var vertices = [];
  30349. var colors = [];
  30350. var pointMap = {};
  30351. // colors
  30352. var colorFrustum = new Color( 0xffaa00 );
  30353. var colorCone = new Color( 0xff0000 );
  30354. var colorUp = new Color( 0x00aaff );
  30355. var colorTarget = new Color( 0xffffff );
  30356. var colorCross = new Color( 0x333333 );
  30357. // near
  30358. addLine( 'n1', 'n2', colorFrustum );
  30359. addLine( 'n2', 'n4', colorFrustum );
  30360. addLine( 'n4', 'n3', colorFrustum );
  30361. addLine( 'n3', 'n1', colorFrustum );
  30362. // far
  30363. addLine( 'f1', 'f2', colorFrustum );
  30364. addLine( 'f2', 'f4', colorFrustum );
  30365. addLine( 'f4', 'f3', colorFrustum );
  30366. addLine( 'f3', 'f1', colorFrustum );
  30367. // sides
  30368. addLine( 'n1', 'f1', colorFrustum );
  30369. addLine( 'n2', 'f2', colorFrustum );
  30370. addLine( 'n3', 'f3', colorFrustum );
  30371. addLine( 'n4', 'f4', colorFrustum );
  30372. // cone
  30373. addLine( 'p', 'n1', colorCone );
  30374. addLine( 'p', 'n2', colorCone );
  30375. addLine( 'p', 'n3', colorCone );
  30376. addLine( 'p', 'n4', colorCone );
  30377. // up
  30378. addLine( 'u1', 'u2', colorUp );
  30379. addLine( 'u2', 'u3', colorUp );
  30380. addLine( 'u3', 'u1', colorUp );
  30381. // target
  30382. addLine( 'c', 't', colorTarget );
  30383. addLine( 'p', 'c', colorCross );
  30384. // cross
  30385. addLine( 'cn1', 'cn2', colorCross );
  30386. addLine( 'cn3', 'cn4', colorCross );
  30387. addLine( 'cf1', 'cf2', colorCross );
  30388. addLine( 'cf3', 'cf4', colorCross );
  30389. function addLine( a, b, color ) {
  30390. addPoint( a, color );
  30391. addPoint( b, color );
  30392. }
  30393. function addPoint( id, color ) {
  30394. vertices.push( 0, 0, 0 );
  30395. colors.push( color.r, color.g, color.b );
  30396. if ( pointMap[ id ] === undefined ) {
  30397. pointMap[ id ] = [];
  30398. }
  30399. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  30400. }
  30401. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  30402. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  30403. LineSegments.call( this, geometry, material );
  30404. this.camera = camera;
  30405. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  30406. this.matrix = camera.matrixWorld;
  30407. this.matrixAutoUpdate = false;
  30408. this.pointMap = pointMap;
  30409. this.update();
  30410. }
  30411. CameraHelper.prototype = Object.create( LineSegments.prototype );
  30412. CameraHelper.prototype.constructor = CameraHelper;
  30413. CameraHelper.prototype.update = function () {
  30414. var geometry, pointMap;
  30415. var vector = new Vector3();
  30416. var camera = new Camera();
  30417. function setPoint( point, x, y, z ) {
  30418. vector.set( x, y, z ).unproject( camera );
  30419. var points = pointMap[ point ];
  30420. if ( points !== undefined ) {
  30421. var position = geometry.getAttribute( 'position' );
  30422. for ( var i = 0, l = points.length; i < l; i ++ ) {
  30423. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  30424. }
  30425. }
  30426. }
  30427. return function update() {
  30428. geometry = this.geometry;
  30429. pointMap = this.pointMap;
  30430. var w = 1, h = 1;
  30431. // we need just camera projection matrix
  30432. // world matrix must be identity
  30433. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  30434. // center / target
  30435. setPoint( 'c', 0, 0, - 1 );
  30436. setPoint( 't', 0, 0, 1 );
  30437. // near
  30438. setPoint( 'n1', - w, - h, - 1 );
  30439. setPoint( 'n2', w, - h, - 1 );
  30440. setPoint( 'n3', - w, h, - 1 );
  30441. setPoint( 'n4', w, h, - 1 );
  30442. // far
  30443. setPoint( 'f1', - w, - h, 1 );
  30444. setPoint( 'f2', w, - h, 1 );
  30445. setPoint( 'f3', - w, h, 1 );
  30446. setPoint( 'f4', w, h, 1 );
  30447. // up
  30448. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  30449. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  30450. setPoint( 'u3', 0, h * 2, - 1 );
  30451. // cross
  30452. setPoint( 'cf1', - w, 0, 1 );
  30453. setPoint( 'cf2', w, 0, 1 );
  30454. setPoint( 'cf3', 0, - h, 1 );
  30455. setPoint( 'cf4', 0, h, 1 );
  30456. setPoint( 'cn1', - w, 0, - 1 );
  30457. setPoint( 'cn2', w, 0, - 1 );
  30458. setPoint( 'cn3', 0, - h, - 1 );
  30459. setPoint( 'cn4', 0, h, - 1 );
  30460. geometry.getAttribute( 'position' ).needsUpdate = true;
  30461. };
  30462. }();
  30463. /**
  30464. * @author TristanVALCKE / https://github.com/Itee
  30465. */
  30466. /* global QUnit */
  30467. QUnit.module( 'Helpers', () => {
  30468. QUnit.module.todo( 'CameraHelper', () => {
  30469. // INHERITANCE
  30470. QUnit.test( "Extending", ( assert ) => {
  30471. assert.ok( false, "everything's gonna be alright" );
  30472. } );
  30473. // INSTANCING
  30474. QUnit.test( "Instancing", ( assert ) => {
  30475. assert.ok( false, "everything's gonna be alright" );
  30476. } );
  30477. // PUBLIC STUFF
  30478. QUnit.test( "update", ( assert ) => {
  30479. assert.ok( false, "everything's gonna be alright" );
  30480. } );
  30481. } );
  30482. } );
  30483. /**
  30484. * @author alteredq / http://alteredqualia.com/
  30485. * @author mrdoob / http://mrdoob.com/
  30486. * @author WestLangley / http://github.com/WestLangley
  30487. */
  30488. /**
  30489. * @author TristanVALCKE / https://github.com/Itee
  30490. */
  30491. /* global QUnit */
  30492. QUnit.module( 'Helpers', () => {
  30493. QUnit.module.todo( 'DirectionalLightHelper', () => {
  30494. // INHERITANCE
  30495. QUnit.test( "Extending", ( assert ) => {
  30496. assert.ok( false, "everything's gonna be alright" );
  30497. } );
  30498. // INSTANCING
  30499. QUnit.test( "Instancing", ( assert ) => {
  30500. assert.ok( false, "everything's gonna be alright" );
  30501. } );
  30502. // PUBLIC STUFF
  30503. QUnit.test( "dispose", ( assert ) => {
  30504. assert.ok( false, "everything's gonna be alright" );
  30505. } );
  30506. QUnit.test( "update", ( assert ) => {
  30507. assert.ok( false, "everything's gonna be alright" );
  30508. } );
  30509. } );
  30510. } );
  30511. /**
  30512. * @author mrdoob / http://mrdoob.com/
  30513. * @author WestLangley / http://github.com/WestLangley
  30514. */
  30515. function FaceNormalsHelper( object, size, hex, linewidth ) {
  30516. // FaceNormalsHelper only supports THREE.Geometry
  30517. this.object = object;
  30518. this.size = ( size !== undefined ) ? size : 1;
  30519. var color = ( hex !== undefined ) ? hex : 0xffff00;
  30520. var width = ( linewidth !== undefined ) ? linewidth : 1;
  30521. //
  30522. var nNormals = 0;
  30523. var objGeometry = this.object.geometry;
  30524. if ( objGeometry && objGeometry.isGeometry ) {
  30525. nNormals = objGeometry.faces.length;
  30526. } else {
  30527. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  30528. }
  30529. //
  30530. var geometry = new BufferGeometry();
  30531. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  30532. geometry.addAttribute( 'position', positions );
  30533. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  30534. //
  30535. this.matrixAutoUpdate = false;
  30536. this.update();
  30537. }
  30538. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  30539. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  30540. FaceNormalsHelper.prototype.update = ( function () {
  30541. var v1 = new Vector3();
  30542. var v2 = new Vector3();
  30543. var normalMatrix = new Matrix3();
  30544. return function update() {
  30545. this.object.updateMatrixWorld( true );
  30546. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  30547. var matrixWorld = this.object.matrixWorld;
  30548. var position = this.geometry.attributes.position;
  30549. //
  30550. var objGeometry = this.object.geometry;
  30551. var vertices = objGeometry.vertices;
  30552. var faces = objGeometry.faces;
  30553. var idx = 0;
  30554. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  30555. var face = faces[ i ];
  30556. var normal = face.normal;
  30557. v1.copy( vertices[ face.a ] )
  30558. .add( vertices[ face.b ] )
  30559. .add( vertices[ face.c ] )
  30560. .divideScalar( 3 )
  30561. .applyMatrix4( matrixWorld );
  30562. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  30563. position.setXYZ( idx, v1.x, v1.y, v1.z );
  30564. idx = idx + 1;
  30565. position.setXYZ( idx, v2.x, v2.y, v2.z );
  30566. idx = idx + 1;
  30567. }
  30568. position.needsUpdate = true;
  30569. };
  30570. }() );
  30571. /**
  30572. * @author TristanVALCKE / https://github.com/Itee
  30573. */
  30574. /* global QUnit */
  30575. QUnit.module( 'Helpers', () => {
  30576. QUnit.module.todo( 'FaceNormalsHelper', () => {
  30577. // INHERITANCE
  30578. QUnit.test( "Extending", ( assert ) => {
  30579. assert.ok( false, "everything's gonna be alright" );
  30580. } );
  30581. // INSTANCING
  30582. QUnit.test( "Instancing", ( assert ) => {
  30583. assert.ok( false, "everything's gonna be alright" );
  30584. } );
  30585. // PUBLIC STUFF
  30586. QUnit.test( "update", ( assert ) => {
  30587. assert.ok( false, "everything's gonna be alright" );
  30588. } );
  30589. } );
  30590. } );
  30591. /**
  30592. * @author mrdoob / http://mrdoob.com/
  30593. */
  30594. /**
  30595. * @author TristanVALCKE / https://github.com/Itee
  30596. */
  30597. /* global QUnit */
  30598. QUnit.module( 'Helpers', () => {
  30599. QUnit.module.todo( 'GridHelper', () => {
  30600. // INHERITANCE
  30601. QUnit.test( "Extending", ( assert ) => {
  30602. assert.ok( false, "everything's gonna be alright" );
  30603. } );
  30604. // INSTANCING
  30605. QUnit.test( "Instancing", ( assert ) => {
  30606. assert.ok( false, "everything's gonna be alright" );
  30607. } );
  30608. } );
  30609. } );
  30610. /**
  30611. * @author alteredq / http://alteredqualia.com/
  30612. * @author mrdoob / http://mrdoob.com/
  30613. * @author Mugen87 / https://github.com/Mugen87
  30614. */
  30615. function HemisphereLightHelper( light, size, color ) {
  30616. Object3D.call( this );
  30617. this.light = light;
  30618. this.light.updateMatrixWorld();
  30619. this.matrix = light.matrixWorld;
  30620. this.matrixAutoUpdate = false;
  30621. this.color = color;
  30622. var geometry = new OctahedronBufferGeometry( size );
  30623. geometry.rotateY( Math.PI * 0.5 );
  30624. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  30625. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  30626. var position = geometry.getAttribute( 'position' );
  30627. var colors = new Float32Array( position.count * 3 );
  30628. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  30629. this.add( new Mesh( geometry, this.material ) );
  30630. this.update();
  30631. }
  30632. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  30633. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  30634. HemisphereLightHelper.prototype.dispose = function () {
  30635. this.children[ 0 ].geometry.dispose();
  30636. this.children[ 0 ].material.dispose();
  30637. };
  30638. HemisphereLightHelper.prototype.update = function () {
  30639. var vector = new Vector3();
  30640. var color1 = new Color();
  30641. var color2 = new Color();
  30642. return function update() {
  30643. var mesh = this.children[ 0 ];
  30644. if ( this.color !== undefined ) {
  30645. this.material.color.set( this.color );
  30646. } else {
  30647. var colors = mesh.geometry.getAttribute( 'color' );
  30648. color1.copy( this.light.color );
  30649. color2.copy( this.light.groundColor );
  30650. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  30651. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  30652. colors.setXYZ( i, color.r, color.g, color.b );
  30653. }
  30654. colors.needsUpdate = true;
  30655. }
  30656. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  30657. };
  30658. }();
  30659. /**
  30660. * @author TristanVALCKE / https://github.com/Itee
  30661. */
  30662. /* global QUnit */
  30663. QUnit.module( 'Helpers', () => {
  30664. QUnit.module.todo( 'HemisphereLightHelper', () => {
  30665. // INHERITANCE
  30666. QUnit.test( "Extending", ( assert ) => {
  30667. assert.ok( false, "everything's gonna be alright" );
  30668. } );
  30669. // INSTANCING
  30670. QUnit.test( "Instancing", ( assert ) => {
  30671. assert.ok( false, "everything's gonna be alright" );
  30672. } );
  30673. // PUBLIC STUFF
  30674. QUnit.test( "dispose", ( assert ) => {
  30675. assert.ok( false, "everything's gonna be alright" );
  30676. } );
  30677. QUnit.test( "update", ( assert ) => {
  30678. assert.ok( false, "everything's gonna be alright" );
  30679. } );
  30680. } );
  30681. } );
  30682. /**
  30683. * @author WestLangley / http://github.com/WestLangley
  30684. */
  30685. /**
  30686. * @author TristanVALCKE / https://github.com/Itee
  30687. */
  30688. /* global QUnit */
  30689. QUnit.module( 'Helpers', () => {
  30690. QUnit.module.todo( 'PlaneHelper', () => {
  30691. // INHERITANCE
  30692. QUnit.test( "Extending", ( assert ) => {
  30693. assert.ok( false, "everything's gonna be alright" );
  30694. } );
  30695. // INSTANCING
  30696. QUnit.test( "Instancing", ( assert ) => {
  30697. assert.ok( false, "everything's gonna be alright" );
  30698. } );
  30699. // PUBLIC STUFF
  30700. QUnit.test( "updateMatrixWorld", ( assert ) => {
  30701. assert.ok( false, "everything's gonna be alright" );
  30702. } );
  30703. } );
  30704. } );
  30705. /**
  30706. * @author alteredq / http://alteredqualia.com/
  30707. * @author mrdoob / http://mrdoob.com/
  30708. */
  30709. /**
  30710. * @author TristanVALCKE / https://github.com/Itee
  30711. */
  30712. /* global QUnit */
  30713. QUnit.module( 'Helpers', () => {
  30714. QUnit.module.todo( 'PointLightHelper', () => {
  30715. // INHERITANCE
  30716. QUnit.test( "Extending", ( assert ) => {
  30717. assert.ok( false, "everything's gonna be alright" );
  30718. } );
  30719. // INSTANCING
  30720. QUnit.test( "Instancing", ( assert ) => {
  30721. assert.ok( false, "everything's gonna be alright" );
  30722. } );
  30723. // PUBLIC STUFF
  30724. QUnit.test( "dispose", ( assert ) => {
  30725. assert.ok( false, "everything's gonna be alright" );
  30726. } );
  30727. QUnit.test( "update", ( assert ) => {
  30728. assert.ok( false, "everything's gonna be alright" );
  30729. } );
  30730. } );
  30731. } );
  30732. /**
  30733. * @author mrdoob / http://mrdoob.com/
  30734. * @author Mugen87 / http://github.com/Mugen87
  30735. * @author Hectate / http://www.github.com/Hectate
  30736. */
  30737. /**
  30738. * @author TristanVALCKE / https://github.com/Itee
  30739. */
  30740. /* global QUnit */
  30741. QUnit.module( 'Helpers', () => {
  30742. QUnit.module.todo( 'PolarGridHelper', () => {
  30743. // INHERITANCE
  30744. QUnit.test( "Extending", ( assert ) => {
  30745. assert.ok( false, "everything's gonna be alright" );
  30746. } );
  30747. // INSTANCING
  30748. QUnit.test( "Instancing", ( assert ) => {
  30749. assert.ok( false, "everything's gonna be alright" );
  30750. } );
  30751. } );
  30752. } );
  30753. /**
  30754. * @author abelnation / http://github.com/abelnation
  30755. * @author Mugen87 / http://github.com/Mugen87
  30756. * @author WestLangley / http://github.com/WestLangley
  30757. */
  30758. /**
  30759. * @author TristanVALCKE / https://github.com/Itee
  30760. */
  30761. /* global QUnit */
  30762. QUnit.module( 'Helpers', () => {
  30763. QUnit.module.todo( 'RectAreaLightHelper', () => {
  30764. // INHERITANCE
  30765. QUnit.test( "Extending", ( assert ) => {
  30766. assert.ok( false, "everything's gonna be alright" );
  30767. } );
  30768. // INSTANCING
  30769. QUnit.test( "Instancing", ( assert ) => {
  30770. assert.ok( false, "everything's gonna be alright" );
  30771. } );
  30772. // PUBLIC STUFF
  30773. QUnit.test( "dispose", ( assert ) => {
  30774. assert.ok( false, "everything's gonna be alright" );
  30775. } );
  30776. QUnit.test( "update", ( assert ) => {
  30777. assert.ok( false, "everything's gonna be alright" );
  30778. } );
  30779. } );
  30780. } );
  30781. /**
  30782. * @author Sean Griffin / http://twitter.com/sgrif
  30783. * @author Michael Guerrero / http://realitymeltdown.com
  30784. * @author mrdoob / http://mrdoob.com/
  30785. * @author ikerr / http://verold.com
  30786. * @author Mugen87 / https://github.com/Mugen87
  30787. */
  30788. function getBoneList( object ) {
  30789. var boneList = [];
  30790. if ( object && object.isBone ) {
  30791. boneList.push( object );
  30792. }
  30793. for ( var i = 0; i < object.children.length; i ++ ) {
  30794. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  30795. }
  30796. return boneList;
  30797. }
  30798. function SkeletonHelper( object ) {
  30799. var bones = getBoneList( object );
  30800. var geometry = new BufferGeometry();
  30801. var vertices = [];
  30802. var colors = [];
  30803. var color1 = new Color( 0, 0, 1 );
  30804. var color2 = new Color( 0, 1, 0 );
  30805. for ( var i = 0; i < bones.length; i ++ ) {
  30806. var bone = bones[ i ];
  30807. if ( bone.parent && bone.parent.isBone ) {
  30808. vertices.push( 0, 0, 0 );
  30809. vertices.push( 0, 0, 0 );
  30810. colors.push( color1.r, color1.g, color1.b );
  30811. colors.push( color2.r, color2.g, color2.b );
  30812. }
  30813. }
  30814. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  30815. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  30816. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  30817. LineSegments.call( this, geometry, material );
  30818. this.root = object;
  30819. this.bones = bones;
  30820. this.matrix = object.matrixWorld;
  30821. this.matrixAutoUpdate = false;
  30822. }
  30823. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  30824. SkeletonHelper.prototype.constructor = SkeletonHelper;
  30825. SkeletonHelper.prototype.updateMatrixWorld = function () {
  30826. var vector = new Vector3();
  30827. var boneMatrix = new Matrix4();
  30828. var matrixWorldInv = new Matrix4();
  30829. return function updateMatrixWorld( force ) {
  30830. var bones = this.bones;
  30831. var geometry = this.geometry;
  30832. var position = geometry.getAttribute( 'position' );
  30833. matrixWorldInv.getInverse( this.root.matrixWorld );
  30834. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  30835. var bone = bones[ i ];
  30836. if ( bone.parent && bone.parent.isBone ) {
  30837. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  30838. vector.setFromMatrixPosition( boneMatrix );
  30839. position.setXYZ( j, vector.x, vector.y, vector.z );
  30840. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  30841. vector.setFromMatrixPosition( boneMatrix );
  30842. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  30843. j += 2;
  30844. }
  30845. }
  30846. geometry.getAttribute( 'position' ).needsUpdate = true;
  30847. Object3D.prototype.updateMatrixWorld.call( this, force );
  30848. };
  30849. }();
  30850. /**
  30851. * @author TristanVALCKE / https://github.com/Itee
  30852. */
  30853. /* global QUnit */
  30854. QUnit.module( 'Helpers', () => {
  30855. QUnit.module.todo( 'SkeletonHelper', () => {
  30856. // INHERITANCE
  30857. QUnit.test( "Extending", ( assert ) => {
  30858. assert.ok( false, "everything's gonna be alright" );
  30859. } );
  30860. // INSTANCING
  30861. QUnit.test( "Instancing", ( assert ) => {
  30862. assert.ok( false, "everything's gonna be alright" );
  30863. } );
  30864. // PUBLIC STUFF
  30865. QUnit.test( "updateMatrixWorld", ( assert ) => {
  30866. assert.ok( false, "everything's gonna be alright" );
  30867. } );
  30868. } );
  30869. } );
  30870. /**
  30871. * @author alteredq / http://alteredqualia.com/
  30872. * @author mrdoob / http://mrdoob.com/
  30873. * @author WestLangley / http://github.com/WestLangley
  30874. */
  30875. /**
  30876. * @author TristanVALCKE / https://github.com/Itee
  30877. */
  30878. /* global QUnit */
  30879. QUnit.module( 'Helpers', () => {
  30880. QUnit.module.todo( 'SpotLightHelper', () => {
  30881. // INHERITANCE
  30882. QUnit.test( "Extending", ( assert ) => {
  30883. assert.ok( false, "everything's gonna be alright" );
  30884. } );
  30885. // INSTANCING
  30886. QUnit.test( "Instancing", ( assert ) => {
  30887. assert.ok( false, "everything's gonna be alright" );
  30888. } );
  30889. // PUBLIC STUFF
  30890. QUnit.test( "dispose", ( assert ) => {
  30891. assert.ok( false, "everything's gonna be alright" );
  30892. } );
  30893. QUnit.test( "update", ( assert ) => {
  30894. assert.ok( false, "everything's gonna be alright" );
  30895. } );
  30896. } );
  30897. } );
  30898. /**
  30899. * @author mrdoob / http://mrdoob.com/
  30900. * @author WestLangley / http://github.com/WestLangley
  30901. */
  30902. function VertexNormalsHelper( object, size, hex, linewidth ) {
  30903. this.object = object;
  30904. this.size = ( size !== undefined ) ? size : 1;
  30905. var color = ( hex !== undefined ) ? hex : 0xff0000;
  30906. var width = ( linewidth !== undefined ) ? linewidth : 1;
  30907. //
  30908. var nNormals = 0;
  30909. var objGeometry = this.object.geometry;
  30910. if ( objGeometry && objGeometry.isGeometry ) {
  30911. nNormals = objGeometry.faces.length * 3;
  30912. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  30913. nNormals = objGeometry.attributes.normal.count;
  30914. }
  30915. //
  30916. var geometry = new BufferGeometry();
  30917. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  30918. geometry.addAttribute( 'position', positions );
  30919. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  30920. //
  30921. this.matrixAutoUpdate = false;
  30922. this.update();
  30923. }
  30924. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  30925. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  30926. VertexNormalsHelper.prototype.update = ( function () {
  30927. var v1 = new Vector3();
  30928. var v2 = new Vector3();
  30929. var normalMatrix = new Matrix3();
  30930. return function update() {
  30931. var keys = [ 'a', 'b', 'c' ];
  30932. this.object.updateMatrixWorld( true );
  30933. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  30934. var matrixWorld = this.object.matrixWorld;
  30935. var position = this.geometry.attributes.position;
  30936. //
  30937. var objGeometry = this.object.geometry;
  30938. if ( objGeometry && objGeometry.isGeometry ) {
  30939. var vertices = objGeometry.vertices;
  30940. var faces = objGeometry.faces;
  30941. var idx = 0;
  30942. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  30943. var face = faces[ i ];
  30944. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  30945. var vertex = vertices[ face[ keys[ j ] ] ];
  30946. var normal = face.vertexNormals[ j ];
  30947. v1.copy( vertex ).applyMatrix4( matrixWorld );
  30948. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  30949. position.setXYZ( idx, v1.x, v1.y, v1.z );
  30950. idx = idx + 1;
  30951. position.setXYZ( idx, v2.x, v2.y, v2.z );
  30952. idx = idx + 1;
  30953. }
  30954. }
  30955. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  30956. var objPos = objGeometry.attributes.position;
  30957. var objNorm = objGeometry.attributes.normal;
  30958. var idx = 0;
  30959. // for simplicity, ignore index and drawcalls, and render every normal
  30960. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  30961. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  30962. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  30963. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  30964. position.setXYZ( idx, v1.x, v1.y, v1.z );
  30965. idx = idx + 1;
  30966. position.setXYZ( idx, v2.x, v2.y, v2.z );
  30967. idx = idx + 1;
  30968. }
  30969. }
  30970. position.needsUpdate = true;
  30971. };
  30972. }() );
  30973. /**
  30974. * @author TristanVALCKE / https://github.com/Itee
  30975. */
  30976. /* global QUnit */
  30977. QUnit.module( 'Helpers', () => {
  30978. QUnit.module.todo( 'VertexNormalsHelper', () => {
  30979. // INHERITANCE
  30980. QUnit.test( "Extending", ( assert ) => {
  30981. assert.ok( false, "everything's gonna be alright" );
  30982. } );
  30983. // INSTANCING
  30984. QUnit.test( "Instancing", ( assert ) => {
  30985. assert.ok( false, "everything's gonna be alright" );
  30986. } );
  30987. // PUBLIC STUFF
  30988. QUnit.test( "update", ( assert ) => {
  30989. assert.ok( false, "everything's gonna be alright" );
  30990. } );
  30991. } );
  30992. } );
  30993. /**
  30994. * @author mrdoob / http://mrdoob.com/
  30995. * @author alteredq / http://alteredqualia.com/
  30996. */
  30997. function Light( color, intensity ) {
  30998. Object3D.call( this );
  30999. this.type = 'Light';
  31000. this.color = new Color( color );
  31001. this.intensity = intensity !== undefined ? intensity : 1;
  31002. this.receiveShadow = undefined;
  31003. }
  31004. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  31005. constructor: Light,
  31006. isLight: true,
  31007. copy: function ( source ) {
  31008. Object3D.prototype.copy.call( this, source );
  31009. this.color.copy( source.color );
  31010. this.intensity = source.intensity;
  31011. return this;
  31012. },
  31013. toJSON: function ( meta ) {
  31014. var data = Object3D.prototype.toJSON.call( this, meta );
  31015. data.object.color = this.color.getHex();
  31016. data.object.intensity = this.intensity;
  31017. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  31018. if ( this.distance !== undefined ) data.object.distance = this.distance;
  31019. if ( this.angle !== undefined ) data.object.angle = this.angle;
  31020. if ( this.decay !== undefined ) data.object.decay = this.decay;
  31021. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  31022. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  31023. return data;
  31024. }
  31025. } );
  31026. /**
  31027. * @author mrdoob / http://mrdoob.com/
  31028. */
  31029. function AmbientLight( color, intensity ) {
  31030. Light.call( this, color, intensity );
  31031. this.type = 'AmbientLight';
  31032. this.castShadow = undefined;
  31033. }
  31034. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  31035. constructor: AmbientLight,
  31036. isAmbientLight: true
  31037. } );
  31038. /**
  31039. * @author TristanVALCKE / https://github.com/Itee
  31040. * @author moraxy / https://github.com/moraxy
  31041. */
  31042. /* global QUnit */
  31043. QUnit.module( 'Lights', () => {
  31044. QUnit.module.todo( 'ArrowHelper', ( hooks ) => {
  31045. var lights = undefined;
  31046. hooks.beforeEach( function () {
  31047. const parameters = {
  31048. color: 0xaaaaaa,
  31049. intensity: 0.5
  31050. };
  31051. lights = [
  31052. new AmbientLight(),
  31053. new AmbientLight( parameters.color ),
  31054. new AmbientLight( parameters.color, parameters.intensity )
  31055. ];
  31056. } );
  31057. // INHERITANCE
  31058. QUnit.test( "Extending", ( assert ) => {
  31059. assert.ok( false, "everything's gonna be alright" );
  31060. } );
  31061. // INSTANCING
  31062. QUnit.test( "Instancing", ( assert ) => {
  31063. assert.ok( false, "everything's gonna be alright" );
  31064. } );
  31065. // PUBLIC STUFF
  31066. QUnit.test( "isAmbiantLight", ( assert ) => {
  31067. assert.ok( false, "everything's gonna be alright" );
  31068. } );
  31069. // OTHERS
  31070. QUnit.test( 'Standard light tests', ( assert ) => {
  31071. runStdLightTests( assert, lights );
  31072. } );
  31073. } );
  31074. } );
  31075. /**
  31076. * @author mrdoob / http://mrdoob.com/
  31077. */
  31078. function LightShadow( camera ) {
  31079. this.camera = camera;
  31080. this.bias = 0;
  31081. this.radius = 1;
  31082. this.mapSize = new Vector2( 512, 512 );
  31083. this.map = null;
  31084. this.matrix = new Matrix4();
  31085. }
  31086. Object.assign( LightShadow.prototype, {
  31087. copy: function ( source ) {
  31088. this.camera = source.camera.clone();
  31089. this.bias = source.bias;
  31090. this.radius = source.radius;
  31091. this.mapSize.copy( source.mapSize );
  31092. return this;
  31093. },
  31094. clone: function () {
  31095. return new this.constructor().copy( this );
  31096. },
  31097. toJSON: function () {
  31098. var object = {};
  31099. if ( this.bias !== 0 ) object.bias = this.bias;
  31100. if ( this.radius !== 1 ) object.radius = this.radius;
  31101. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  31102. object.camera = this.camera.toJSON( false ).object;
  31103. delete object.camera.matrix;
  31104. return object;
  31105. }
  31106. } );
  31107. /**
  31108. * @author mrdoob / http://mrdoob.com/
  31109. */
  31110. function DirectionalLightShadow( ) {
  31111. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  31112. }
  31113. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  31114. constructor: DirectionalLightShadow
  31115. } );
  31116. /**
  31117. * @author mrdoob / http://mrdoob.com/
  31118. * @author alteredq / http://alteredqualia.com/
  31119. */
  31120. function DirectionalLight$1( color, intensity ) {
  31121. Light.call( this, color, intensity );
  31122. this.type = 'DirectionalLight';
  31123. this.position.copy( Object3D.DefaultUp );
  31124. this.updateMatrix();
  31125. this.target = new Object3D();
  31126. this.shadow = new DirectionalLightShadow();
  31127. }
  31128. DirectionalLight$1.prototype = Object.assign( Object.create( Light.prototype ), {
  31129. constructor: DirectionalLight$1,
  31130. isDirectionalLight: true,
  31131. copy: function ( source ) {
  31132. Light.prototype.copy.call( this, source );
  31133. this.target = source.target.clone();
  31134. this.shadow = source.shadow.clone();
  31135. return this;
  31136. }
  31137. } );
  31138. /**
  31139. * @author TristanVALCKE / https://github.com/Itee
  31140. * @author moraxy / https://github.com/moraxy
  31141. */
  31142. /* global QUnit */
  31143. QUnit.module( 'Lights', () => {
  31144. QUnit.module.todo( 'DirectionalLight', ( hooks ) => {
  31145. var lights = undefined;
  31146. hooks.beforeEach( function () {
  31147. const parameters = {
  31148. color: 0xaaaaaa,
  31149. intensity: 0.8
  31150. };
  31151. lights = [
  31152. new DirectionalLight$1(),
  31153. new DirectionalLight$1( parameters.color ),
  31154. new DirectionalLight$1( parameters.color, parameters.intensity )
  31155. ];
  31156. } );
  31157. // INHERITANCE
  31158. QUnit.test( "Extending", ( assert ) => {
  31159. assert.ok( false, "everything's gonna be alright" );
  31160. } );
  31161. // INSTANCING
  31162. QUnit.test( "Instancing", ( assert ) => {
  31163. assert.ok( false, "everything's gonna be alright" );
  31164. } );
  31165. // PUBLIC STUFF
  31166. QUnit.test( "isDirectionalLight", ( assert ) => {
  31167. assert.ok( false, "everything's gonna be alright" );
  31168. } );
  31169. QUnit.test( "copy", ( assert ) => {
  31170. assert.ok( false, "everything's gonna be alright" );
  31171. } );
  31172. // OTHERS
  31173. QUnit.test( 'Standard light tests', ( assert ) => {
  31174. runStdLightTests( assert, lights );
  31175. } );
  31176. } );
  31177. } );
  31178. /**
  31179. * @author TristanVALCKE / https://github.com/Itee
  31180. * @author moraxy / https://github.com/moraxy
  31181. */
  31182. /* global QUnit */
  31183. QUnit.module( 'Lights', () => {
  31184. QUnit.module.todo( 'DirectionalLightShadow', () => {
  31185. // INHERITANCE
  31186. QUnit.test( "Extending", ( assert ) => {
  31187. assert.ok( false, "everything's gonna be alright" );
  31188. } );
  31189. // INSTANCING
  31190. QUnit.test( "Instancing", ( assert ) => {
  31191. assert.ok( false, "everything's gonna be alright" );
  31192. } );
  31193. // OTHERS
  31194. QUnit.test( "clone/copy", ( assert ) => {
  31195. var a = new DirectionalLightShadow();
  31196. var b = new DirectionalLightShadow();
  31197. var c;
  31198. assert.notDeepEqual( a, b, "Newly instanced shadows are not equal" );
  31199. c = a.clone();
  31200. assert.smartEqual( a, c, "Shadows are identical after clone()" );
  31201. c.mapSize.set( 1024, 1024 );
  31202. assert.notDeepEqual( a, c, "Shadows are different again after change" );
  31203. b.copy( a );
  31204. assert.smartEqual( a, b, "Shadows are identical after copy()" );
  31205. b.mapSize.set( 512, 512 );
  31206. assert.notDeepEqual( a, b, "Shadows are different again after change" );
  31207. } );
  31208. QUnit.test( "toJSON", ( assert ) => {
  31209. var light = new DirectionalLight();
  31210. var shadow = new DirectionalLightShadow();
  31211. shadow.bias = 10;
  31212. shadow.radius = 5;
  31213. shadow.mapSize.set( 1024, 1024 );
  31214. light.shadow = shadow;
  31215. var json = light.toJSON();
  31216. var newLight = new ObjectLoader().parse( json );
  31217. assert.smartEqual( newLight.shadow, light.shadow, "Reloaded shadow is identical to the original one" );
  31218. } );
  31219. } );
  31220. } );
  31221. /**
  31222. * @author alteredq / http://alteredqualia.com/
  31223. */
  31224. function HemisphereLight( skyColor, groundColor, intensity ) {
  31225. Light.call( this, skyColor, intensity );
  31226. this.type = 'HemisphereLight';
  31227. this.castShadow = undefined;
  31228. this.position.copy( Object3D.DefaultUp );
  31229. this.updateMatrix();
  31230. this.groundColor = new Color( groundColor );
  31231. }
  31232. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  31233. constructor: HemisphereLight,
  31234. isHemisphereLight: true,
  31235. copy: function ( source ) {
  31236. Light.prototype.copy.call( this, source );
  31237. this.groundColor.copy( source.groundColor );
  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( 'HemisphereLight', ( hooks ) => {
  31248. var lights = undefined;
  31249. hooks.beforeEach( function () {
  31250. const parameters = {
  31251. skyColor: 0x123456,
  31252. groundColor: 0xabc012,
  31253. intensity: 0.6
  31254. };
  31255. lights = [
  31256. new HemisphereLight(),
  31257. new HemisphereLight( parameters.skyColor ),
  31258. new HemisphereLight( parameters.skyColor, parameters.groundColor ),
  31259. new HemisphereLight( parameters.skyColor, parameters.groundColor, parameters.intensity ),
  31260. ];
  31261. } );
  31262. // INHERITANCE
  31263. QUnit.test( "Extending", ( assert ) => {
  31264. assert.ok( false, "everything's gonna be alright" );
  31265. } );
  31266. // INSTANCING
  31267. QUnit.test( "Instancing", ( assert ) => {
  31268. assert.ok( false, "everything's gonna be alright" );
  31269. } );
  31270. // PUBLIC STUFF
  31271. QUnit.test( "isHemisphereLight", ( assert ) => {
  31272. assert.ok( false, "everything's gonna be alright" );
  31273. } );
  31274. QUnit.test( "copy", ( assert ) => {
  31275. assert.ok( false, "everything's gonna be alright" );
  31276. } );
  31277. // OTHERS
  31278. QUnit.test( 'Standard light tests', ( assert ) => {
  31279. runStdLightTests( assert, lights );
  31280. } );
  31281. } );
  31282. } );
  31283. /**
  31284. * @author TristanVALCKE / https://github.com/Itee
  31285. */
  31286. /* global QUnit */
  31287. QUnit.module( 'Lights', () => {
  31288. QUnit.module.todo( 'Light', ( hooks ) => {
  31289. var lights = undefined;
  31290. hooks.beforeEach( function () {
  31291. const parameters = {
  31292. color: 0xaaaaaa,
  31293. intensity: 0.5
  31294. };
  31295. lights = [
  31296. new Light(),
  31297. new Light( parameters.color ),
  31298. new Light( parameters.color, parameters.intensity )
  31299. ];
  31300. } );
  31301. // INHERITANCE
  31302. QUnit.test( "Extending", ( assert ) => {
  31303. assert.ok( false, "everything's gonna be alright" );
  31304. } );
  31305. // INSTANCING
  31306. QUnit.test( "Instancing", ( assert ) => {
  31307. assert.ok( false, "everything's gonna be alright" );
  31308. } );
  31309. // PUBLIC STUFF
  31310. QUnit.test( "isLight", ( assert ) => {
  31311. assert.ok( false, "everything's gonna be alright" );
  31312. } );
  31313. QUnit.test( "copy", ( assert ) => {
  31314. assert.ok( false, "everything's gonna be alright" );
  31315. } );
  31316. QUnit.test( "toJSON", ( assert ) => {
  31317. assert.ok( false, "everything's gonna be alright" );
  31318. } );
  31319. // OTHERS
  31320. QUnit.test( 'Standard light tests', ( assert ) => {
  31321. runStdLightTests( assert, lights );
  31322. } );
  31323. } );
  31324. } );
  31325. /**
  31326. * @author TristanVALCKE / https://github.com/Itee
  31327. * @author moraxy / https://github.com/moraxy
  31328. */
  31329. /* global QUnit */
  31330. QUnit.module( 'Lights', () => {
  31331. QUnit.module.todo( 'LightShadow', () => {
  31332. // INSTANCING
  31333. QUnit.test( "Instancing", ( assert ) => {
  31334. assert.ok( false, "everything's gonna be alright" );
  31335. } );
  31336. // PUBLIC STUFF
  31337. QUnit.test( "clone/copy", ( assert ) => {
  31338. var a = new LightShadow( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  31339. var b = new LightShadow( new OrthographicCamera( - 3, 3, 3, - 3, 0.3, 300 ) );
  31340. var c;
  31341. assert.notDeepEqual( a, b, "Newly instanced shadows are not equal" );
  31342. c = a.clone();
  31343. assert.smartEqual( a, c, "Shadows are identical after clone()" );
  31344. c.mapSize.set( 256, 256 );
  31345. assert.notDeepEqual( a, c, "Shadows are different again after change" );
  31346. b.copy( a );
  31347. assert.smartEqual( a, b, "Shadows are identical after copy()" );
  31348. b.mapSize.set( 512, 512 );
  31349. assert.notDeepEqual( a, b, "Shadows are different again after change" );
  31350. } );
  31351. QUnit.test( "toJSON", ( assert ) => {
  31352. assert.ok( false, "everything's gonna be alright" );
  31353. } );
  31354. } );
  31355. } );
  31356. /**
  31357. * @author mrdoob / http://mrdoob.com/
  31358. */
  31359. function PointLight( color, intensity, distance, decay ) {
  31360. Light.call( this, color, intensity );
  31361. this.type = 'PointLight';
  31362. Object.defineProperty( this, 'power', {
  31363. get: function () {
  31364. // intensity = power per solid angle.
  31365. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  31366. return this.intensity * 4 * Math.PI;
  31367. },
  31368. set: function ( power ) {
  31369. // intensity = power per solid angle.
  31370. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  31371. this.intensity = power / ( 4 * Math.PI );
  31372. }
  31373. } );
  31374. this.distance = ( distance !== undefined ) ? distance : 0;
  31375. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  31376. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  31377. }
  31378. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  31379. constructor: PointLight,
  31380. isPointLight: true,
  31381. copy: function ( source ) {
  31382. Light.prototype.copy.call( this, source );
  31383. this.distance = source.distance;
  31384. this.decay = source.decay;
  31385. this.shadow = source.shadow.clone();
  31386. return this;
  31387. }
  31388. } );
  31389. /**
  31390. * @author TristanVALCKE / https://github.com/Itee
  31391. * @author moraxy / https://github.com/moraxy
  31392. */
  31393. /* global QUnit */
  31394. QUnit.module( 'Lights', () => {
  31395. QUnit.module.todo( 'PointLight', ( hooks ) => {
  31396. var lights = undefined;
  31397. hooks.beforeEach( function () {
  31398. const parameters = {
  31399. color: 0xaaaaaa,
  31400. intensity: 0.5,
  31401. distance: 100,
  31402. decay: 2
  31403. };
  31404. lights = [
  31405. new PointLight(),
  31406. new PointLight( parameters.color ),
  31407. new PointLight( parameters.color, parameters.intensity ),
  31408. new PointLight( parameters.color, parameters.intensity, parameters.distance ),
  31409. new PointLight( parameters.color, parameters.intensity, parameters.distance, parameters.decay )
  31410. ];
  31411. } );
  31412. // INHERITANCE
  31413. QUnit.test( "Extending", ( assert ) => {
  31414. assert.ok( false, "everything's gonna be alright" );
  31415. } );
  31416. // INSTANCING
  31417. QUnit.test( "Instancing", ( assert ) => {
  31418. assert.ok( false, "everything's gonna be alright" );
  31419. } );
  31420. // PROPERTIES
  31421. QUnit.test( "power", ( assert ) => {
  31422. var a = new PointLight( 0xaaaaaa );
  31423. a.intensity = 100;
  31424. assert.numEqual( a.power, 100 * Math.PI * 4, "Correct power for an intensity of 100" );
  31425. a.intensity = 40;
  31426. assert.numEqual( a.power, 40 * Math.PI * 4, "Correct power for an intensity of 40" );
  31427. a.power = 100;
  31428. assert.numEqual( a.intensity, 100 / ( 4 * Math.PI ), "Correct intensity for a power of 100" );
  31429. } );
  31430. // PUBLIC STUFF
  31431. QUnit.test( "isPointLight", ( assert ) => {
  31432. assert.ok( false, "everything's gonna be alright" );
  31433. } );
  31434. QUnit.test( "copy", ( assert ) => {
  31435. assert.ok( false, "everything's gonna be alright" );
  31436. } );
  31437. // OTHERS
  31438. QUnit.test( 'Standard light tests', ( assert ) => {
  31439. runStdLightTests( assert, lights );
  31440. } );
  31441. } );
  31442. } );
  31443. /**
  31444. * @author abelnation / http://github.com/abelnation
  31445. */
  31446. function RectAreaLight( color, intensity, width, height ) {
  31447. Light.call( this, color, intensity );
  31448. this.type = 'RectAreaLight';
  31449. this.position.set( 0, 1, 0 );
  31450. this.updateMatrix();
  31451. this.width = ( width !== undefined ) ? width : 10;
  31452. this.height = ( height !== undefined ) ? height : 10;
  31453. // TODO (abelnation): distance/decay
  31454. // TODO (abelnation): update method for RectAreaLight to update transform to lookat target
  31455. // TODO (abelnation): shadows
  31456. }
  31457. // TODO (abelnation): RectAreaLight update when light shape is changed
  31458. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  31459. constructor: RectAreaLight,
  31460. isRectAreaLight: true,
  31461. copy: function ( source ) {
  31462. Light.prototype.copy.call( this, source );
  31463. this.width = source.width;
  31464. this.height = source.height;
  31465. return this;
  31466. },
  31467. toJSON: function ( meta ) {
  31468. var data = Light.prototype.toJSON.call( this, meta );
  31469. data.object.width = this.width;
  31470. data.object.height = this.height;
  31471. return data;
  31472. }
  31473. } );
  31474. /**
  31475. * @author TristanVALCKE / https://github.com/Itee
  31476. * @author moraxy / https://github.com/moraxy
  31477. */
  31478. /* global QUnit */
  31479. QUnit.module( 'Lights', () => {
  31480. QUnit.module.todo( 'RectAreaLight', ( hooks ) => {
  31481. var lights = undefined;
  31482. hooks.beforeEach( function () {
  31483. const parameters = {
  31484. color: 0xaaaaaa,
  31485. intensity: 0.5,
  31486. width: 100,
  31487. height: 50
  31488. };
  31489. lights = [
  31490. new RectAreaLight( parameters.color ),
  31491. new RectAreaLight( parameters.color, parameters.intensity ),
  31492. new RectAreaLight( parameters.color, parameters.intensity, parameters.width ),
  31493. new RectAreaLight( parameters.color, parameters.intensity, parameters.width, parameters.height )
  31494. ];
  31495. } );
  31496. // INHERITANCE
  31497. QUnit.test( "Extending", ( assert ) => {
  31498. assert.ok( false, "everything's gonna be alright" );
  31499. } );
  31500. // INSTANCING
  31501. QUnit.test( "Instancing", ( assert ) => {
  31502. assert.ok( false, "everything's gonna be alright" );
  31503. } );
  31504. // PUBLIC STUFF
  31505. QUnit.test( "isRectAreaLight", ( assert ) => {
  31506. assert.ok( false, "everything's gonna be alright" );
  31507. } );
  31508. QUnit.test( "copy", ( assert ) => {
  31509. assert.ok( false, "everything's gonna be alright" );
  31510. } );
  31511. QUnit.test( "toJSON", ( assert ) => {
  31512. assert.ok( false, "everything's gonna be alright" );
  31513. } );
  31514. // OTHERS
  31515. QUnit.test( 'Standard light tests', ( assert ) => {
  31516. runStdLightTests( assert, lights );
  31517. } );
  31518. } );
  31519. } );
  31520. /**
  31521. * @author mrdoob / http://mrdoob.com/
  31522. */
  31523. function SpotLightShadow() {
  31524. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  31525. }
  31526. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  31527. constructor: SpotLightShadow,
  31528. isSpotLightShadow: true,
  31529. update: function ( light ) {
  31530. var camera = this.camera;
  31531. var fov = _Math.RAD2DEG * 2 * light.angle;
  31532. var aspect = this.mapSize.width / this.mapSize.height;
  31533. var far = light.distance || camera.far;
  31534. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  31535. camera.fov = fov;
  31536. camera.aspect = aspect;
  31537. camera.far = far;
  31538. camera.updateProjectionMatrix();
  31539. }
  31540. }
  31541. } );
  31542. /**
  31543. * @author alteredq / http://alteredqualia.com/
  31544. */
  31545. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  31546. Light.call( this, color, intensity );
  31547. this.type = 'SpotLight';
  31548. this.position.copy( Object3D.DefaultUp );
  31549. this.updateMatrix();
  31550. this.target = new Object3D();
  31551. Object.defineProperty( this, 'power', {
  31552. get: function () {
  31553. // intensity = power per solid angle.
  31554. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  31555. return this.intensity * Math.PI;
  31556. },
  31557. set: function ( power ) {
  31558. // intensity = power per solid angle.
  31559. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  31560. this.intensity = power / Math.PI;
  31561. }
  31562. } );
  31563. this.distance = ( distance !== undefined ) ? distance : 0;
  31564. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  31565. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  31566. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  31567. this.shadow = new SpotLightShadow();
  31568. }
  31569. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  31570. constructor: SpotLight,
  31571. isSpotLight: true,
  31572. copy: function ( source ) {
  31573. Light.prototype.copy.call( this, source );
  31574. this.distance = source.distance;
  31575. this.angle = source.angle;
  31576. this.penumbra = source.penumbra;
  31577. this.decay = source.decay;
  31578. this.target = source.target.clone();
  31579. this.shadow = source.shadow.clone();
  31580. return this;
  31581. }
  31582. } );
  31583. /**
  31584. * @author TristanVALCKE / https://github.com/Itee
  31585. * @author moraxy / https://github.com/moraxy
  31586. */
  31587. /* global QUnit */
  31588. QUnit.module( 'Lights', () => {
  31589. QUnit.module.todo( 'SpotLight', ( hooks ) => {
  31590. var lights = undefined;
  31591. hooks.beforeEach( function () {
  31592. const parameters = {
  31593. color: 0xaaaaaa,
  31594. intensity: 0.5,
  31595. distance: 100,
  31596. angle: 0.8,
  31597. penumbra: 8,
  31598. decay: 2
  31599. };
  31600. lights = [
  31601. new SpotLight( parameters.color ),
  31602. new SpotLight( parameters.color, parameters.intensity ),
  31603. new SpotLight( parameters.color, parameters.intensity, parameters.distance ),
  31604. new SpotLight( parameters.color, parameters.intensity, parameters.distance, parameters.angle ),
  31605. new SpotLight( parameters.color, parameters.intensity, parameters.distance, parameters.angle, parameters.penumbra ),
  31606. new SpotLight( parameters.color, parameters.intensity, parameters.distance, parameters.angle, parameters.penumbra, parameters.decay ),
  31607. ];
  31608. } );
  31609. // INHERITANCE
  31610. QUnit.test( "Extending", ( assert ) => {
  31611. assert.ok( false, "everything's gonna be alright" );
  31612. } );
  31613. // INSTANCING
  31614. QUnit.test( "Instancing", ( assert ) => {
  31615. assert.ok( false, "everything's gonna be alright" );
  31616. } );
  31617. // PROPERTIES
  31618. QUnit.test( "power", ( assert ) => {
  31619. var a = new SpotLight( 0xaaaaaa );
  31620. a.intensity = 100;
  31621. assert.numEqual( a.power, 100 * Math.PI, "Correct power for an intensity of 100" );
  31622. a.intensity = 40;
  31623. assert.numEqual( a.power, 40 * Math.PI, "Correct power for an intensity of 40" );
  31624. a.power = 100;
  31625. assert.numEqual( a.intensity, 100 / Math.PI, "Correct intensity for a power of 100" );
  31626. } );
  31627. // PUBLIC STUFF
  31628. QUnit.test( "isSpotLight", ( assert ) => {
  31629. assert.ok( false, "everything's gonna be alright" );
  31630. } );
  31631. QUnit.test( "copy", ( assert ) => {
  31632. assert.ok( false, "everything's gonna be alright" );
  31633. } );
  31634. // OTHERS
  31635. QUnit.test( 'Standard light tests', ( assert ) => {
  31636. runStdLightTests( assert, lights );
  31637. } );
  31638. } );
  31639. } );
  31640. /**
  31641. * @author mikael emtinger / http://gomo.se/
  31642. * @author alteredq / http://alteredqualia.com/
  31643. */
  31644. function Sprite( material ) {
  31645. Object3D.call( this );
  31646. this.type = 'Sprite';
  31647. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  31648. }
  31649. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  31650. constructor: Sprite,
  31651. isSprite: true,
  31652. raycast: ( function () {
  31653. var intersectPoint = new Vector3();
  31654. var worldPosition = new Vector3();
  31655. var worldScale = new Vector3();
  31656. return function raycast( raycaster, intersects ) {
  31657. worldPosition.setFromMatrixPosition( this.matrixWorld );
  31658. raycaster.ray.closestPointToPoint( worldPosition, intersectPoint );
  31659. worldScale.setFromMatrixScale( this.matrixWorld );
  31660. var guessSizeSq = worldScale.x * worldScale.y / 4;
  31661. if ( worldPosition.distanceToSquared( intersectPoint ) > guessSizeSq ) return;
  31662. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  31663. if ( distance < raycaster.near || distance > raycaster.far ) return;
  31664. intersects.push( {
  31665. distance: distance,
  31666. point: intersectPoint.clone(),
  31667. face: null,
  31668. object: this
  31669. } );
  31670. };
  31671. }() ),
  31672. clone: function () {
  31673. return new this.constructor( this.material ).copy( this );
  31674. }
  31675. } );
  31676. /**
  31677. * @author alteredq / http://alteredqualia.com/
  31678. */
  31679. function Points( geometry, material ) {
  31680. Object3D.call( this );
  31681. this.type = 'Points';
  31682. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  31683. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  31684. }
  31685. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  31686. constructor: Points,
  31687. isPoints: true,
  31688. raycast: ( function () {
  31689. var inverseMatrix = new Matrix4();
  31690. var ray = new Ray();
  31691. var sphere = new Sphere();
  31692. return function raycast( raycaster, intersects ) {
  31693. var object = this;
  31694. var geometry = this.geometry;
  31695. var matrixWorld = this.matrixWorld;
  31696. var threshold = raycaster.params.Points.threshold;
  31697. // Checking boundingSphere distance to ray
  31698. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  31699. sphere.copy( geometry.boundingSphere );
  31700. sphere.applyMatrix4( matrixWorld );
  31701. sphere.radius += threshold;
  31702. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  31703. //
  31704. inverseMatrix.getInverse( matrixWorld );
  31705. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  31706. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  31707. var localThresholdSq = localThreshold * localThreshold;
  31708. var position = new Vector3();
  31709. function testPoint( point, index ) {
  31710. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  31711. if ( rayPointDistanceSq < localThresholdSq ) {
  31712. var intersectPoint = ray.closestPointToPoint( point );
  31713. intersectPoint.applyMatrix4( matrixWorld );
  31714. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  31715. if ( distance < raycaster.near || distance > raycaster.far ) return;
  31716. intersects.push( {
  31717. distance: distance,
  31718. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  31719. point: intersectPoint.clone(),
  31720. index: index,
  31721. face: null,
  31722. object: object
  31723. } );
  31724. }
  31725. }
  31726. if ( geometry.isBufferGeometry ) {
  31727. var index = geometry.index;
  31728. var attributes = geometry.attributes;
  31729. var positions = attributes.position.array;
  31730. if ( index !== null ) {
  31731. var indices = index.array;
  31732. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  31733. var a = indices[ i ];
  31734. position.fromArray( positions, a * 3 );
  31735. testPoint( position, a );
  31736. }
  31737. } else {
  31738. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  31739. position.fromArray( positions, i * 3 );
  31740. testPoint( position, i );
  31741. }
  31742. }
  31743. } else {
  31744. var vertices = geometry.vertices;
  31745. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  31746. testPoint( vertices[ i ], i );
  31747. }
  31748. }
  31749. };
  31750. }() ),
  31751. clone: function () {
  31752. return new this.constructor( this.geometry, this.material ).copy( this );
  31753. }
  31754. } );
  31755. /**
  31756. * @author mgreter / http://github.com/mgreter
  31757. */
  31758. function LineLoop( geometry, material ) {
  31759. Line.call( this, geometry, material );
  31760. this.type = 'LineLoop';
  31761. }
  31762. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  31763. constructor: LineLoop,
  31764. isLineLoop: true,
  31765. } );
  31766. /**
  31767. * @author mikael emtinger / http://gomo.se/
  31768. * @author alteredq / http://alteredqualia.com/
  31769. * @author mrdoob / http://mrdoob.com/
  31770. */
  31771. function LOD() {
  31772. Object3D.call( this );
  31773. this.type = 'LOD';
  31774. Object.defineProperties( this, {
  31775. levels: {
  31776. enumerable: true,
  31777. value: []
  31778. }
  31779. } );
  31780. }
  31781. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  31782. constructor: LOD,
  31783. copy: function ( source ) {
  31784. Object3D.prototype.copy.call( this, source, false );
  31785. var levels = source.levels;
  31786. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  31787. var level = levels[ i ];
  31788. this.addLevel( level.object.clone(), level.distance );
  31789. }
  31790. return this;
  31791. },
  31792. addLevel: function ( object, distance ) {
  31793. if ( distance === undefined ) distance = 0;
  31794. distance = Math.abs( distance );
  31795. var levels = this.levels;
  31796. for ( var l = 0; l < levels.length; l ++ ) {
  31797. if ( distance < levels[ l ].distance ) {
  31798. break;
  31799. }
  31800. }
  31801. levels.splice( l, 0, { distance: distance, object: object } );
  31802. this.add( object );
  31803. },
  31804. getObjectForDistance: function ( distance ) {
  31805. var levels = this.levels;
  31806. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  31807. if ( distance < levels[ i ].distance ) {
  31808. break;
  31809. }
  31810. }
  31811. return levels[ i - 1 ].object;
  31812. },
  31813. raycast: ( function () {
  31814. var matrixPosition = new Vector3();
  31815. return function raycast( raycaster, intersects ) {
  31816. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  31817. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  31818. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  31819. };
  31820. }() ),
  31821. update: function () {
  31822. var v1 = new Vector3();
  31823. var v2 = new Vector3();
  31824. return function update( camera ) {
  31825. var levels = this.levels;
  31826. if ( levels.length > 1 ) {
  31827. v1.setFromMatrixPosition( camera.matrixWorld );
  31828. v2.setFromMatrixPosition( this.matrixWorld );
  31829. var distance = v1.distanceTo( v2 );
  31830. levels[ 0 ].object.visible = true;
  31831. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  31832. if ( distance >= levels[ i ].distance ) {
  31833. levels[ i - 1 ].object.visible = false;
  31834. levels[ i ].object.visible = true;
  31835. } else {
  31836. break;
  31837. }
  31838. }
  31839. for ( ; i < l; i ++ ) {
  31840. levels[ i ].object.visible = false;
  31841. }
  31842. }
  31843. };
  31844. }(),
  31845. toJSON: function ( meta ) {
  31846. var data = Object3D.prototype.toJSON.call( this, meta );
  31847. data.object.levels = [];
  31848. var levels = this.levels;
  31849. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  31850. var level = levels[ i ];
  31851. data.object.levels.push( {
  31852. object: level.object.uuid,
  31853. distance: level.distance
  31854. } );
  31855. }
  31856. return data;
  31857. }
  31858. } );
  31859. /**
  31860. * @author mikael emtinger / http://gomo.se/
  31861. * @author alteredq / http://alteredqualia.com/
  31862. * @author michael guerrero / http://realitymeltdown.com
  31863. * @author ikerr / http://verold.com
  31864. */
  31865. function Skeleton( bones, boneInverses ) {
  31866. // copy the bone array
  31867. bones = bones || [];
  31868. this.bones = bones.slice( 0 );
  31869. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  31870. // use the supplied bone inverses or calculate the inverses
  31871. if ( boneInverses === undefined ) {
  31872. this.calculateInverses();
  31873. } else {
  31874. if ( this.bones.length === boneInverses.length ) {
  31875. this.boneInverses = boneInverses.slice( 0 );
  31876. } else {
  31877. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  31878. this.boneInverses = [];
  31879. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  31880. this.boneInverses.push( new Matrix4() );
  31881. }
  31882. }
  31883. }
  31884. }
  31885. Object.assign( Skeleton.prototype, {
  31886. calculateInverses: function () {
  31887. this.boneInverses = [];
  31888. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  31889. var inverse = new Matrix4();
  31890. if ( this.bones[ i ] ) {
  31891. inverse.getInverse( this.bones[ i ].matrixWorld );
  31892. }
  31893. this.boneInverses.push( inverse );
  31894. }
  31895. },
  31896. pose: function () {
  31897. var bone, i, il;
  31898. // recover the bind-time world matrices
  31899. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  31900. bone = this.bones[ i ];
  31901. if ( bone ) {
  31902. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  31903. }
  31904. }
  31905. // compute the local matrices, positions, rotations and scales
  31906. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  31907. bone = this.bones[ i ];
  31908. if ( bone ) {
  31909. if ( bone.parent && bone.parent.isBone ) {
  31910. bone.matrix.getInverse( bone.parent.matrixWorld );
  31911. bone.matrix.multiply( bone.matrixWorld );
  31912. } else {
  31913. bone.matrix.copy( bone.matrixWorld );
  31914. }
  31915. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  31916. }
  31917. }
  31918. },
  31919. update: ( function () {
  31920. var offsetMatrix = new Matrix4();
  31921. var identityMatrix = new Matrix4();
  31922. return function update() {
  31923. var bones = this.bones;
  31924. var boneInverses = this.boneInverses;
  31925. var boneMatrices = this.boneMatrices;
  31926. var boneTexture = this.boneTexture;
  31927. // flatten bone matrices to array
  31928. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  31929. // compute the offset between the current and the original transform
  31930. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  31931. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  31932. offsetMatrix.toArray( boneMatrices, i * 16 );
  31933. }
  31934. if ( boneTexture !== undefined ) {
  31935. boneTexture.needsUpdate = true;
  31936. }
  31937. };
  31938. } )(),
  31939. clone: function () {
  31940. return new Skeleton( this.bones, this.boneInverses );
  31941. }
  31942. } );
  31943. /**
  31944. * @author mikael emtinger / http://gomo.se/
  31945. * @author alteredq / http://alteredqualia.com/
  31946. * @author ikerr / http://verold.com
  31947. */
  31948. function Bone() {
  31949. Object3D.call( this );
  31950. this.type = 'Bone';
  31951. }
  31952. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  31953. constructor: Bone,
  31954. isBone: true
  31955. } );
  31956. /**
  31957. * @author mikael emtinger / http://gomo.se/
  31958. * @author alteredq / http://alteredqualia.com/
  31959. * @author ikerr / http://verold.com
  31960. */
  31961. function SkinnedMesh( geometry, material ) {
  31962. Mesh.call( this, geometry, material );
  31963. this.type = 'SkinnedMesh';
  31964. this.bindMode = 'attached';
  31965. this.bindMatrix = new Matrix4();
  31966. this.bindMatrixInverse = new Matrix4();
  31967. var bones = this.initBones();
  31968. var skeleton = new Skeleton( bones );
  31969. this.bind( skeleton, this.matrixWorld );
  31970. this.normalizeSkinWeights();
  31971. }
  31972. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  31973. constructor: SkinnedMesh,
  31974. isSkinnedMesh: true,
  31975. initBones: function () {
  31976. var bones = [], bone, gbone;
  31977. var i, il;
  31978. if ( this.geometry && this.geometry.bones !== undefined ) {
  31979. // first, create array of 'Bone' objects from geometry data
  31980. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  31981. gbone = this.geometry.bones[ i ];
  31982. // create new 'Bone' object
  31983. bone = new Bone();
  31984. bones.push( bone );
  31985. // apply values
  31986. bone.name = gbone.name;
  31987. bone.position.fromArray( gbone.pos );
  31988. bone.quaternion.fromArray( gbone.rotq );
  31989. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  31990. }
  31991. // second, create bone hierarchy
  31992. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  31993. gbone = this.geometry.bones[ i ];
  31994. if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) {
  31995. // subsequent bones in the hierarchy
  31996. bones[ gbone.parent ].add( bones[ i ] );
  31997. } else {
  31998. // topmost bone, immediate child of the skinned mesh
  31999. this.add( bones[ i ] );
  32000. }
  32001. }
  32002. }
  32003. // now the bones are part of the scene graph and children of the skinned mesh.
  32004. // let's update the corresponding matrices
  32005. this.updateMatrixWorld( true );
  32006. return bones;
  32007. },
  32008. bind: function ( skeleton, bindMatrix ) {
  32009. this.skeleton = skeleton;
  32010. if ( bindMatrix === undefined ) {
  32011. this.updateMatrixWorld( true );
  32012. this.skeleton.calculateInverses();
  32013. bindMatrix = this.matrixWorld;
  32014. }
  32015. this.bindMatrix.copy( bindMatrix );
  32016. this.bindMatrixInverse.getInverse( bindMatrix );
  32017. },
  32018. pose: function () {
  32019. this.skeleton.pose();
  32020. },
  32021. normalizeSkinWeights: function () {
  32022. var scale, i;
  32023. if ( this.geometry && this.geometry.isGeometry ) {
  32024. for ( i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  32025. var sw = this.geometry.skinWeights[ i ];
  32026. scale = 1.0 / sw.manhattanLength();
  32027. if ( scale !== Infinity ) {
  32028. sw.multiplyScalar( scale );
  32029. } else {
  32030. sw.set( 1, 0, 0, 0 ); // do something reasonable
  32031. }
  32032. }
  32033. } else if ( this.geometry && this.geometry.isBufferGeometry ) {
  32034. var vec = new Vector4();
  32035. var skinWeight = this.geometry.attributes.skinWeight;
  32036. for ( i = 0; i < skinWeight.count; i ++ ) {
  32037. vec.x = skinWeight.getX( i );
  32038. vec.y = skinWeight.getY( i );
  32039. vec.z = skinWeight.getZ( i );
  32040. vec.w = skinWeight.getW( i );
  32041. scale = 1.0 / vec.manhattanLength();
  32042. if ( scale !== Infinity ) {
  32043. vec.multiplyScalar( scale );
  32044. } else {
  32045. vec.set( 1, 0, 0, 0 ); // do something reasonable
  32046. }
  32047. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  32048. }
  32049. }
  32050. },
  32051. updateMatrixWorld: function ( force ) {
  32052. Mesh.prototype.updateMatrixWorld.call( this, force );
  32053. if ( this.bindMode === 'attached' ) {
  32054. this.bindMatrixInverse.getInverse( this.matrixWorld );
  32055. } else if ( this.bindMode === 'detached' ) {
  32056. this.bindMatrixInverse.getInverse( this.bindMatrix );
  32057. } else {
  32058. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  32059. }
  32060. },
  32061. clone: function () {
  32062. return new this.constructor( this.geometry, this.material ).copy( this );
  32063. }
  32064. } );
  32065. /**
  32066. * @author mrdoob / http://mrdoob.com/
  32067. * @author alteredq / http://alteredqualia.com/
  32068. */
  32069. function Fog( color, near, far ) {
  32070. this.name = '';
  32071. this.color = new Color( color );
  32072. this.near = ( near !== undefined ) ? near : 1;
  32073. this.far = ( far !== undefined ) ? far : 1000;
  32074. }
  32075. Fog.prototype.isFog = true;
  32076. Fog.prototype.clone = function () {
  32077. return new Fog( this.color.getHex(), this.near, this.far );
  32078. };
  32079. Fog.prototype.toJSON = function ( /* meta */ ) {
  32080. return {
  32081. type: 'Fog',
  32082. color: this.color.getHex(),
  32083. near: this.near,
  32084. far: this.far
  32085. };
  32086. };
  32087. /**
  32088. * @author mrdoob / http://mrdoob.com/
  32089. * @author alteredq / http://alteredqualia.com/
  32090. */
  32091. function FogExp2( color, density ) {
  32092. this.name = '';
  32093. this.color = new Color( color );
  32094. this.density = ( density !== undefined ) ? density : 0.00025;
  32095. }
  32096. FogExp2.prototype.isFogExp2 = true;
  32097. FogExp2.prototype.clone = function () {
  32098. return new FogExp2( this.color.getHex(), this.density );
  32099. };
  32100. FogExp2.prototype.toJSON = function ( /* meta */ ) {
  32101. return {
  32102. type: 'FogExp2',
  32103. color: this.color.getHex(),
  32104. density: this.density
  32105. };
  32106. };
  32107. /**
  32108. * @author mrdoob / http://mrdoob.com/
  32109. */
  32110. function BufferGeometryLoader( manager ) {
  32111. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32112. }
  32113. Object.assign( BufferGeometryLoader.prototype, {
  32114. load: function ( url, onLoad, onProgress, onError ) {
  32115. var scope = this;
  32116. var loader = new FileLoader( scope.manager );
  32117. loader.load( url, function ( text ) {
  32118. onLoad( scope.parse( JSON.parse( text ) ) );
  32119. }, onProgress, onError );
  32120. },
  32121. parse: function ( json ) {
  32122. var geometry = new BufferGeometry();
  32123. var index = json.data.index;
  32124. if ( index !== undefined ) {
  32125. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  32126. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  32127. }
  32128. var attributes = json.data.attributes;
  32129. for ( var key in attributes ) {
  32130. var attribute = attributes[ key ];
  32131. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  32132. geometry.addAttribute( key, new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  32133. }
  32134. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  32135. if ( groups !== undefined ) {
  32136. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  32137. var group = groups[ i ];
  32138. geometry.addGroup( group.start, group.count, group.materialIndex );
  32139. }
  32140. }
  32141. var boundingSphere = json.data.boundingSphere;
  32142. if ( boundingSphere !== undefined ) {
  32143. var center = new Vector3();
  32144. if ( boundingSphere.center !== undefined ) {
  32145. center.fromArray( boundingSphere.center );
  32146. }
  32147. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  32148. }
  32149. return geometry;
  32150. }
  32151. } );
  32152. var TYPED_ARRAYS = {
  32153. Int8Array: Int8Array,
  32154. Uint8Array: Uint8Array,
  32155. // Workaround for IE11 pre KB2929437. See #11440
  32156. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  32157. Int16Array: Int16Array,
  32158. Uint16Array: Uint16Array,
  32159. Int32Array: Int32Array,
  32160. Uint32Array: Uint32Array,
  32161. Float32Array: Float32Array,
  32162. Float64Array: Float64Array
  32163. };
  32164. var Geometries = Object.freeze({
  32165. WireframeGeometry: WireframeGeometry,
  32166. ParametricGeometry: ParametricGeometry,
  32167. ParametricBufferGeometry: ParametricBufferGeometry,
  32168. TetrahedronGeometry: TetrahedronGeometry,
  32169. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  32170. OctahedronGeometry: OctahedronGeometry,
  32171. OctahedronBufferGeometry: OctahedronBufferGeometry,
  32172. IcosahedronGeometry: IcosahedronGeometry,
  32173. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  32174. DodecahedronGeometry: DodecahedronGeometry,
  32175. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  32176. PolyhedronGeometry: PolyhedronGeometry,
  32177. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  32178. TubeGeometry: TubeGeometry,
  32179. TubeBufferGeometry: TubeBufferGeometry,
  32180. TorusKnotGeometry: TorusKnotGeometry,
  32181. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  32182. TorusGeometry: TorusGeometry,
  32183. TorusBufferGeometry: TorusBufferGeometry,
  32184. TextGeometry: TextGeometry,
  32185. TextBufferGeometry: TextBufferGeometry,
  32186. SphereGeometry: SphereGeometry,
  32187. SphereBufferGeometry: SphereBufferGeometry,
  32188. RingGeometry: RingGeometry,
  32189. RingBufferGeometry: RingBufferGeometry,
  32190. PlaneGeometry: PlaneGeometry,
  32191. PlaneBufferGeometry: PlaneBufferGeometry,
  32192. LatheGeometry: LatheGeometry,
  32193. LatheBufferGeometry: LatheBufferGeometry,
  32194. ShapeGeometry: ShapeGeometry,
  32195. ShapeBufferGeometry: ShapeBufferGeometry,
  32196. ExtrudeGeometry: ExtrudeGeometry,
  32197. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  32198. EdgesGeometry: EdgesGeometry,
  32199. ConeGeometry: ConeGeometry,
  32200. ConeBufferGeometry: ConeBufferGeometry,
  32201. CylinderGeometry: CylinderGeometry,
  32202. CylinderBufferGeometry: CylinderBufferGeometry,
  32203. CircleGeometry: CircleGeometry,
  32204. CircleBufferGeometry: CircleBufferGeometry,
  32205. BoxGeometry: BoxGeometry,
  32206. BoxBufferGeometry: BoxBufferGeometry
  32207. });
  32208. /**
  32209. * @author mrdoob / http://mrdoob.com/
  32210. */
  32211. function ObjectLoader$1( manager ) {
  32212. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32213. this.texturePath = '';
  32214. }
  32215. Object.assign( ObjectLoader$1.prototype, {
  32216. load: function ( url, onLoad, onProgress, onError ) {
  32217. if ( this.texturePath === '' ) {
  32218. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  32219. }
  32220. var scope = this;
  32221. var loader = new FileLoader( scope.manager );
  32222. loader.load( url, function ( text ) {
  32223. var json = null;
  32224. try {
  32225. json = JSON.parse( text );
  32226. } catch ( error ) {
  32227. if ( onError !== undefined ) onError( error );
  32228. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  32229. return;
  32230. }
  32231. var metadata = json.metadata;
  32232. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  32233. console.error( 'THREE.ObjectLoader: Can\'t load ' + url + '. Use THREE.JSONLoader instead.' );
  32234. return;
  32235. }
  32236. scope.parse( json, onLoad );
  32237. }, onProgress, onError );
  32238. },
  32239. setTexturePath: function ( value ) {
  32240. this.texturePath = value;
  32241. },
  32242. setCrossOrigin: function ( value ) {
  32243. this.crossOrigin = value;
  32244. },
  32245. parse: function ( json, onLoad ) {
  32246. var geometries = this.parseGeometries( json.geometries );
  32247. var images = this.parseImages( json.images, function () {
  32248. if ( onLoad !== undefined ) onLoad( object );
  32249. } );
  32250. var textures = this.parseTextures( json.textures, images );
  32251. var materials = this.parseMaterials( json.materials, textures );
  32252. var object = this.parseObject( json.object, geometries, materials );
  32253. if ( json.animations ) {
  32254. object.animations = this.parseAnimations( json.animations );
  32255. }
  32256. if ( json.images === undefined || json.images.length === 0 ) {
  32257. if ( onLoad !== undefined ) onLoad( object );
  32258. }
  32259. return object;
  32260. },
  32261. parseGeometries: function ( json ) {
  32262. var geometries = {};
  32263. if ( json !== undefined ) {
  32264. var geometryLoader = new JSONLoader();
  32265. var bufferGeometryLoader = new BufferGeometryLoader();
  32266. for ( var i = 0, l = json.length; i < l; i ++ ) {
  32267. var geometry;
  32268. var data = json[ i ];
  32269. switch ( data.type ) {
  32270. case 'PlaneGeometry':
  32271. case 'PlaneBufferGeometry':
  32272. geometry = new Geometries[ data.type ](
  32273. data.width,
  32274. data.height,
  32275. data.widthSegments,
  32276. data.heightSegments
  32277. );
  32278. break;
  32279. case 'BoxGeometry':
  32280. case 'BoxBufferGeometry':
  32281. case 'CubeGeometry': // backwards compatible
  32282. geometry = new Geometries[ data.type ](
  32283. data.width,
  32284. data.height,
  32285. data.depth,
  32286. data.widthSegments,
  32287. data.heightSegments,
  32288. data.depthSegments
  32289. );
  32290. break;
  32291. case 'CircleGeometry':
  32292. case 'CircleBufferGeometry':
  32293. geometry = new Geometries[ data.type ](
  32294. data.radius,
  32295. data.segments,
  32296. data.thetaStart,
  32297. data.thetaLength
  32298. );
  32299. break;
  32300. case 'CylinderGeometry':
  32301. case 'CylinderBufferGeometry':
  32302. geometry = new Geometries[ data.type ](
  32303. data.radiusTop,
  32304. data.radiusBottom,
  32305. data.height,
  32306. data.radialSegments,
  32307. data.heightSegments,
  32308. data.openEnded,
  32309. data.thetaStart,
  32310. data.thetaLength
  32311. );
  32312. break;
  32313. case 'ConeGeometry':
  32314. case 'ConeBufferGeometry':
  32315. geometry = new Geometries[ data.type ](
  32316. data.radius,
  32317. data.height,
  32318. data.radialSegments,
  32319. data.heightSegments,
  32320. data.openEnded,
  32321. data.thetaStart,
  32322. data.thetaLength
  32323. );
  32324. break;
  32325. case 'SphereGeometry':
  32326. case 'SphereBufferGeometry':
  32327. geometry = new Geometries[ data.type ](
  32328. data.radius,
  32329. data.widthSegments,
  32330. data.heightSegments,
  32331. data.phiStart,
  32332. data.phiLength,
  32333. data.thetaStart,
  32334. data.thetaLength
  32335. );
  32336. break;
  32337. case 'DodecahedronGeometry':
  32338. case 'DodecahedronBufferGeometry':
  32339. case 'IcosahedronGeometry':
  32340. case 'IcosahedronBufferGeometry':
  32341. case 'OctahedronGeometry':
  32342. case 'OctahedronBufferGeometry':
  32343. case 'TetrahedronGeometry':
  32344. case 'TetrahedronBufferGeometry':
  32345. geometry = new Geometries[ data.type ](
  32346. data.radius,
  32347. data.detail
  32348. );
  32349. break;
  32350. case 'RingGeometry':
  32351. case 'RingBufferGeometry':
  32352. geometry = new Geometries[ data.type ](
  32353. data.innerRadius,
  32354. data.outerRadius,
  32355. data.thetaSegments,
  32356. data.phiSegments,
  32357. data.thetaStart,
  32358. data.thetaLength
  32359. );
  32360. break;
  32361. case 'TorusGeometry':
  32362. case 'TorusBufferGeometry':
  32363. geometry = new Geometries[ data.type ](
  32364. data.radius,
  32365. data.tube,
  32366. data.radialSegments,
  32367. data.tubularSegments,
  32368. data.arc
  32369. );
  32370. break;
  32371. case 'TorusKnotGeometry':
  32372. case 'TorusKnotBufferGeometry':
  32373. geometry = new Geometries[ data.type ](
  32374. data.radius,
  32375. data.tube,
  32376. data.tubularSegments,
  32377. data.radialSegments,
  32378. data.p,
  32379. data.q
  32380. );
  32381. break;
  32382. case 'LatheGeometry':
  32383. case 'LatheBufferGeometry':
  32384. geometry = new Geometries[ data.type ](
  32385. data.points,
  32386. data.segments,
  32387. data.phiStart,
  32388. data.phiLength
  32389. );
  32390. break;
  32391. case 'PolyhedronGeometry':
  32392. case 'PolyhedronBufferGeometry':
  32393. geometry = new Geometries[ data.type ](
  32394. data.vertices,
  32395. data.indices,
  32396. data.radius,
  32397. data.details
  32398. );
  32399. break;
  32400. case 'BufferGeometry':
  32401. geometry = bufferGeometryLoader.parse( data );
  32402. break;
  32403. case 'Geometry':
  32404. geometry = geometryLoader.parse( data, this.texturePath ).geometry;
  32405. break;
  32406. default:
  32407. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  32408. continue;
  32409. }
  32410. geometry.uuid = data.uuid;
  32411. if ( data.name !== undefined ) geometry.name = data.name;
  32412. geometries[ data.uuid ] = geometry;
  32413. }
  32414. }
  32415. return geometries;
  32416. },
  32417. parseMaterials: function ( json, textures ) {
  32418. var materials = {};
  32419. if ( json !== undefined ) {
  32420. var loader = new MaterialLoader();
  32421. loader.setTextures( textures );
  32422. for ( var i = 0, l = json.length; i < l; i ++ ) {
  32423. var data = json[ i ];
  32424. if ( data.type === 'MultiMaterial' ) {
  32425. // Deprecated
  32426. var array = [];
  32427. for ( var j = 0; j < data.materials.length; j ++ ) {
  32428. array.push( loader.parse( data.materials[ j ] ) );
  32429. }
  32430. materials[ data.uuid ] = array;
  32431. } else {
  32432. materials[ data.uuid ] = loader.parse( data );
  32433. }
  32434. }
  32435. }
  32436. return materials;
  32437. },
  32438. parseAnimations: function ( json ) {
  32439. var animations = [];
  32440. for ( var i = 0; i < json.length; i ++ ) {
  32441. var clip = AnimationClip.parse( json[ i ] );
  32442. animations.push( clip );
  32443. }
  32444. return animations;
  32445. },
  32446. parseImages: function ( json, onLoad ) {
  32447. var scope = this;
  32448. var images = {};
  32449. function loadImage( url ) {
  32450. scope.manager.itemStart( url );
  32451. return loader.load( url, function () {
  32452. scope.manager.itemEnd( url );
  32453. }, undefined, function () {
  32454. scope.manager.itemEnd( url );
  32455. scope.manager.itemError( url );
  32456. } );
  32457. }
  32458. if ( json !== undefined && json.length > 0 ) {
  32459. var manager = new LoadingManager( onLoad );
  32460. var loader = new ImageLoader( manager );
  32461. loader.setCrossOrigin( this.crossOrigin );
  32462. for ( var i = 0, l = json.length; i < l; i ++ ) {
  32463. var image = json[ i ];
  32464. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  32465. images[ image.uuid ] = loadImage( path );
  32466. }
  32467. }
  32468. return images;
  32469. },
  32470. parseTextures: function ( json, images ) {
  32471. function parseConstant( value, type ) {
  32472. if ( typeof value === 'number' ) return value;
  32473. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  32474. return type[ value ];
  32475. }
  32476. var textures = {};
  32477. if ( json !== undefined ) {
  32478. for ( var i = 0, l = json.length; i < l; i ++ ) {
  32479. var data = json[ i ];
  32480. if ( data.image === undefined ) {
  32481. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  32482. }
  32483. if ( images[ data.image ] === undefined ) {
  32484. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  32485. }
  32486. var texture = new Texture( images[ data.image ] );
  32487. texture.needsUpdate = true;
  32488. texture.uuid = data.uuid;
  32489. if ( data.name !== undefined ) texture.name = data.name;
  32490. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  32491. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  32492. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  32493. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  32494. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  32495. if ( data.wrap !== undefined ) {
  32496. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  32497. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  32498. }
  32499. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  32500. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  32501. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  32502. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  32503. textures[ data.uuid ] = texture;
  32504. }
  32505. }
  32506. return textures;
  32507. },
  32508. parseObject: function () {
  32509. var matrix = new Matrix4();
  32510. return function parseObject( data, geometries, materials ) {
  32511. var object;
  32512. function getGeometry( name ) {
  32513. if ( geometries[ name ] === undefined ) {
  32514. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  32515. }
  32516. return geometries[ name ];
  32517. }
  32518. function getMaterial( name ) {
  32519. if ( name === undefined ) return undefined;
  32520. if ( Array.isArray( name ) ) {
  32521. var array = [];
  32522. for ( var i = 0, l = name.length; i < l; i ++ ) {
  32523. var uuid = name[ i ];
  32524. if ( materials[ uuid ] === undefined ) {
  32525. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  32526. }
  32527. array.push( materials[ uuid ] );
  32528. }
  32529. return array;
  32530. }
  32531. if ( materials[ name ] === undefined ) {
  32532. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  32533. }
  32534. return materials[ name ];
  32535. }
  32536. switch ( data.type ) {
  32537. case 'Scene':
  32538. object = new Scene();
  32539. if ( data.background !== undefined ) {
  32540. if ( Number.isInteger( data.background ) ) {
  32541. object.background = new Color( data.background );
  32542. }
  32543. }
  32544. if ( data.fog !== undefined ) {
  32545. if ( data.fog.type === 'Fog' ) {
  32546. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  32547. } else if ( data.fog.type === 'FogExp2' ) {
  32548. object.fog = new FogExp2( data.fog.color, data.fog.density );
  32549. }
  32550. }
  32551. break;
  32552. case 'PerspectiveCamera':
  32553. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  32554. if ( data.focus !== undefined ) object.focus = data.focus;
  32555. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  32556. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  32557. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  32558. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  32559. break;
  32560. case 'OrthographicCamera':
  32561. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  32562. break;
  32563. case 'AmbientLight':
  32564. object = new AmbientLight( data.color, data.intensity );
  32565. break;
  32566. case 'DirectionalLight':
  32567. object = new DirectionalLight$1( data.color, data.intensity );
  32568. break;
  32569. case 'PointLight':
  32570. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  32571. break;
  32572. case 'RectAreaLight':
  32573. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  32574. break;
  32575. case 'SpotLight':
  32576. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  32577. break;
  32578. case 'HemisphereLight':
  32579. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  32580. break;
  32581. case 'SkinnedMesh':
  32582. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  32583. case 'Mesh':
  32584. var geometry = getGeometry( data.geometry );
  32585. var material = getMaterial( data.material );
  32586. if ( geometry.bones && geometry.bones.length > 0 ) {
  32587. object = new SkinnedMesh( geometry, material );
  32588. } else {
  32589. object = new Mesh( geometry, material );
  32590. }
  32591. break;
  32592. case 'LOD':
  32593. object = new LOD();
  32594. break;
  32595. case 'Line':
  32596. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  32597. break;
  32598. case 'LineLoop':
  32599. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  32600. break;
  32601. case 'LineSegments':
  32602. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  32603. break;
  32604. case 'PointCloud':
  32605. case 'Points':
  32606. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  32607. break;
  32608. case 'Sprite':
  32609. object = new Sprite( getMaterial( data.material ) );
  32610. break;
  32611. case 'Group':
  32612. object = new Group();
  32613. break;
  32614. default:
  32615. object = new Object3D();
  32616. }
  32617. object.uuid = data.uuid;
  32618. if ( data.name !== undefined ) object.name = data.name;
  32619. if ( data.matrix !== undefined ) {
  32620. matrix.fromArray( data.matrix );
  32621. matrix.decompose( object.position, object.quaternion, object.scale );
  32622. } else {
  32623. if ( data.position !== undefined ) object.position.fromArray( data.position );
  32624. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  32625. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  32626. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  32627. }
  32628. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  32629. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  32630. if ( data.shadow ) {
  32631. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  32632. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  32633. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  32634. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  32635. }
  32636. if ( data.visible !== undefined ) object.visible = data.visible;
  32637. if ( data.userData !== undefined ) object.userData = data.userData;
  32638. if ( data.children !== undefined ) {
  32639. var children = data.children;
  32640. for ( var i = 0; i < children.length; i ++ ) {
  32641. object.add( this.parseObject( children[ i ], geometries, materials ) );
  32642. }
  32643. }
  32644. if ( data.type === 'LOD' ) {
  32645. var levels = data.levels;
  32646. for ( var l = 0; l < levels.length; l ++ ) {
  32647. var level = levels[ l ];
  32648. var child = object.getObjectByProperty( 'uuid', level.object );
  32649. if ( child !== undefined ) {
  32650. object.addLevel( child, level.distance );
  32651. }
  32652. }
  32653. }
  32654. return object;
  32655. };
  32656. }()
  32657. } );
  32658. var TEXTURE_MAPPING = {
  32659. UVMapping: UVMapping,
  32660. CubeReflectionMapping: CubeReflectionMapping,
  32661. CubeRefractionMapping: CubeRefractionMapping,
  32662. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  32663. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  32664. SphericalReflectionMapping: SphericalReflectionMapping,
  32665. CubeUVReflectionMapping: CubeUVReflectionMapping,
  32666. CubeUVRefractionMapping: CubeUVRefractionMapping
  32667. };
  32668. var TEXTURE_WRAPPING = {
  32669. RepeatWrapping: RepeatWrapping,
  32670. ClampToEdgeWrapping: ClampToEdgeWrapping,
  32671. MirroredRepeatWrapping: MirroredRepeatWrapping
  32672. };
  32673. var TEXTURE_FILTER = {
  32674. NearestFilter: NearestFilter,
  32675. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  32676. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  32677. LinearFilter: LinearFilter,
  32678. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  32679. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  32680. };
  32681. /**
  32682. * @author TristanVALCKE / https://github.com/Itee
  32683. * @author moraxy / https://github.com/moraxy
  32684. */
  32685. /* global QUnit */
  32686. QUnit.module( 'Lights', () => {
  32687. QUnit.module.todo( 'SpotLightShadow', () => {
  32688. // INHERITANCE
  32689. QUnit.test( "Extending", ( assert ) => {
  32690. assert.ok( false, "everything's gonna be alright" );
  32691. } );
  32692. // INSTANCING
  32693. QUnit.test( "Instancing", ( assert ) => {
  32694. assert.ok( false, "everything's gonna be alright" );
  32695. } );
  32696. // PUBLIC STUFF
  32697. QUnit.test( "isSpotLightShadow", ( assert ) => {
  32698. assert.ok( false, "everything's gonna be alright" );
  32699. } );
  32700. QUnit.test( "update", ( assert ) => {
  32701. assert.ok( false, "everything's gonna be alright" );
  32702. } );
  32703. // OTHERS
  32704. QUnit.test( "clone/copy", ( assert ) => {
  32705. var a = new SpotLightShadow();
  32706. var b = new SpotLightShadow();
  32707. var c;
  32708. assert.notDeepEqual( a, b, "Newly instanced shadows are not equal" );
  32709. c = a.clone();
  32710. assert.smartEqual( a, c, "Shadows are identical after clone()" );
  32711. c.mapSize.set( 256, 256 );
  32712. assert.notDeepEqual( a, c, "Shadows are different again after change" );
  32713. b.copy( a );
  32714. assert.smartEqual( a, b, "Shadows are identical after copy()" );
  32715. b.mapSize.set( 512, 512 );
  32716. assert.notDeepEqual( a, b, "Shadows are different again after change" );
  32717. } );
  32718. QUnit.test( "toJSON", ( assert ) => {
  32719. var light = new SpotLight();
  32720. var shadow = new SpotLightShadow();
  32721. shadow.bias = 10;
  32722. shadow.radius = 5;
  32723. shadow.mapSize.set( 128, 128 );
  32724. light.shadow = shadow;
  32725. var json = light.toJSON();
  32726. var newLight = new ObjectLoader$1().parse( json );
  32727. assert.smartEqual( newLight.shadow, light.shadow, "Reloaded shadow is equal to the original one" );
  32728. } );
  32729. } );
  32730. } );
  32731. /**
  32732. * @author bhouston / http://clara.io/
  32733. */
  32734. function AnimationLoader( manager ) {
  32735. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32736. }
  32737. Object.assign( AnimationLoader.prototype, {
  32738. load: function ( url, onLoad, onProgress, onError ) {
  32739. var scope = this;
  32740. var loader = new FileLoader( scope.manager );
  32741. loader.load( url, function ( text ) {
  32742. onLoad( scope.parse( JSON.parse( text ) ) );
  32743. }, onProgress, onError );
  32744. },
  32745. parse: function ( json, onLoad ) {
  32746. var animations = [];
  32747. for ( var i = 0; i < json.length; i ++ ) {
  32748. var clip = AnimationClip.parse( json[ i ] );
  32749. animations.push( clip );
  32750. }
  32751. onLoad( animations );
  32752. }
  32753. } );
  32754. /**
  32755. * @author TristanVALCKE / https://github.com/Itee
  32756. */
  32757. /* global QUnit */
  32758. QUnit.module( 'Loaders', () => {
  32759. QUnit.module.todo( 'AnimationLoader', () => {
  32760. // INSTANCING
  32761. QUnit.test( "Instancing", ( assert ) => {
  32762. assert.ok( false, "everything's gonna be alright" );
  32763. } );
  32764. // PUBLIC STUFF
  32765. QUnit.test( "load", ( assert ) => {
  32766. assert.ok( false, "everything's gonna be alright" );
  32767. } );
  32768. QUnit.test( "parse", ( assert ) => {
  32769. assert.ok( false, "everything's gonna be alright" );
  32770. } );
  32771. } );
  32772. } );
  32773. /**
  32774. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  32775. */
  32776. function AudioLoader( manager ) {
  32777. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32778. }
  32779. Object.assign( AudioLoader.prototype, {
  32780. load: function ( url, onLoad, onProgress, onError ) {
  32781. var loader = new FileLoader( this.manager );
  32782. loader.setResponseType( 'arraybuffer' );
  32783. loader.load( url, function ( buffer ) {
  32784. var context = AudioContext.getContext();
  32785. context.decodeAudioData( buffer, function ( audioBuffer ) {
  32786. onLoad( audioBuffer );
  32787. } );
  32788. }, onProgress, onError );
  32789. }
  32790. } );
  32791. /**
  32792. * @author TristanVALCKE / https://github.com/Itee
  32793. */
  32794. /* global QUnit */
  32795. QUnit.module( 'Loaders', () => {
  32796. QUnit.module.todo( 'AudioLoader', () => {
  32797. // INSTANCING
  32798. QUnit.test( "Instancing", ( assert ) => {
  32799. assert.ok( false, "everything's gonna be alright" );
  32800. } );
  32801. // PUBLIC STUFF
  32802. QUnit.test( "load", ( assert ) => {
  32803. assert.ok( false, "everything's gonna be alright" );
  32804. } );
  32805. } );
  32806. } );
  32807. /**
  32808. * @author TristanVALCKE / https://github.com/Itee
  32809. */
  32810. /* global QUnit */
  32811. QUnit.module( 'Loaders', () => {
  32812. QUnit.module.todo( 'BufferGeometryLoader', () => {
  32813. // INSTANCING
  32814. QUnit.test( "Instancing", ( assert ) => {
  32815. assert.ok( false, "everything's gonna be alright" );
  32816. } );
  32817. // PUBLIC STUFF
  32818. QUnit.test( "load", ( assert ) => {
  32819. assert.ok( false, "everything's gonna be alright" );
  32820. } );
  32821. QUnit.test( "parse", ( assert ) => {
  32822. assert.ok( false, "everything's gonna be alright" );
  32823. } );
  32824. } );
  32825. } );
  32826. /**
  32827. * @author TristanVALCKE / https://github.com/Itee
  32828. */
  32829. /* global QUnit */
  32830. QUnit.module( 'Loaders', () => {
  32831. QUnit.module.todo( 'Cache', () => {
  32832. // PUBLIC STUFF
  32833. QUnit.test( "add", ( assert ) => {
  32834. assert.ok( false, "everything's gonna be alright" );
  32835. } );
  32836. QUnit.test( "get", ( assert ) => {
  32837. assert.ok( false, "everything's gonna be alright" );
  32838. } );
  32839. QUnit.test( "remove", ( assert ) => {
  32840. assert.ok( false, "everything's gonna be alright" );
  32841. } );
  32842. QUnit.test( "clear", ( assert ) => {
  32843. assert.ok( false, "everything's gonna be alright" );
  32844. } );
  32845. } );
  32846. } );
  32847. /**
  32848. * @author alteredq / http://alteredqualia.com/
  32849. */
  32850. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  32851. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  32852. this.image = { width: width, height: height };
  32853. this.mipmaps = mipmaps;
  32854. // no flipping for cube textures
  32855. // (also flipping doesn't work for compressed textures )
  32856. this.flipY = false;
  32857. // can't generate mipmaps for compressed textures
  32858. // mips must be embedded in DDS files
  32859. this.generateMipmaps = false;
  32860. }
  32861. CompressedTexture.prototype = Object.create( Texture.prototype );
  32862. CompressedTexture.prototype.constructor = CompressedTexture;
  32863. CompressedTexture.prototype.isCompressedTexture = true;
  32864. /**
  32865. * @author mrdoob / http://mrdoob.com/
  32866. *
  32867. * Abstract Base class to block based textures loader (dds, pvr, ...)
  32868. */
  32869. function CompressedTextureLoader( manager ) {
  32870. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32871. // override in sub classes
  32872. this._parser = null;
  32873. }
  32874. Object.assign( CompressedTextureLoader.prototype, {
  32875. load: function ( url, onLoad, onProgress, onError ) {
  32876. var scope = this;
  32877. var images = [];
  32878. var texture = new CompressedTexture();
  32879. texture.image = images;
  32880. var loader = new FileLoader( this.manager );
  32881. loader.setPath( this.path );
  32882. loader.setResponseType( 'arraybuffer' );
  32883. function loadTexture( i ) {
  32884. loader.load( url[ i ], function ( buffer ) {
  32885. var texDatas = scope._parser( buffer, true );
  32886. images[ i ] = {
  32887. width: texDatas.width,
  32888. height: texDatas.height,
  32889. format: texDatas.format,
  32890. mipmaps: texDatas.mipmaps
  32891. };
  32892. loaded += 1;
  32893. if ( loaded === 6 ) {
  32894. if ( texDatas.mipmapCount === 1 )
  32895. texture.minFilter = LinearFilter;
  32896. texture.format = texDatas.format;
  32897. texture.needsUpdate = true;
  32898. if ( onLoad ) onLoad( texture );
  32899. }
  32900. }, onProgress, onError );
  32901. }
  32902. if ( Array.isArray( url ) ) {
  32903. var loaded = 0;
  32904. for ( var i = 0, il = url.length; i < il; ++ i ) {
  32905. loadTexture( i );
  32906. }
  32907. } else {
  32908. // compressed cubemap texture stored in a single DDS file
  32909. loader.load( url, function ( buffer ) {
  32910. var texDatas = scope._parser( buffer, true );
  32911. if ( texDatas.isCubemap ) {
  32912. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  32913. for ( var f = 0; f < faces; f ++ ) {
  32914. images[ f ] = { mipmaps: [] };
  32915. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  32916. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  32917. images[ f ].format = texDatas.format;
  32918. images[ f ].width = texDatas.width;
  32919. images[ f ].height = texDatas.height;
  32920. }
  32921. }
  32922. } else {
  32923. texture.image.width = texDatas.width;
  32924. texture.image.height = texDatas.height;
  32925. texture.mipmaps = texDatas.mipmaps;
  32926. }
  32927. if ( texDatas.mipmapCount === 1 ) {
  32928. texture.minFilter = LinearFilter;
  32929. }
  32930. texture.format = texDatas.format;
  32931. texture.needsUpdate = true;
  32932. if ( onLoad ) onLoad( texture );
  32933. }, onProgress, onError );
  32934. }
  32935. return texture;
  32936. },
  32937. setPath: function ( value ) {
  32938. this.path = value;
  32939. return this;
  32940. }
  32941. } );
  32942. /**
  32943. * @author TristanVALCKE / https://github.com/Itee
  32944. */
  32945. /* global QUnit */
  32946. QUnit.module( 'Loaders', () => {
  32947. QUnit.module.todo( 'CompressedTextureLoader', () => {
  32948. // INSTANCING
  32949. QUnit.test( "Instancing", ( assert ) => {
  32950. assert.ok( false, "everything's gonna be alright" );
  32951. } );
  32952. // PUBLIC STUFF
  32953. QUnit.test( "load", ( assert ) => {
  32954. assert.ok( false, "everything's gonna be alright" );
  32955. } );
  32956. QUnit.test( "setPath", ( assert ) => {
  32957. assert.ok( false, "everything's gonna be alright" );
  32958. } );
  32959. } );
  32960. } );
  32961. /**
  32962. * @author mrdoob / http://mrdoob.com/
  32963. */
  32964. function CubeTextureLoader( manager ) {
  32965. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32966. }
  32967. Object.assign( CubeTextureLoader.prototype, {
  32968. crossOrigin: 'Anonymous',
  32969. load: function ( urls, onLoad, onProgress, onError ) {
  32970. var texture = new CubeTexture();
  32971. var loader = new ImageLoader( this.manager );
  32972. loader.setCrossOrigin( this.crossOrigin );
  32973. loader.setPath( this.path );
  32974. var loaded = 0;
  32975. function loadTexture( i ) {
  32976. loader.load( urls[ i ], function ( image ) {
  32977. texture.images[ i ] = image;
  32978. loaded ++;
  32979. if ( loaded === 6 ) {
  32980. texture.needsUpdate = true;
  32981. if ( onLoad ) onLoad( texture );
  32982. }
  32983. }, undefined, onError );
  32984. }
  32985. for ( var i = 0; i < urls.length; ++ i ) {
  32986. loadTexture( i );
  32987. }
  32988. return texture;
  32989. },
  32990. setCrossOrigin: function ( value ) {
  32991. this.crossOrigin = value;
  32992. return this;
  32993. },
  32994. setPath: function ( value ) {
  32995. this.path = value;
  32996. return this;
  32997. }
  32998. } );
  32999. /**
  33000. * @author TristanVALCKE / https://github.com/Itee
  33001. */
  33002. /* global QUnit */
  33003. QUnit.module( 'Loaders', () => {
  33004. QUnit.module.todo( 'CubeTextureLoader', () => {
  33005. // INSTANCING
  33006. QUnit.test( "Instancing", ( assert ) => {
  33007. assert.ok( false, "everything's gonna be alright" );
  33008. } );
  33009. // PUBLIC STUFF
  33010. QUnit.test( "load", ( assert ) => {
  33011. assert.ok( false, "everything's gonna be alright" );
  33012. } );
  33013. QUnit.test( "setCrossOrigin", ( assert ) => {
  33014. assert.ok( false, "everything's gonna be alright" );
  33015. } );
  33016. QUnit.test( "setPath", ( assert ) => {
  33017. assert.ok( false, "everything's gonna be alright" );
  33018. } );
  33019. } );
  33020. } );
  33021. /**
  33022. * @author Nikos M. / https://github.com/foo123/
  33023. *
  33024. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  33025. */
  33026. function DataTextureLoader( manager ) {
  33027. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  33028. // override in sub classes
  33029. this._parser = null;
  33030. }
  33031. Object.assign( DataTextureLoader.prototype, {
  33032. load: function ( url, onLoad, onProgress, onError ) {
  33033. var scope = this;
  33034. var texture = new DataTexture();
  33035. var loader = new FileLoader( this.manager );
  33036. loader.setResponseType( 'arraybuffer' );
  33037. loader.load( url, function ( buffer ) {
  33038. var texData = scope._parser( buffer );
  33039. if ( ! texData ) return;
  33040. if ( undefined !== texData.image ) {
  33041. texture.image = texData.image;
  33042. } else if ( undefined !== texData.data ) {
  33043. texture.image.width = texData.width;
  33044. texture.image.height = texData.height;
  33045. texture.image.data = texData.data;
  33046. }
  33047. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : ClampToEdgeWrapping;
  33048. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : ClampToEdgeWrapping;
  33049. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : LinearFilter;
  33050. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : LinearMipMapLinearFilter;
  33051. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  33052. if ( undefined !== texData.format ) {
  33053. texture.format = texData.format;
  33054. }
  33055. if ( undefined !== texData.type ) {
  33056. texture.type = texData.type;
  33057. }
  33058. if ( undefined !== texData.mipmaps ) {
  33059. texture.mipmaps = texData.mipmaps;
  33060. }
  33061. if ( 1 === texData.mipmapCount ) {
  33062. texture.minFilter = LinearFilter;
  33063. }
  33064. texture.needsUpdate = true;
  33065. if ( onLoad ) onLoad( texture, texData );
  33066. }, onProgress, onError );
  33067. return texture;
  33068. }
  33069. } );
  33070. /**
  33071. * @author TristanVALCKE / https://github.com/Itee
  33072. */
  33073. /* global QUnit */
  33074. QUnit.module( 'Loaders', () => {
  33075. QUnit.module.todo( 'DataTextureLoader', () => {
  33076. // INSTANCING
  33077. QUnit.test( "Instancing", ( assert ) => {
  33078. assert.ok( false, "everything's gonna be alright" );
  33079. } );
  33080. // PUBLIC STUFF
  33081. QUnit.test( "load", ( assert ) => {
  33082. assert.ok( false, "everything's gonna be alright" );
  33083. } );
  33084. } );
  33085. } );
  33086. /**
  33087. * @author TristanVALCKE / https://github.com/Itee
  33088. */
  33089. /* global QUnit */
  33090. QUnit.module( 'Loaders', () => {
  33091. QUnit.module.todo( 'FileLoader', () => {
  33092. // INSTANCING
  33093. QUnit.test( "Instancing", ( assert ) => {
  33094. assert.ok( false, "everything's gonna be alright" );
  33095. } );
  33096. // PUBLIC STUFF
  33097. QUnit.test( "load", ( assert ) => {
  33098. assert.ok( false, "everything's gonna be alright" );
  33099. } );
  33100. QUnit.test( "setPath", ( assert ) => {
  33101. assert.ok( false, "everything's gonna be alright" );
  33102. } );
  33103. QUnit.test( "setResponseType", ( assert ) => {
  33104. assert.ok( false, "everything's gonna be alright" );
  33105. } );
  33106. QUnit.test( "setWithCredentials", ( assert ) => {
  33107. assert.ok( false, "everything's gonna be alright" );
  33108. } );
  33109. QUnit.test( "setMimeType", ( assert ) => {
  33110. assert.ok( false, "everything's gonna be alright" );
  33111. } );
  33112. QUnit.test( "setRequestHeader", ( assert ) => {
  33113. assert.ok( false, "everything's gonna be alright" );
  33114. } );
  33115. } );
  33116. } );
  33117. /**
  33118. * @author mrdoob / http://mrdoob.com/
  33119. */
  33120. function FontLoader( manager ) {
  33121. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  33122. }
  33123. Object.assign( FontLoader.prototype, {
  33124. load: function ( url, onLoad, onProgress, onError ) {
  33125. var scope = this;
  33126. var loader = new FileLoader( this.manager );
  33127. loader.setPath( this.path );
  33128. loader.load( url, function ( text ) {
  33129. var json;
  33130. try {
  33131. json = JSON.parse( text );
  33132. } catch ( e ) {
  33133. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  33134. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  33135. }
  33136. var font = scope.parse( json );
  33137. if ( onLoad ) onLoad( font );
  33138. }, onProgress, onError );
  33139. },
  33140. parse: function ( json ) {
  33141. return new Font( json );
  33142. },
  33143. setPath: function ( value ) {
  33144. this.path = value;
  33145. return this;
  33146. }
  33147. } );
  33148. /**
  33149. * @author TristanVALCKE / https://github.com/Itee
  33150. */
  33151. /* global QUnit */
  33152. QUnit.module( 'Loaders', () => {
  33153. QUnit.module.todo( 'FontLoader', () => {
  33154. // INSTANCING
  33155. QUnit.test( "Instancing", ( assert ) => {
  33156. assert.ok( false, "everything's gonna be alright" );
  33157. } );
  33158. // PUBLIC STUFF
  33159. QUnit.test( "load", ( assert ) => {
  33160. assert.ok( false, "everything's gonna be alright" );
  33161. } );
  33162. QUnit.test( "parse", ( assert ) => {
  33163. assert.ok( false, "everything's gonna be alright" );
  33164. } );
  33165. QUnit.test( "setPath", ( assert ) => {
  33166. assert.ok( false, "everything's gonna be alright" );
  33167. } );
  33168. } );
  33169. } );
  33170. /**
  33171. * @author TristanVALCKE / https://github.com/Itee
  33172. */
  33173. /* global QUnit */
  33174. QUnit.module( 'Loaders', () => {
  33175. QUnit.module.todo( 'ImageLoader', () => {
  33176. // INSTANCING
  33177. QUnit.test( "Instancing", ( assert ) => {
  33178. assert.ok( false, "everything's gonna be alright" );
  33179. } );
  33180. // PUBLIC STUFF
  33181. QUnit.test( "load", ( assert ) => {
  33182. assert.ok( false, "everything's gonna be alright" );
  33183. } );
  33184. QUnit.test( "setCrossOrigin", ( assert ) => {
  33185. assert.ok( false, "everything's gonna be alright" );
  33186. } );
  33187. QUnit.test( "setPath", ( assert ) => {
  33188. assert.ok( false, "everything's gonna be alright" );
  33189. } );
  33190. } );
  33191. } );
  33192. /**
  33193. * @author TristanVALCKE / https://github.com/Itee
  33194. */
  33195. /* global QUnit */
  33196. QUnit.module( 'Loaders', () => {
  33197. QUnit.module.todo( 'JSONLoader', () => {
  33198. // INSTANCING
  33199. QUnit.test( "Instancing", ( assert ) => {
  33200. assert.ok( false, "everything's gonna be alright" );
  33201. } );
  33202. // PUBLIC STUFF
  33203. QUnit.test( "load", ( assert ) => {
  33204. assert.ok( false, "everything's gonna be alright" );
  33205. } );
  33206. QUnit.test( "setTexturePath", ( assert ) => {
  33207. assert.ok( false, "everything's gonna be alright" );
  33208. } );
  33209. QUnit.test( "parse", ( assert ) => {
  33210. assert.ok( false, "everything's gonna be alright" );
  33211. } );
  33212. } );
  33213. } );
  33214. /**
  33215. * @author TristanVALCKE / https://github.com/Itee
  33216. */
  33217. /* global QUnit */
  33218. QUnit.module( 'Loaders', () => {
  33219. QUnit.module.todo( 'Loader', () => {
  33220. // INSTANCING
  33221. QUnit.test( "Instancing", ( assert ) => {
  33222. assert.ok( false, "everything's gonna be alright" );
  33223. } );
  33224. // STATIC STUFF
  33225. QUnit.test( "Handlers.add", ( assert ) => {
  33226. assert.ok( false, "everything's gonna be alright" );
  33227. } );
  33228. QUnit.test( "Handlers.get", ( assert ) => {
  33229. assert.ok( false, "everything's gonna be alright" );
  33230. } );
  33231. // PUBLIC STUFF
  33232. QUnit.test( "extractUrlBase", ( assert ) => {
  33233. assert.ok( false, "everything's gonna be alright" );
  33234. } );
  33235. QUnit.test( "initMaterials", ( assert ) => {
  33236. assert.ok( false, "everything's gonna be alright" );
  33237. } );
  33238. QUnit.test( "createMaterial", ( assert ) => {
  33239. assert.ok( false, "everything's gonna be alright" );
  33240. } );
  33241. } );
  33242. } );
  33243. /**
  33244. * @author TristanVALCKE / https://github.com/Itee
  33245. */
  33246. /* global QUnit */
  33247. QUnit.module( 'Loaders', () => {
  33248. QUnit.module.todo( 'LoadingManager', () => {
  33249. // INSTANCING
  33250. QUnit.test( "Instancing", ( assert ) => {
  33251. assert.ok( false, "everything's gonna be alright" );
  33252. } );
  33253. // PUBLIC STUFF
  33254. QUnit.test( "onStart", ( assert ) => {
  33255. assert.ok( false, "everything's gonna be alright" );
  33256. } );
  33257. QUnit.test( "onLoad", ( assert ) => {
  33258. assert.ok( false, "everything's gonna be alright" );
  33259. } );
  33260. QUnit.test( "onProgress", ( assert ) => {
  33261. assert.ok( false, "everything's gonna be alright" );
  33262. } );
  33263. QUnit.test( "onError", ( assert ) => {
  33264. assert.ok( false, "everything's gonna be alright" );
  33265. } );
  33266. QUnit.test( "itemStart", ( assert ) => {
  33267. assert.ok( false, "everything's gonna be alright" );
  33268. } );
  33269. QUnit.test( "itemEnd", ( assert ) => {
  33270. assert.ok( false, "everything's gonna be alright" );
  33271. } );
  33272. QUnit.test( "itemError", ( assert ) => {
  33273. assert.ok( false, "everything's gonna be alright" );
  33274. } );
  33275. } );
  33276. } );
  33277. /**
  33278. * @author TristanVALCKE / https://github.com/Itee
  33279. */
  33280. /* global QUnit */
  33281. QUnit.module( 'Loaders', () => {
  33282. QUnit.module.todo( 'MaterialLoader', () => {
  33283. // INSTANCING
  33284. QUnit.test( "Instancing", ( assert ) => {
  33285. assert.ok( false, "everything's gonna be alright" );
  33286. } );
  33287. // PUBLIC STUFF
  33288. QUnit.test( "load", ( assert ) => {
  33289. assert.ok( false, "everything's gonna be alright" );
  33290. } );
  33291. QUnit.test( "setTextures", ( assert ) => {
  33292. assert.ok( false, "everything's gonna be alright" );
  33293. } );
  33294. QUnit.test( "parse", ( assert ) => {
  33295. assert.ok( false, "everything's gonna be alright" );
  33296. } );
  33297. } );
  33298. } );
  33299. /**
  33300. * @author TristanVALCKE / https://github.com/Itee
  33301. */
  33302. /* global QUnit */
  33303. QUnit.module( 'Loaders', () => {
  33304. QUnit.module.todo( 'ObjectLoader', () => {
  33305. // INSTANCING
  33306. QUnit.test( "Instancing", ( assert ) => {
  33307. assert.ok( false, "everything's gonna be alright" );
  33308. } );
  33309. // PUBLIC STUFF
  33310. QUnit.test( "load", ( assert ) => {
  33311. assert.ok( false, "everything's gonna be alright" );
  33312. } );
  33313. QUnit.test( "setTexturePath", ( assert ) => {
  33314. assert.ok( false, "everything's gonna be alright" );
  33315. } );
  33316. QUnit.test( "setCrossOrigin", ( assert ) => {
  33317. assert.ok( false, "everything's gonna be alright" );
  33318. } );
  33319. QUnit.test( "parse", ( assert ) => {
  33320. assert.ok( false, "everything's gonna be alright" );
  33321. } );
  33322. QUnit.test( "parseGeometries", ( assert ) => {
  33323. assert.ok( false, "everything's gonna be alright" );
  33324. } );
  33325. QUnit.test( "parseMaterials", ( assert ) => {
  33326. assert.ok( false, "everything's gonna be alright" );
  33327. } );
  33328. QUnit.test( "parseAnimations", ( assert ) => {
  33329. assert.ok( false, "everything's gonna be alright" );
  33330. } );
  33331. QUnit.test( "parseImages", ( assert ) => {
  33332. assert.ok( false, "everything's gonna be alright" );
  33333. } );
  33334. QUnit.test( "parseTextures", ( assert ) => {
  33335. assert.ok( false, "everything's gonna be alright" );
  33336. } );
  33337. QUnit.test( "parseObject", ( 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( 'Loaders', () => {
  33347. QUnit.module.todo( 'TextureLoader', () => {
  33348. // INSTANCING
  33349. QUnit.test( "Instancing", ( assert ) => {
  33350. assert.ok( false, "everything's gonna be alright" );
  33351. } );
  33352. // PUBLIC STUFF
  33353. QUnit.test( "load", ( assert ) => {
  33354. assert.ok( false, "everything's gonna be alright" );
  33355. } );
  33356. QUnit.test( "setCrossOrigin", ( assert ) => {
  33357. assert.ok( false, "everything's gonna be alright" );
  33358. } );
  33359. QUnit.test( "setPath", ( assert ) => {
  33360. assert.ok( false, "everything's gonna be alright" );
  33361. } );
  33362. } );
  33363. } );
  33364. /**
  33365. * @author TristanVALCKE / https://github.com/Itee
  33366. */
  33367. /* global QUnit */
  33368. QUnit.module( 'Materials', () => {
  33369. QUnit.module.todo( 'LineBasicMaterial', () => {
  33370. // INHERITANCE
  33371. QUnit.test( "Extending", ( assert ) => {
  33372. assert.ok( false, "everything's gonna be alright" );
  33373. } );
  33374. // INSTANCING
  33375. QUnit.test( "Instancing", ( assert ) => {
  33376. assert.ok( false, "everything's gonna be alright" );
  33377. } );
  33378. // PUBLIC STUFF
  33379. QUnit.test( "isLineBasicMaterial", ( assert ) => {
  33380. assert.ok( false, "everything's gonna be alright" );
  33381. } );
  33382. QUnit.test( "copy", ( assert ) => {
  33383. assert.ok( false, "everything's gonna be alright" );
  33384. } );
  33385. } );
  33386. } );
  33387. /**
  33388. * @author TristanVALCKE / https://github.com/Itee
  33389. */
  33390. /* global QUnit */
  33391. QUnit.module( 'Materials', () => {
  33392. QUnit.module.todo( 'LineDashedMaterial', () => {
  33393. // INHERITANCE
  33394. QUnit.test( "Extending", ( assert ) => {
  33395. assert.ok( false, "everything's gonna be alright" );
  33396. } );
  33397. // INSTANCING
  33398. QUnit.test( "Instancing", ( assert ) => {
  33399. assert.ok( false, "everything's gonna be alright" );
  33400. } );
  33401. // PUBLIC STUFF
  33402. QUnit.test( "isLineDashedMaterial", ( assert ) => {
  33403. assert.ok( false, "everything's gonna be alright" );
  33404. } );
  33405. QUnit.test( "copy", ( assert ) => {
  33406. assert.ok( false, "everything's gonna be alright" );
  33407. } );
  33408. } );
  33409. } );
  33410. /**
  33411. * @author TristanVALCKE / https://github.com/Itee
  33412. */
  33413. /* global QUnit */
  33414. QUnit.module( 'Materials', () => {
  33415. QUnit.module.todo( 'Material', () => {
  33416. // INSTANCING
  33417. QUnit.test( "Instancing", ( assert ) => {
  33418. assert.ok( false, "everything's gonna be alright" );
  33419. } );
  33420. // PUBLIC STUFF
  33421. QUnit.test( "isMaterial", ( assert ) => {
  33422. assert.ok( false, "everything's gonna be alright" );
  33423. } );
  33424. QUnit.test( "onBeforeCompile", ( assert ) => {
  33425. assert.ok( false, "everything's gonna be alright" );
  33426. } );
  33427. QUnit.test( "setValues", ( assert ) => {
  33428. assert.ok( false, "everything's gonna be alright" );
  33429. } );
  33430. QUnit.test( "toJSON", ( assert ) => {
  33431. assert.ok( false, "everything's gonna be alright" );
  33432. } );
  33433. QUnit.test( "clone", ( assert ) => {
  33434. assert.ok( false, "everything's gonna be alright" );
  33435. } );
  33436. QUnit.test( "copy", ( assert ) => {
  33437. assert.ok( false, "everything's gonna be alright" );
  33438. } );
  33439. QUnit.test( "dispose", ( assert ) => {
  33440. assert.ok( false, "everything's gonna be alright" );
  33441. } );
  33442. } );
  33443. } );
  33444. /**
  33445. * @author TristanVALCKE / https://github.com/Itee
  33446. */
  33447. /* global QUnit */
  33448. QUnit.module( 'Materials', () => {
  33449. QUnit.module.todo( 'MeshBasicMaterial', () => {
  33450. // INHERITANCE
  33451. QUnit.test( "Extending", ( assert ) => {
  33452. assert.ok( false, "everything's gonna be alright" );
  33453. } );
  33454. // INSTANCING
  33455. QUnit.test( "Instancing", ( assert ) => {
  33456. assert.ok( false, "everything's gonna be alright" );
  33457. } );
  33458. // PUBLIC STUFF
  33459. QUnit.test( "isMeshBasicMaterial", ( assert ) => {
  33460. assert.ok( false, "everything's gonna be alright" );
  33461. } );
  33462. QUnit.test( "copy", ( assert ) => {
  33463. assert.ok( false, "everything's gonna be alright" );
  33464. } );
  33465. } );
  33466. } );
  33467. /**
  33468. * @author TristanVALCKE / https://github.com/Itee
  33469. */
  33470. /* global QUnit */
  33471. QUnit.module( 'Materials', () => {
  33472. QUnit.module.todo( 'MeshDepthMaterial', () => {
  33473. // INHERITANCE
  33474. QUnit.test( "Extending", ( assert ) => {
  33475. assert.ok( false, "everything's gonna be alright" );
  33476. } );
  33477. // INSTANCING
  33478. QUnit.test( "Instancing", ( assert ) => {
  33479. assert.ok( false, "everything's gonna be alright" );
  33480. } );
  33481. // PUBLIC STUFF
  33482. QUnit.test( "isMeshDepthMaterial", ( assert ) => {
  33483. assert.ok( false, "everything's gonna be alright" );
  33484. } );
  33485. QUnit.test( "copy", ( assert ) => {
  33486. assert.ok( false, "everything's gonna be alright" );
  33487. } );
  33488. } );
  33489. } );
  33490. /**
  33491. * @author TristanVALCKE / https://github.com/Itee
  33492. */
  33493. /* global QUnit */
  33494. QUnit.module( 'Materials', () => {
  33495. QUnit.module.todo( 'MeshDistanceMaterial', () => {
  33496. // INHERITANCE
  33497. QUnit.test( "Extending", ( assert ) => {
  33498. assert.ok( false, "everything's gonna be alright" );
  33499. } );
  33500. // INSTANCING
  33501. QUnit.test( "Instancing", ( assert ) => {
  33502. assert.ok( false, "everything's gonna be alright" );
  33503. } );
  33504. // PUBLIC STUFF
  33505. QUnit.test( "isMeshDistanceMaterial", ( assert ) => {
  33506. assert.ok( false, "everything's gonna be alright" );
  33507. } );
  33508. QUnit.test( "copy", ( assert ) => {
  33509. assert.ok( false, "everything's gonna be alright" );
  33510. } );
  33511. } );
  33512. } );
  33513. /**
  33514. * @author TristanVALCKE / https://github.com/Itee
  33515. */
  33516. /* global QUnit */
  33517. QUnit.module( 'Materials', () => {
  33518. QUnit.module.todo( 'MeshLambertMaterial', () => {
  33519. // INHERITANCE
  33520. QUnit.test( "Extending", ( assert ) => {
  33521. assert.ok( false, "everything's gonna be alright" );
  33522. } );
  33523. // INSTANCING
  33524. QUnit.test( "Instancing", ( assert ) => {
  33525. assert.ok( false, "everything's gonna be alright" );
  33526. } );
  33527. // PUBLIC STUFF
  33528. QUnit.test( "isMeshLambertMaterial", ( assert ) => {
  33529. assert.ok( false, "everything's gonna be alright" );
  33530. } );
  33531. QUnit.test( "copy", ( assert ) => {
  33532. assert.ok( false, "everything's gonna be alright" );
  33533. } );
  33534. } );
  33535. } );
  33536. /**
  33537. * @author TristanVALCKE / https://github.com/Itee
  33538. */
  33539. /* global QUnit */
  33540. QUnit.module( 'Materials', () => {
  33541. QUnit.module.todo( 'MeshNormalMaterial', () => {
  33542. // INHERITANCE
  33543. QUnit.test( "Extending", ( assert ) => {
  33544. assert.ok( false, "everything's gonna be alright" );
  33545. } );
  33546. // INSTANCING
  33547. QUnit.test( "Instancing", ( assert ) => {
  33548. assert.ok( false, "everything's gonna be alright" );
  33549. } );
  33550. // PUBLIC STUFF
  33551. QUnit.test( "isMeshNormalMaterial", ( assert ) => {
  33552. assert.ok( false, "everything's gonna be alright" );
  33553. } );
  33554. QUnit.test( "copy", ( assert ) => {
  33555. assert.ok( false, "everything's gonna be alright" );
  33556. } );
  33557. } );
  33558. } );
  33559. /**
  33560. * @author TristanVALCKE / https://github.com/Itee
  33561. */
  33562. /* global QUnit */
  33563. QUnit.module( 'Materials', () => {
  33564. QUnit.module.todo( 'MeshPhongMaterial', () => {
  33565. // INHERITANCE
  33566. QUnit.test( "Extending", ( assert ) => {
  33567. assert.ok( false, "everything's gonna be alright" );
  33568. } );
  33569. // INSTANCING
  33570. QUnit.test( "Instancing", ( assert ) => {
  33571. assert.ok( false, "everything's gonna be alright" );
  33572. } );
  33573. // PUBLIC STUFF
  33574. QUnit.test( "isMeshPhongMaterial", ( assert ) => {
  33575. assert.ok( false, "everything's gonna be alright" );
  33576. } );
  33577. QUnit.test( "copy", ( assert ) => {
  33578. assert.ok( false, "everything's gonna be alright" );
  33579. } );
  33580. } );
  33581. } );
  33582. /**
  33583. * @author TristanVALCKE / https://github.com/Itee
  33584. */
  33585. /* global QUnit */
  33586. QUnit.module( 'Materials', () => {
  33587. QUnit.module.todo( 'MeshPhysicalMaterial', () => {
  33588. // INHERITANCE
  33589. QUnit.test( "Extending", ( assert ) => {
  33590. assert.ok( false, "everything's gonna be alright" );
  33591. } );
  33592. // INSTANCING
  33593. QUnit.test( "Instancing", ( assert ) => {
  33594. assert.ok( false, "everything's gonna be alright" );
  33595. } );
  33596. // PUBLIC STUFF
  33597. QUnit.test( "isMeshPhysicalMaterial", ( assert ) => {
  33598. assert.ok( false, "everything's gonna be alright" );
  33599. } );
  33600. QUnit.test( "copy", ( assert ) => {
  33601. assert.ok( false, "everything's gonna be alright" );
  33602. } );
  33603. } );
  33604. } );
  33605. /**
  33606. * @author TristanVALCKE / https://github.com/Itee
  33607. */
  33608. /* global QUnit */
  33609. QUnit.module( 'Materials', () => {
  33610. QUnit.module.todo( 'MeshStandardMaterial', () => {
  33611. // INHERITANCE
  33612. QUnit.test( "Extending", ( assert ) => {
  33613. assert.ok( false, "everything's gonna be alright" );
  33614. } );
  33615. // INSTANCING
  33616. QUnit.test( "Instancing", ( assert ) => {
  33617. assert.ok( false, "everything's gonna be alright" );
  33618. } );
  33619. // PUBLIC STUFF
  33620. QUnit.test( "isMeshStandardMaterial", ( assert ) => {
  33621. assert.ok( false, "everything's gonna be alright" );
  33622. } );
  33623. QUnit.test( "copy", ( assert ) => {
  33624. assert.ok( false, "everything's gonna be alright" );
  33625. } );
  33626. } );
  33627. } );
  33628. /**
  33629. * @author TristanVALCKE / https://github.com/Itee
  33630. */
  33631. /* global QUnit */
  33632. QUnit.module( 'Materials', () => {
  33633. QUnit.module.todo( 'MeshToonMaterial', () => {
  33634. // INHERITANCE
  33635. QUnit.test( "Extending", ( assert ) => {
  33636. assert.ok( false, "everything's gonna be alright" );
  33637. } );
  33638. // INSTANCING
  33639. QUnit.test( "Instancing", ( assert ) => {
  33640. assert.ok( false, "everything's gonna be alright" );
  33641. } );
  33642. // PUBLIC STUFF
  33643. QUnit.test( "isMeshToonMaterial", ( assert ) => {
  33644. assert.ok( false, "everything's gonna be alright" );
  33645. } );
  33646. QUnit.test( "copy", ( assert ) => {
  33647. assert.ok( false, "everything's gonna be alright" );
  33648. } );
  33649. } );
  33650. } );
  33651. /**
  33652. * @author TristanVALCKE / https://github.com/Itee
  33653. */
  33654. /* global QUnit */
  33655. QUnit.module( 'Materials', () => {
  33656. QUnit.module.todo( 'PointsMaterial', () => {
  33657. // INHERITANCE
  33658. QUnit.test( "Extending", ( assert ) => {
  33659. assert.ok( false, "everything's gonna be alright" );
  33660. } );
  33661. // INSTANCING
  33662. QUnit.test( "Instancing", ( assert ) => {
  33663. assert.ok( false, "everything's gonna be alright" );
  33664. } );
  33665. // PUBLIC STUFF
  33666. QUnit.test( "isPointsMaterial", ( assert ) => {
  33667. assert.ok( false, "everything's gonna be alright" );
  33668. } );
  33669. QUnit.test( "copy", ( assert ) => {
  33670. assert.ok( false, "everything's gonna be alright" );
  33671. } );
  33672. } );
  33673. } );
  33674. /**
  33675. * @author TristanVALCKE / https://github.com/Itee
  33676. */
  33677. /* global QUnit */
  33678. QUnit.module( 'Materials', () => {
  33679. QUnit.module.todo( 'RawShaderMaterial', () => {
  33680. // INHERITANCE
  33681. QUnit.test( "Extending", ( assert ) => {
  33682. assert.ok( false, "everything's gonna be alright" );
  33683. } );
  33684. // INSTANCING
  33685. QUnit.test( "Instancing", ( assert ) => {
  33686. assert.ok( false, "everything's gonna be alright" );
  33687. } );
  33688. // PUBLIC STUFF
  33689. QUnit.test( "isRawShaderMaterial", ( assert ) => {
  33690. assert.ok( false, "everything's gonna be alright" );
  33691. } );
  33692. } );
  33693. } );
  33694. /**
  33695. * @author TristanVALCKE / https://github.com/Itee
  33696. */
  33697. /* global QUnit */
  33698. QUnit.module( 'Materials', () => {
  33699. QUnit.module.todo( 'ShaderMaterial', () => {
  33700. // INHERITANCE
  33701. QUnit.test( "Extending", ( assert ) => {
  33702. assert.ok( false, "everything's gonna be alright" );
  33703. } );
  33704. // INSTANCING
  33705. QUnit.test( "Instancing", ( assert ) => {
  33706. assert.ok( false, "everything's gonna be alright" );
  33707. } );
  33708. // PUBLIC STUFF
  33709. QUnit.test( "isShaderwMaterial", ( assert ) => {
  33710. assert.ok( false, "everything's gonna be alright" );
  33711. } );
  33712. QUnit.test( "copy", ( assert ) => {
  33713. assert.ok( false, "everything's gonna be alright" );
  33714. } );
  33715. QUnit.test( "toJSON", ( assert ) => {
  33716. assert.ok( false, "everything's gonna be alright" );
  33717. } );
  33718. } );
  33719. } );
  33720. /**
  33721. * @author TristanVALCKE / https://github.com/Itee
  33722. */
  33723. /* global QUnit */
  33724. QUnit.module( 'Materials', () => {
  33725. QUnit.module.todo( 'LineBasicMaterial', () => {
  33726. // INHERITANCE
  33727. QUnit.test( "Extending", ( assert ) => {
  33728. assert.ok( false, "everything's gonna be alright" );
  33729. } );
  33730. // INSTANCING
  33731. QUnit.test( "Instancing", ( assert ) => {
  33732. assert.ok( false, "everything's gonna be alright" );
  33733. } );
  33734. // PUBLIC STUFF
  33735. QUnit.test( "isShadowMaterial", ( assert ) => {
  33736. assert.ok( false, "everything's gonna be alright" );
  33737. } );
  33738. } );
  33739. } );
  33740. /**
  33741. * @author TristanVALCKE / https://github.com/Itee
  33742. */
  33743. /* global QUnit */
  33744. QUnit.module( 'Materials', () => {
  33745. QUnit.module.todo( 'SpriteMaterial', () => {
  33746. // INHERITANCE
  33747. QUnit.test( "Extending", ( assert ) => {
  33748. assert.ok( false, "everything's gonna be alright" );
  33749. } );
  33750. // INSTANCING
  33751. QUnit.test( "Instancing", ( assert ) => {
  33752. assert.ok( false, "everything's gonna be alright" );
  33753. } );
  33754. // PUBLIC STUFF
  33755. QUnit.test( "isSpriteMaterial", ( assert ) => {
  33756. assert.ok( false, "everything's gonna be alright" );
  33757. } );
  33758. QUnit.test( "copy", ( assert ) => {
  33759. assert.ok( false, "everything's gonna be alright" );
  33760. } );
  33761. } );
  33762. } );
  33763. /**
  33764. * @author bhouston / http://exocortex.com
  33765. * @author TristanVALCKE / https://github.com/Itee
  33766. */
  33767. /* global QUnit */
  33768. QUnit.module( 'Maths', () => {
  33769. QUnit.module.todo( 'Box2', () => {
  33770. // INSTANCING
  33771. QUnit.test( "Instancing", ( assert ) => {
  33772. var a = new Box2();
  33773. assert.ok( a.min.equals( posInf2 ), "Passed!" );
  33774. assert.ok( a.max.equals( negInf2 ), "Passed!" );
  33775. var a = new Box2( zero2.clone(), zero2.clone() );
  33776. assert.ok( a.min.equals( zero2 ), "Passed!" );
  33777. assert.ok( a.max.equals( zero2 ), "Passed!" );
  33778. var a = new Box2( zero2.clone(), one2.clone() );
  33779. assert.ok( a.min.equals( zero2 ), "Passed!" );
  33780. assert.ok( a.max.equals( one2 ), "Passed!" );
  33781. } );
  33782. // PUBLIC STUFF
  33783. QUnit.test( "set", ( assert ) => {
  33784. var a = new Box2();
  33785. a.set( zero2, one2 );
  33786. assert.ok( a.min.equals( zero2 ), "Passed!" );
  33787. assert.ok( a.max.equals( one2 ), "Passed!" );
  33788. } );
  33789. QUnit.test( "setFromPoints", ( assert ) => {
  33790. var a = new Box2();
  33791. a.setFromPoints( [ zero2, one2, two2 ] );
  33792. assert.ok( a.min.equals( zero2 ), "Passed!" );
  33793. assert.ok( a.max.equals( two2 ), "Passed!" );
  33794. a.setFromPoints( [ one2 ] );
  33795. assert.ok( a.min.equals( one2 ), "Passed!" );
  33796. assert.ok( a.max.equals( one2 ), "Passed!" );
  33797. a.setFromPoints( [] );
  33798. assert.ok( a.isEmpty(), "Passed!" );
  33799. } );
  33800. QUnit.test( "setFromCenterAndSize", ( assert ) => {
  33801. assert.ok( false, "everything's gonna be alright" );
  33802. } );
  33803. QUnit.test( "clone", ( assert ) => {
  33804. assert.ok( false, "everything's gonna be alright" );
  33805. } );
  33806. QUnit.test( "copy", ( assert ) => {
  33807. var a = new Box2( zero2.clone(), one2.clone() );
  33808. var b = new Box2().copy( a );
  33809. assert.ok( b.min.equals( zero2 ), "Passed!" );
  33810. assert.ok( b.max.equals( one2 ), "Passed!" );
  33811. // ensure that it is a true copy
  33812. a.min = zero2;
  33813. a.max = one2;
  33814. assert.ok( b.min.equals( zero2 ), "Passed!" );
  33815. assert.ok( b.max.equals( one2 ), "Passed!" );
  33816. } );
  33817. QUnit.test( "empty/makeEmpty", ( assert ) => {
  33818. var a = new Box2();
  33819. assert.ok( a.isEmpty(), "Passed!" );
  33820. var a = new Box2( zero2.clone(), one2.clone() );
  33821. assert.ok( ! a.isEmpty(), "Passed!" );
  33822. a.makeEmpty();
  33823. assert.ok( a.isEmpty(), "Passed!" );
  33824. } );
  33825. QUnit.test( "isEmpty", ( assert ) => {
  33826. assert.ok( false, "everything's gonna be alright" );
  33827. } );
  33828. QUnit.test( "getCenter", ( assert ) => {
  33829. var a = new Box2( zero2.clone(), zero2.clone() );
  33830. assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
  33831. var a = new Box2( zero2, one2 );
  33832. var midpoint = one2.clone().multiplyScalar( 0.5 );
  33833. assert.ok( a.getCenter().equals( midpoint ), "Passed!" );
  33834. } );
  33835. QUnit.test( "getSize", ( assert ) => {
  33836. var a = new Box2( zero2.clone(), zero2.clone() );
  33837. assert.ok( a.getSize().equals( zero2 ), "Passed!" );
  33838. var a = new Box2( zero2.clone(), one2.clone() );
  33839. assert.ok( a.getSize().equals( one2 ), "Passed!" );
  33840. } );
  33841. QUnit.test( "expandByPoint", ( assert ) => {
  33842. var a = new Box2( zero2.clone(), zero2.clone() );
  33843. a.expandByPoint( zero2 );
  33844. assert.ok( a.getSize().equals( zero2 ), "Passed!" );
  33845. a.expandByPoint( one2 );
  33846. assert.ok( a.getSize().equals( one2 ), "Passed!" );
  33847. a.expandByPoint( one2.clone().negate() );
  33848. assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
  33849. assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
  33850. } );
  33851. QUnit.test( "expandByVector", ( assert ) => {
  33852. var a = new Box2( zero2.clone(), zero2.clone() );
  33853. a.expandByVector( zero2 );
  33854. assert.ok( a.getSize().equals( zero2 ), "Passed!" );
  33855. a.expandByVector( one2 );
  33856. assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
  33857. assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
  33858. } );
  33859. QUnit.test( "expandByScalar", ( assert ) => {
  33860. var a = new Box2( zero2.clone(), zero2.clone() );
  33861. a.expandByScalar( 0 );
  33862. assert.ok( a.getSize().equals( zero2 ), "Passed!" );
  33863. a.expandByScalar( 1 );
  33864. assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
  33865. assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
  33866. } );
  33867. QUnit.test( "containsPoint", ( assert ) => {
  33868. var a = new Box2( zero2.clone(), zero2.clone() );
  33869. assert.ok( a.containsPoint( zero2 ), "Passed!" );
  33870. assert.ok( ! a.containsPoint( one2 ), "Passed!" );
  33871. a.expandByScalar( 1 );
  33872. assert.ok( a.containsPoint( zero2 ), "Passed!" );
  33873. assert.ok( a.containsPoint( one2 ), "Passed!" );
  33874. assert.ok( a.containsPoint( one2.clone().negate() ), "Passed!" );
  33875. } );
  33876. QUnit.test( "containsBox", ( assert ) => {
  33877. var a = new Box2( zero2.clone(), zero2.clone() );
  33878. var b = new Box2( zero2.clone(), one2.clone() );
  33879. var c = new Box2( one2.clone().negate(), one2.clone() );
  33880. assert.ok( a.containsBox( a ), "Passed!" );
  33881. assert.ok( ! a.containsBox( b ), "Passed!" );
  33882. assert.ok( ! a.containsBox( c ), "Passed!" );
  33883. assert.ok( b.containsBox( a ), "Passed!" );
  33884. assert.ok( c.containsBox( a ), "Passed!" );
  33885. assert.ok( ! b.containsBox( c ), "Passed!" );
  33886. } );
  33887. QUnit.test( "getParameter", ( assert ) => {
  33888. var a = new Box2( zero2.clone(), one2.clone() );
  33889. var b = new Box2( one2.clone().negate(), one2.clone() );
  33890. assert.ok( a.getParameter( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33891. assert.ok( a.getParameter( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
  33892. assert.ok( b.getParameter( new Vector2( - 1, - 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33893. assert.ok( b.getParameter( new Vector2( 0, 0 ) ).equals( new Vector2( 0.5, 0.5 ) ), "Passed!" );
  33894. assert.ok( b.getParameter( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
  33895. } );
  33896. QUnit.test( "intersectsBox", ( assert ) => {
  33897. var a = new Box2( zero2.clone(), zero2.clone() );
  33898. var b = new Box2( zero2.clone(), one2.clone() );
  33899. var c = new Box2( one2.clone().negate(), one2.clone() );
  33900. assert.ok( a.intersectsBox( a ), "Passed!" );
  33901. assert.ok( a.intersectsBox( b ), "Passed!" );
  33902. assert.ok( a.intersectsBox( c ), "Passed!" );
  33903. assert.ok( b.intersectsBox( a ), "Passed!" );
  33904. assert.ok( c.intersectsBox( a ), "Passed!" );
  33905. assert.ok( b.intersectsBox( c ), "Passed!" );
  33906. b.translate( new Vector2( 2, 2 ) );
  33907. assert.ok( ! a.intersectsBox( b ), "Passed!" );
  33908. assert.ok( ! b.intersectsBox( a ), "Passed!" );
  33909. assert.ok( ! b.intersectsBox( c ), "Passed!" );
  33910. } );
  33911. QUnit.test( "clampPoint", ( assert ) => {
  33912. var a = new Box2( zero2.clone(), zero2.clone() );
  33913. var b = new Box2( one2.clone().negate(), one2.clone() );
  33914. assert.ok( a.clampPoint( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33915. assert.ok( a.clampPoint( new Vector2( 1, 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33916. assert.ok( a.clampPoint( new Vector2( - 1, - 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33917. assert.ok( b.clampPoint( new Vector2( 2, 2 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
  33918. assert.ok( b.clampPoint( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
  33919. assert.ok( b.clampPoint( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33920. assert.ok( b.clampPoint( new Vector2( - 1, - 1 ) ).equals( new Vector2( - 1, - 1 ) ), "Passed!" );
  33921. assert.ok( b.clampPoint( new Vector2( - 2, - 2 ) ).equals( new Vector2( - 1, - 1 ) ), "Passed!" );
  33922. } );
  33923. QUnit.test( "distanceToPoint", ( assert ) => {
  33924. var a = new Box2( zero2.clone(), zero2.clone() );
  33925. var b = new Box2( one2.clone().negate(), one2.clone() );
  33926. assert.ok( a.distanceToPoint( new Vector2( 0, 0 ) ) == 0, "Passed!" );
  33927. assert.ok( a.distanceToPoint( new Vector2( 1, 1 ) ) == Math.sqrt( 2 ), "Passed!" );
  33928. assert.ok( a.distanceToPoint( new Vector2( - 1, - 1 ) ) == Math.sqrt( 2 ), "Passed!" );
  33929. assert.ok( b.distanceToPoint( new Vector2( 2, 2 ) ) == Math.sqrt( 2 ), "Passed!" );
  33930. assert.ok( b.distanceToPoint( new Vector2( 1, 1 ) ) == 0, "Passed!" );
  33931. assert.ok( b.distanceToPoint( new Vector2( 0, 0 ) ) == 0, "Passed!" );
  33932. assert.ok( b.distanceToPoint( new Vector2( - 1, - 1 ) ) == 0, "Passed!" );
  33933. assert.ok( b.distanceToPoint( new Vector2( - 2, - 2 ) ) == Math.sqrt( 2 ), "Passed!" );
  33934. } );
  33935. QUnit.test( "intersect", ( assert ) => {
  33936. var a = new Box2( zero2.clone(), zero2.clone() );
  33937. var b = new Box2( zero2.clone(), one2.clone() );
  33938. var c = new Box2( one2.clone().negate(), one2.clone() );
  33939. assert.ok( a.clone().intersect( a ).equals( a ), "Passed!" );
  33940. assert.ok( a.clone().intersect( b ).equals( a ), "Passed!" );
  33941. assert.ok( b.clone().intersect( b ).equals( b ), "Passed!" );
  33942. assert.ok( a.clone().intersect( c ).equals( a ), "Passed!" );
  33943. assert.ok( b.clone().intersect( c ).equals( b ), "Passed!" );
  33944. assert.ok( c.clone().intersect( c ).equals( c ), "Passed!" );
  33945. } );
  33946. QUnit.test( "union", ( assert ) => {
  33947. var a = new Box2( zero2.clone(), zero2.clone() );
  33948. var b = new Box2( zero2.clone(), one2.clone() );
  33949. var c = new Box2( one2.clone().negate(), one2.clone() );
  33950. assert.ok( a.clone().union( a ).equals( a ), "Passed!" );
  33951. assert.ok( a.clone().union( b ).equals( b ), "Passed!" );
  33952. assert.ok( a.clone().union( c ).equals( c ), "Passed!" );
  33953. assert.ok( b.clone().union( c ).equals( c ), "Passed!" );
  33954. } );
  33955. QUnit.test( "translate", ( assert ) => {
  33956. var a = new Box2( zero2.clone(), zero2.clone() );
  33957. var b = new Box2( zero2.clone(), one2.clone() );
  33958. var c = new Box2( one2.clone().negate(), one2.clone() );
  33959. var d = new Box2( one2.clone().negate(), zero2.clone() );
  33960. assert.ok( a.clone().translate( one2 ).equals( new Box2( one2, one2 ) ), "Passed!" );
  33961. assert.ok( a.clone().translate( one2 ).translate( one2.clone().negate() ).equals( a ), "Passed!" );
  33962. assert.ok( d.clone().translate( one2 ).equals( b ), "Passed!" );
  33963. assert.ok( b.clone().translate( one2.clone().negate() ).equals( d ), "Passed!" );
  33964. } );
  33965. QUnit.test( "equals", ( assert ) => {
  33966. assert.ok( false, "everything's gonna be alright" );
  33967. } );
  33968. } );
  33969. } );
  33970. /**
  33971. * @author bhouston / http://exocortex.com
  33972. * @author TristanVALCKE / https://github.com/Itee
  33973. */
  33974. /* global QUnit */
  33975. function compareBox( a, b, threshold ) {
  33976. threshold = threshold || 0.0001;
  33977. return ( a.min.distanceTo( b.min ) < threshold &&
  33978. a.max.distanceTo( b.max ) < threshold );
  33979. }
  33980. QUnit.module( 'Maths', () => {
  33981. QUnit.module.todo( 'Box3', () => {
  33982. // INSTANCING
  33983. QUnit.test( "Instancing", ( assert ) => {
  33984. var a = new Box3();
  33985. assert.ok( a.min.equals( posInf3 ), "Passed!" );
  33986. assert.ok( a.max.equals( negInf3 ), "Passed!" );
  33987. var a = new Box3( zero3.clone(), zero3.clone() );
  33988. assert.ok( a.min.equals( zero3 ), "Passed!" );
  33989. assert.ok( a.max.equals( zero3 ), "Passed!" );
  33990. var a = new Box3( zero3.clone(), one3.clone() );
  33991. assert.ok( a.min.equals( zero3 ), "Passed!" );
  33992. assert.ok( a.max.equals( one3 ), "Passed!" );
  33993. } );
  33994. // PUBLIC STUFF
  33995. QUnit.test( "isBox3", ( assert ) => {
  33996. assert.ok( false, "everything's gonna be alright" );
  33997. } );
  33998. QUnit.test( "set", ( assert ) => {
  33999. var a = new Box3();
  34000. a.set( zero3, one3 );
  34001. assert.ok( a.min.equals( zero3 ), "Passed!" );
  34002. assert.ok( a.max.equals( one3 ), "Passed!" );
  34003. } );
  34004. QUnit.test( "setFromArray", ( assert ) => {
  34005. assert.ok( false, "everything's gonna be alright" );
  34006. } );
  34007. QUnit.test( "setFromBufferAttribute", ( assert ) => {
  34008. var a = new Box3( zero3.clone(), one3.clone() );
  34009. var bigger = new BufferAttribute( new Float32Array( [
  34010. - 2, - 2, - 2, 2, 2, 2, 1.5, 1.5, 1.5, 0, 0, 0
  34011. ] ), 3 );
  34012. var smaller = new BufferAttribute( new Float32Array( [
  34013. - 0.5, - 0.5, - 0.5, 0.5, 0.5, 0.5, 0, 0, 0
  34014. ] ), 3 );
  34015. var newMin = new Vector3( - 2, - 2, - 2 );
  34016. var newMax = new Vector3( 2, 2, 2 );
  34017. a.setFromBufferAttribute( bigger );
  34018. assert.ok( a.min.equals( newMin ), "Bigger box: correct new minimum" );
  34019. assert.ok( a.max.equals( newMax ), "Bigger box: correct new maximum" );
  34020. newMin.set( - 0.5, - 0.5, - 0.5 );
  34021. newMax.set( 0.5, 0.5, 0.5 );
  34022. a.setFromBufferAttribute( smaller );
  34023. assert.ok( a.min.equals( newMin ), "Smaller box: correct new minimum" );
  34024. assert.ok( a.max.equals( newMax ), "Smaller box: correct new maximum" );
  34025. } );
  34026. QUnit.test( "setFromPoints", ( assert ) => {
  34027. var a = new Box3();
  34028. a.setFromPoints( [ zero3, one3, two3 ] );
  34029. assert.ok( a.min.equals( zero3 ), "Passed!" );
  34030. assert.ok( a.max.equals( two3 ), "Passed!" );
  34031. a.setFromPoints( [ one3 ] );
  34032. assert.ok( a.min.equals( one3 ), "Passed!" );
  34033. assert.ok( a.max.equals( one3 ), "Passed!" );
  34034. a.setFromPoints( [] );
  34035. assert.ok( a.isEmpty(), "Passed!" );
  34036. } );
  34037. QUnit.test( "setFromCenterAndSize", ( assert ) => {
  34038. var a = new Box3( zero3.clone(), one3.clone() );
  34039. var b = a.clone();
  34040. var newCenter = one3;
  34041. var newSize = two3;
  34042. a.setFromCenterAndSize( a.getCenter(), a.getSize() );
  34043. assert.ok( a.equals( b ), "Same values: no changes" );
  34044. a.setFromCenterAndSize( newCenter, a.getSize() );
  34045. assert.ok( a.getCenter().equals( newCenter ), "Move center: correct new center" );
  34046. assert.ok( a.getSize().equals( b.getSize() ), "Move center: no change in size" );
  34047. assert.notOk( a.equals( b ), "Move center: no longer equal to old values" );
  34048. a.setFromCenterAndSize( a.getCenter(), newSize );
  34049. assert.ok( a.getCenter().equals( newCenter ), "Resize: no change to center" );
  34050. assert.ok( a.getSize().equals( newSize ), "Resize: correct new size" );
  34051. assert.notOk( a.equals( b ), "Resize: no longer equal to old values" );
  34052. } );
  34053. QUnit.test( "setFromObject/BufferGeometry", ( assert ) => {
  34054. var a = new Box3( zero3.clone(), one3.clone() );
  34055. var object = new Mesh( new BoxBufferGeometry( 2, 2, 2 ) );
  34056. var child = new Mesh( new BoxBufferGeometry( 1, 1, 1 ) );
  34057. object.add( child );
  34058. a.setFromObject( object );
  34059. assert.ok( a.min.equals( new Vector3( - 1, - 1, - 1 ) ), "Correct new minimum" );
  34060. assert.ok( a.max.equals( new Vector3( 1, 1, 1 ) ), "Correct new maximum" );
  34061. } );
  34062. QUnit.test( "clone", ( assert ) => {
  34063. assert.ok( false, "everything's gonna be alright" );
  34064. } );
  34065. QUnit.test( "copy", ( assert ) => {
  34066. var a = new Box3( zero3.clone(), one3.clone() );
  34067. var b = new Box3().copy( a );
  34068. assert.ok( b.min.equals( zero3 ), "Passed!" );
  34069. assert.ok( b.max.equals( one3 ), "Passed!" );
  34070. // ensure that it is a true copy
  34071. a.min = zero3;
  34072. a.max = one3;
  34073. assert.ok( b.min.equals( zero3 ), "Passed!" );
  34074. assert.ok( b.max.equals( one3 ), "Passed!" );
  34075. } );
  34076. QUnit.test( "empty/makeEmpty", ( assert ) => {
  34077. var a = new Box3();
  34078. assert.ok( a.isEmpty(), "Passed!" );
  34079. var a = new Box3( zero3.clone(), one3.clone() );
  34080. assert.ok( ! a.isEmpty(), "Passed!" );
  34081. a.makeEmpty();
  34082. assert.ok( a.isEmpty(), "Passed!" );
  34083. } );
  34084. QUnit.test( "isEmpty", ( assert ) => {
  34085. assert.ok( false, "everything's gonna be alright" );
  34086. } );
  34087. QUnit.test( "getCenter", ( assert ) => {
  34088. var a = new Box3( zero3.clone(), zero3.clone() );
  34089. assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
  34090. var a = new Box3( zero3.clone(), one3.clone() );
  34091. var midpoint = one3.clone().multiplyScalar( 0.5 );
  34092. assert.ok( a.getCenter().equals( midpoint ), "Passed!" );
  34093. } );
  34094. QUnit.test( "getSize", ( assert ) => {
  34095. var a = new Box3( zero3.clone(), zero3.clone() );
  34096. assert.ok( a.getSize().equals( zero3 ), "Passed!" );
  34097. var a = new Box3( zero3.clone(), one3.clone() );
  34098. assert.ok( a.getSize().equals( one3 ), "Passed!" );
  34099. } );
  34100. QUnit.test( "expandByPoint", ( assert ) => {
  34101. var a = new Box3( zero3.clone(), zero3.clone() );
  34102. a.expandByPoint( zero3 );
  34103. assert.ok( a.getSize().equals( zero3 ), "Passed!" );
  34104. a.expandByPoint( one3 );
  34105. assert.ok( a.getSize().equals( one3 ), "Passed!" );
  34106. a.expandByPoint( one3.clone().negate() );
  34107. assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
  34108. assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
  34109. } );
  34110. QUnit.test( "expandByVector", ( assert ) => {
  34111. var a = new Box3( zero3.clone(), zero3.clone() );
  34112. a.expandByVector( zero3 );
  34113. assert.ok( a.getSize().equals( zero3 ), "Passed!" );
  34114. a.expandByVector( one3 );
  34115. assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
  34116. assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
  34117. } );
  34118. QUnit.test( "expandByScalar", ( assert ) => {
  34119. var a = new Box3( zero3.clone(), zero3.clone() );
  34120. a.expandByScalar( 0 );
  34121. assert.ok( a.getSize().equals( zero3 ), "Passed!" );
  34122. a.expandByScalar( 1 );
  34123. assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
  34124. assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
  34125. } );
  34126. QUnit.test( "expandByObject", ( assert ) => {
  34127. var a = new Box3( zero3.clone(), one3.clone() );
  34128. var b = a.clone();
  34129. var bigger = new Mesh( new BoxGeometry( 2, 2, 2 ) );
  34130. var smaller = new Mesh( new BoxGeometry( 0.5, 0.5, 0.5 ) );
  34131. var child = new Mesh( new BoxGeometry( 1, 1, 1 ) );
  34132. // just a bigger box to begin with
  34133. a.expandByObject( bigger );
  34134. assert.ok( a.min.equals( new Vector3( - 1, - 1, - 1 ) ), "Bigger box: correct new minimum" );
  34135. assert.ok( a.max.equals( new Vector3( 1, 1, 1 ) ), "Bigger box: correct new maximum" );
  34136. // a translated, bigger box
  34137. a.copy( b );
  34138. bigger.translateX( 2 );
  34139. a.expandByObject( bigger );
  34140. assert.ok( a.min.equals( new Vector3( 0, - 1, - 1 ) ), "Translated, bigger box: correct new minimum" );
  34141. assert.ok( a.max.equals( new Vector3( 3, 1, 1 ) ), "Translated, bigger box: correct new maximum" );
  34142. // a translated, bigger box with child
  34143. a.copy( b );
  34144. bigger.add( child );
  34145. a.expandByObject( bigger );
  34146. assert.ok( a.min.equals( new Vector3( 0, - 1, - 1 ) ), "Translated, bigger box with child: correct new minimum" );
  34147. assert.ok( a.max.equals( new Vector3( 3, 1, 1 ) ), "Translated, bigger box with child: correct new maximum" );
  34148. // a translated, bigger box with a translated child
  34149. a.copy( b );
  34150. child.translateX( 2 );
  34151. a.expandByObject( bigger );
  34152. assert.ok( a.min.equals( new Vector3( 0, - 1, - 1 ) ), "Translated, bigger box with translated child: correct new minimum" );
  34153. assert.ok( a.max.equals( new Vector3( 4.5, 1, 1 ) ), "Translated, bigger box with translated child: correct new maximum" );
  34154. // a smaller box
  34155. a.copy( b );
  34156. a.expandByObject( smaller );
  34157. assert.ok( a.min.equals( new Vector3( - 0.25, - 0.25, - 0.25 ) ), "Smaller box: correct new minimum" );
  34158. assert.ok( a.max.equals( new Vector3( 1, 1, 1 ) ), "Smaller box: correct new maximum" );
  34159. } );
  34160. QUnit.test( "containsPoint", ( assert ) => {
  34161. var a = new Box3( zero3.clone(), zero3.clone() );
  34162. assert.ok( a.containsPoint( zero3 ), "Passed!" );
  34163. assert.ok( ! a.containsPoint( one3 ), "Passed!" );
  34164. a.expandByScalar( 1 );
  34165. assert.ok( a.containsPoint( zero3 ), "Passed!" );
  34166. assert.ok( a.containsPoint( one3 ), "Passed!" );
  34167. assert.ok( a.containsPoint( one3.clone().negate() ), "Passed!" );
  34168. } );
  34169. QUnit.test( "containsBox", ( assert ) => {
  34170. var a = new Box3( zero3.clone(), zero3.clone() );
  34171. var b = new Box3( zero3.clone(), one3.clone() );
  34172. var c = new Box3( one3.clone().negate(), one3.clone() );
  34173. assert.ok( a.containsBox( a ), "Passed!" );
  34174. assert.ok( ! a.containsBox( b ), "Passed!" );
  34175. assert.ok( ! a.containsBox( c ), "Passed!" );
  34176. assert.ok( b.containsBox( a ), "Passed!" );
  34177. assert.ok( c.containsBox( a ), "Passed!" );
  34178. assert.ok( ! b.containsBox( c ), "Passed!" );
  34179. } );
  34180. QUnit.test( "getParameter", ( assert ) => {
  34181. var a = new Box3( zero3.clone(), one3.clone() );
  34182. var b = new Box3( one3.clone().negate(), one3.clone() );
  34183. assert.ok( a.getParameter( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34184. assert.ok( a.getParameter( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
  34185. assert.ok( b.getParameter( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34186. assert.ok( b.getParameter( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0.5, 0.5, 0.5 ) ), "Passed!" );
  34187. assert.ok( b.getParameter( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
  34188. } );
  34189. QUnit.test( "intersectsBox", ( assert ) => {
  34190. var a = new Box3( zero3.clone(), zero3.clone() );
  34191. var b = new Box3( zero3.clone(), one3.clone() );
  34192. var c = new Box3( one3.clone().negate(), one3.clone() );
  34193. assert.ok( a.intersectsBox( a ), "Passed!" );
  34194. assert.ok( a.intersectsBox( b ), "Passed!" );
  34195. assert.ok( a.intersectsBox( c ), "Passed!" );
  34196. assert.ok( b.intersectsBox( a ), "Passed!" );
  34197. assert.ok( c.intersectsBox( a ), "Passed!" );
  34198. assert.ok( b.intersectsBox( c ), "Passed!" );
  34199. b.translate( new Vector3( 2, 2, 2 ) );
  34200. assert.ok( ! a.intersectsBox( b ), "Passed!" );
  34201. assert.ok( ! b.intersectsBox( a ), "Passed!" );
  34202. assert.ok( ! b.intersectsBox( c ), "Passed!" );
  34203. } );
  34204. QUnit.test( "intersectsSphere", ( assert ) => {
  34205. var a = new Box3( zero3.clone(), one3.clone() );
  34206. var b = new Sphere( zero3.clone(), 1 );
  34207. assert.ok( a.intersectsSphere( b ), "Passed!" );
  34208. b.translate( new Vector3( 2, 2, 2 ) );
  34209. assert.ok( ! a.intersectsSphere( b ), "Passed!" );
  34210. } );
  34211. QUnit.test( "intersectsPlane", ( assert ) => {
  34212. var a = new Box3( zero3.clone(), one3.clone() );
  34213. var b = new Plane( new Vector3( 0, 1, 0 ), 1 );
  34214. var c = new Plane( new Vector3( 0, 1, 0 ), 1.25 );
  34215. var d = new Plane( new Vector3( 0, - 1, 0 ), 1.25 );
  34216. assert.ok( a.intersectsPlane( b ), "Passed!" );
  34217. assert.ok( ! a.intersectsPlane( c ), "Passed!" );
  34218. assert.ok( ! a.intersectsPlane( d ), "Passed!" );
  34219. } );
  34220. QUnit.test( "clampPoint", ( assert ) => {
  34221. var a = new Box3( zero3.clone(), zero3.clone() );
  34222. var b = new Box3( one3.clone().negate(), one3.clone() );
  34223. assert.ok( a.clampPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34224. assert.ok( a.clampPoint( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34225. assert.ok( a.clampPoint( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34226. assert.ok( b.clampPoint( new Vector3( 2, 2, 2 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
  34227. assert.ok( b.clampPoint( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
  34228. assert.ok( b.clampPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34229. assert.ok( b.clampPoint( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
  34230. assert.ok( b.clampPoint( new Vector3( - 2, - 2, - 2 ) ).equals( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
  34231. } );
  34232. QUnit.test( "distanceToPoint", ( assert ) => {
  34233. var a = new Box3( zero3.clone(), zero3.clone() );
  34234. var b = new Box3( one3.clone().negate(), one3.clone() );
  34235. assert.ok( a.distanceToPoint( new Vector3( 0, 0, 0 ) ) == 0, "Passed!" );
  34236. assert.ok( a.distanceToPoint( new Vector3( 1, 1, 1 ) ) == Math.sqrt( 3 ), "Passed!" );
  34237. assert.ok( a.distanceToPoint( new Vector3( - 1, - 1, - 1 ) ) == Math.sqrt( 3 ), "Passed!" );
  34238. assert.ok( b.distanceToPoint( new Vector3( 2, 2, 2 ) ) == Math.sqrt( 3 ), "Passed!" );
  34239. assert.ok( b.distanceToPoint( new Vector3( 1, 1, 1 ) ) == 0, "Passed!" );
  34240. assert.ok( b.distanceToPoint( new Vector3( 0, 0, 0 ) ) == 0, "Passed!" );
  34241. assert.ok( b.distanceToPoint( new Vector3( - 1, - 1, - 1 ) ) == 0, "Passed!" );
  34242. assert.ok( b.distanceToPoint( new Vector3( - 2, - 2, - 2 ) ) == Math.sqrt( 3 ), "Passed!" );
  34243. } );
  34244. QUnit.test( "getBoundingSphere", ( assert ) => {
  34245. var a = new Box3( zero3.clone(), zero3.clone() );
  34246. var b = new Box3( zero3.clone(), one3.clone() );
  34247. var c = new Box3( one3.clone().negate(), one3.clone() );
  34248. assert.ok( a.getBoundingSphere().equals( new Sphere( zero3, 0 ) ), "Passed!" );
  34249. assert.ok( b.getBoundingSphere().equals( new Sphere( one3.clone().multiplyScalar( 0.5 ), Math.sqrt( 3 ) * 0.5 ) ), "Passed!" );
  34250. assert.ok( c.getBoundingSphere().equals( new Sphere( zero3, Math.sqrt( 12 ) * 0.5 ) ), "Passed!" );
  34251. } );
  34252. QUnit.test( "intersect", ( assert ) => {
  34253. var a = new Box3( zero3.clone(), zero3.clone() );
  34254. var b = new Box3( zero3.clone(), one3.clone() );
  34255. var c = new Box3( one3.clone().negate(), one3.clone() );
  34256. assert.ok( a.clone().intersect( a ).equals( a ), "Passed!" );
  34257. assert.ok( a.clone().intersect( b ).equals( a ), "Passed!" );
  34258. assert.ok( b.clone().intersect( b ).equals( b ), "Passed!" );
  34259. assert.ok( a.clone().intersect( c ).equals( a ), "Passed!" );
  34260. assert.ok( b.clone().intersect( c ).equals( b ), "Passed!" );
  34261. assert.ok( c.clone().intersect( c ).equals( c ), "Passed!" );
  34262. } );
  34263. QUnit.test( "union", ( assert ) => {
  34264. var a = new Box3( zero3.clone(), zero3.clone() );
  34265. var b = new Box3( zero3.clone(), one3.clone() );
  34266. var c = new Box3( one3.clone().negate(), one3.clone() );
  34267. assert.ok( a.clone().union( a ).equals( a ), "Passed!" );
  34268. assert.ok( a.clone().union( b ).equals( b ), "Passed!" );
  34269. assert.ok( a.clone().union( c ).equals( c ), "Passed!" );
  34270. assert.ok( b.clone().union( c ).equals( c ), "Passed!" );
  34271. } );
  34272. QUnit.test( "applyMatrix4", ( assert ) => {
  34273. var a = new Box3( zero3.clone(), zero3.clone() );
  34274. var b = new Box3( zero3.clone(), one3.clone() );
  34275. var c = new Box3( one3.clone().negate(), one3.clone() );
  34276. var d = new Box3( one3.clone().negate(), zero3.clone() );
  34277. var m = new Matrix4().makeTranslation( 1, - 2, 1 );
  34278. var t1 = new Vector3( 1, - 2, 1 );
  34279. assert.ok( compareBox( a.clone().applyMatrix4( m ), a.clone().translate( t1 ) ), "Passed!" );
  34280. assert.ok( compareBox( b.clone().applyMatrix4( m ), b.clone().translate( t1 ) ), "Passed!" );
  34281. assert.ok( compareBox( c.clone().applyMatrix4( m ), c.clone().translate( t1 ) ), "Passed!" );
  34282. assert.ok( compareBox( d.clone().applyMatrix4( m ), d.clone().translate( t1 ) ), "Passed!" );
  34283. } );
  34284. QUnit.test( "translate", ( assert ) => {
  34285. var a = new Box3( zero3.clone(), zero3.clone() );
  34286. var b = new Box3( zero3.clone(), one3.clone() );
  34287. var c = new Box3( one3.clone().negate(), one3.clone() );
  34288. var d = new Box3( one3.clone().negate(), zero3.clone() );
  34289. assert.ok( a.clone().translate( one3 ).equals( new Box3( one3, one3 ) ), "Passed!" );
  34290. assert.ok( a.clone().translate( one3 ).translate( one3.clone().negate() ).equals( a ), "Passed!" );
  34291. assert.ok( d.clone().translate( one3 ).equals( b ), "Passed!" );
  34292. assert.ok( b.clone().translate( one3.clone().negate() ).equals( d ), "Passed!" );
  34293. } );
  34294. QUnit.test( "equals", ( assert ) => {
  34295. assert.ok( false, "everything's gonna be alright" );
  34296. } );
  34297. } );
  34298. } );
  34299. /**
  34300. * @author bhouston / http://exocortex.com
  34301. * @author TristanVALCKE / https://github.com/Itee
  34302. */
  34303. /* global QUnit */
  34304. QUnit.module( 'Maths', () => {
  34305. QUnit.module.todo( 'Color', () => {
  34306. // INSTANCING
  34307. QUnit.test( "Instancing", ( assert ) => {
  34308. // default ctor
  34309. var c = new Color();
  34310. assert.ok( c.r, "Red: " + c.r );
  34311. assert.ok( c.g, "Green: " + c.g );
  34312. assert.ok( c.b, "Blue: " + c.b );
  34313. // rgb ctor
  34314. var c = new Color( 1, 1, 1 );
  34315. assert.ok( c.r == 1, "Passed" );
  34316. assert.ok( c.g == 1, "Passed" );
  34317. assert.ok( c.b == 1, "Passed" );
  34318. } );
  34319. // PUBLIC STUFF
  34320. QUnit.test( "isColor", ( assert ) => {
  34321. assert.ok( false, "everything's gonna be alright" );
  34322. } );
  34323. QUnit.test( "set", ( assert ) => {
  34324. var a = new Color();
  34325. var b = new Color( 0.5, 0, 0 );
  34326. var c = new Color( 0xFF0000 );
  34327. var d = new Color( 0, 1.0, 0 );
  34328. a.set( b );
  34329. assert.ok( a.equals( b ), "Set with Color instance" );
  34330. a.set( 0xFF0000 );
  34331. assert.ok( a.equals( c ), "Set with number" );
  34332. a.set( "rgb(0,255,0)" );
  34333. assert.ok( a.equals( d ), "Set with style" );
  34334. } );
  34335. QUnit.test( "setScalar", ( assert ) => {
  34336. assert.ok( false, "everything's gonna be alright" );
  34337. } );
  34338. QUnit.test( "setHex", ( assert ) => {
  34339. var c = new Color();
  34340. c.setHex( 0xFA8072 );
  34341. assert.ok( c.getHex() == 0xFA8072, "Hex: " + c.getHex() );
  34342. } );
  34343. QUnit.test( "setRGB", ( assert ) => {
  34344. assert.ok( false, "everything's gonna be alright" );
  34345. } );
  34346. QUnit.test( "setHSL", ( assert ) => {
  34347. var c = new Color();
  34348. c.setHSL( 0.75, 1.0, 0.25 );
  34349. var hsl = c.getHSL();
  34350. assert.ok( hsl.h == 0.75, "hue: " + hsl.h );
  34351. assert.ok( hsl.s == 1.00, "saturation: " + hsl.s );
  34352. assert.ok( hsl.l == 0.25, "lightness: " + hsl.l );
  34353. } );
  34354. QUnit.test( "setStyle", ( assert ) => {
  34355. assert.ok( false, "everything's gonna be alright" );
  34356. } );
  34357. QUnit.test( "clone", ( assert ) => {
  34358. var c = new Color( 'teal' );
  34359. var c2 = c.clone();
  34360. assert.ok( c2.getHex() == 0x008080, "Hex c2: " + c2.getHex() );
  34361. } );
  34362. QUnit.test( "copy", ( assert ) => {
  34363. assert.ok( false, "everything's gonna be alright" );
  34364. } );
  34365. QUnit.test( "copyGammaToLinear", ( assert ) => {
  34366. var c = new Color();
  34367. var c2 = new Color();
  34368. c2.setRGB( 0.3, 0.5, 0.9 );
  34369. c.copyGammaToLinear( c2 );
  34370. assert.ok( c.r == 0.09, "Red c: " + c.r + " Red c2: " + c2.r );
  34371. assert.ok( c.g == 0.25, "Green c: " + c.g + " Green c2: " + c2.g );
  34372. assert.ok( c.b == 0.81, "Blue c: " + c.b + " Blue c2: " + c2.b );
  34373. } );
  34374. QUnit.test( "copyLinearToGamma", ( assert ) => {
  34375. var c = new Color();
  34376. var c2 = new Color();
  34377. c2.setRGB( 0.09, 0.25, 0.81 );
  34378. c.copyLinearToGamma( c2 );
  34379. assert.ok( c.r == 0.3, "Red c: " + c.r + " Red c2: " + c2.r );
  34380. assert.ok( c.g == 0.5, "Green c: " + c.g + " Green c2: " + c2.g );
  34381. assert.ok( c.b == 0.9, "Blue c: " + c.b + " Blue c2: " + c2.b );
  34382. } );
  34383. QUnit.test( "convertGammaToLinear", ( assert ) => {
  34384. var c = new Color();
  34385. c.setRGB( 0.3, 0.5, 0.9 );
  34386. c.convertGammaToLinear();
  34387. assert.ok( c.r == 0.09, "Red: " + c.r );
  34388. assert.ok( c.g == 0.25, "Green: " + c.g );
  34389. assert.ok( c.b == 0.81, "Blue: " + c.b );
  34390. } );
  34391. QUnit.test( "convertLinearToGamma", ( assert ) => {
  34392. var c = new Color();
  34393. c.setRGB( 4, 9, 16 );
  34394. c.convertLinearToGamma();
  34395. assert.ok( c.r == 2, "Red: " + c.r );
  34396. assert.ok( c.g == 3, "Green: " + c.g );
  34397. assert.ok( c.b == 4, "Blue: " + c.b );
  34398. } );
  34399. QUnit.test( "getHex", ( assert ) => {
  34400. var c = new Color( 'red' );
  34401. var res = c.getHex();
  34402. assert.ok( res == 0xFF0000, "Hex: " + res );
  34403. } );
  34404. QUnit.test( "getHexString", ( assert ) => {
  34405. var c = new Color( 'tomato' );
  34406. var res = c.getHexString();
  34407. assert.ok( res == 'ff6347', "Hex: " + res );
  34408. } );
  34409. QUnit.test( "getHSL", ( assert ) => {
  34410. var c = new Color( 0x80ffff );
  34411. var hsl = c.getHSL();
  34412. assert.ok( hsl.h == 0.5, "hue: " + hsl.h );
  34413. assert.ok( hsl.s == 1.0, "saturation: " + hsl.s );
  34414. assert.ok( ( Math.round( parseFloat( hsl.l ) * 100 ) / 100 ) == 0.75, "lightness: " + hsl.l );
  34415. } );
  34416. QUnit.test( "getStyle", ( assert ) => {
  34417. var c = new Color( 'plum' );
  34418. var res = c.getStyle();
  34419. assert.ok( res == 'rgb(221,160,221)', "style: " + res );
  34420. } );
  34421. QUnit.test( "offsetHSL", ( assert ) => {
  34422. var a = new Color( "hsl(120,50%,50%)" );
  34423. var b = new Color( 0.36, 0.84, 0.648 );
  34424. a.offsetHSL( 0.1, 0.1, 0.1 );
  34425. assert.ok( Math.abs( a.r - b.r ) <= eps, "Check r" );
  34426. assert.ok( Math.abs( a.g - b.g ) <= eps, "Check g" );
  34427. assert.ok( Math.abs( a.b - b.b ) <= eps, "Check b" );
  34428. } );
  34429. QUnit.test( "add", ( assert ) => {
  34430. var a = new Color( 0x0000FF );
  34431. var b = new Color( 0xFF0000 );
  34432. var c = new Color( 0xFF00FF );
  34433. a.add( b );
  34434. assert.ok( a.equals( c ), "Check new value" );
  34435. } );
  34436. QUnit.test( "addColors", ( assert ) => {
  34437. assert.ok( false, "everything's gonna be alright" );
  34438. } );
  34439. QUnit.test( "addScalar", ( assert ) => {
  34440. var a = new Color( 0.1, 0.0, 0.0 );
  34441. var b = new Color( 0.6, 0.5, 0.5 );
  34442. a.addScalar( 0.5 );
  34443. assert.ok( a.equals( b ), "Check new value" );
  34444. } );
  34445. QUnit.test( "sub", ( assert ) => {
  34446. var a = new Color( 0x0000CC );
  34447. var b = new Color( 0xFF0000 );
  34448. var c = new Color( 0x0000AA );
  34449. a.sub( b );
  34450. assert.strictEqual( a.getHex(), 0xCC, "Difference too large" );
  34451. a.sub( c );
  34452. assert.strictEqual( a.getHex(), 0x22, "Difference fine" );
  34453. } );
  34454. QUnit.test( "multiply", ( assert ) => {
  34455. var a = new Color( 1, 0, 0.5 );
  34456. var b = new Color( 0.5, 1, 0.5 );
  34457. var c = new Color( 0.5, 0, 0.25 );
  34458. a.multiply( b );
  34459. assert.ok( a.equals( c ), "Check new value" );
  34460. } );
  34461. QUnit.test( "multiplyScalar", ( assert ) => {
  34462. var a = new Color( 0.25, 0, 0.5 );
  34463. var b = new Color( 0.5, 0, 1 );
  34464. a.multiplyScalar( 2 );
  34465. assert.ok( a.equals( b ), "Check new value" );
  34466. } );
  34467. QUnit.test( "copyHex", ( assert ) => {
  34468. var c = new Color();
  34469. var c2 = new Color( 0xF5FFFA );
  34470. c.copy( c2 );
  34471. assert.ok( c.getHex() == c2.getHex(), "Hex c: " + c.getHex() + " Hex c2: " + c2.getHex() );
  34472. } );
  34473. QUnit.test( "copyColorString", ( assert ) => {
  34474. var c = new Color();
  34475. var c2 = new Color( 'ivory' );
  34476. c.copy( c2 );
  34477. assert.ok( c.getHex() == c2.getHex(), "Hex c: " + c.getHex() + " Hex c2: " + c2.getHex() );
  34478. } );
  34479. QUnit.test( "setRGB", ( assert ) => {
  34480. var c = new Color();
  34481. c.setRGB( 1, 0.2, 0.1 );
  34482. assert.ok( c.r == 1, "Red: " + c.r );
  34483. assert.ok( c.g == 0.2, "Green: " + c.g );
  34484. assert.ok( c.b == 0.1, "Blue: " + c.b );
  34485. } );
  34486. QUnit.test( "lerp", ( assert ) => {
  34487. var c = new Color();
  34488. var c2 = new Color();
  34489. c.setRGB( 0, 0, 0 );
  34490. c.lerp( c2, 0.2 );
  34491. assert.ok( c.r == 0.2, "Red: " + c.r );
  34492. assert.ok( c.g == 0.2, "Green: " + c.g );
  34493. assert.ok( c.b == 0.2, "Blue: " + c.b );
  34494. } );
  34495. QUnit.test( "equals", ( assert ) => {
  34496. var a = new Color( 0.5, 0.0, 1.0 );
  34497. var b = new Color( 0.5, 1.0, 0.0 );
  34498. assert.strictEqual( a.r, b.r, "Components: r is equal" );
  34499. assert.notStrictEqual( a.g, b.g, "Components: g is not equal" );
  34500. assert.notStrictEqual( a.b, b.b, "Components: b is not equal" );
  34501. assert.notOk( a.equals( b ), "equals(): a not equal b" );
  34502. assert.notOk( b.equals( a ), "equals(): b not equal a" );
  34503. a.copy( b );
  34504. assert.strictEqual( a.r, b.r, "Components after copy(): r is equal" );
  34505. assert.strictEqual( a.g, b.g, "Components after copy(): g is equal" );
  34506. assert.strictEqual( a.b, b.b, "Components after copy(): b is equal" );
  34507. assert.ok( a.equals( b ), "equals() after copy(): a equals b" );
  34508. assert.ok( b.equals( a ), "equals() after copy(): b equals a" );
  34509. } );
  34510. QUnit.test( "fromArray", ( assert ) => {
  34511. var a = new Color();
  34512. var array = [ 0.5, 0.6, 0.7, 0, 1, 0 ];
  34513. a.fromArray( array );
  34514. assert.strictEqual( a.r, 0.5, "No offset: check r" );
  34515. assert.strictEqual( a.g, 0.6, "No offset: check g" );
  34516. assert.strictEqual( a.b, 0.7, "No offset: check b" );
  34517. a.fromArray( array, 3 );
  34518. assert.strictEqual( a.r, 0, "With offset: check r" );
  34519. assert.strictEqual( a.g, 1, "With offset: check g" );
  34520. assert.strictEqual( a.b, 0, "With offset: check b" );
  34521. } );
  34522. QUnit.test( "toArray", ( assert ) => {
  34523. var r = 0.5, g = 1.0, b = 0.0;
  34524. var a = new Color( r, g, b );
  34525. var array = a.toArray();
  34526. assert.strictEqual( array[ 0 ], r, "No array, no offset: check r" );
  34527. assert.strictEqual( array[ 1 ], g, "No array, no offset: check g" );
  34528. assert.strictEqual( array[ 2 ], b, "No array, no offset: check b" );
  34529. var array = [];
  34530. a.toArray( array );
  34531. assert.strictEqual( array[ 0 ], r, "With array, no offset: check r" );
  34532. assert.strictEqual( array[ 1 ], g, "With array, no offset: check g" );
  34533. assert.strictEqual( array[ 2 ], b, "With array, no offset: check b" );
  34534. var array = [];
  34535. a.toArray( array, 1 );
  34536. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  34537. assert.strictEqual( array[ 1 ], r, "With array and offset: check r" );
  34538. assert.strictEqual( array[ 2 ], g, "With array and offset: check g" );
  34539. assert.strictEqual( array[ 3 ], b, "With array and offset: check b" );
  34540. } );
  34541. QUnit.test( "toJSON", ( assert ) => {
  34542. var a = new Color( 0.0, 0.0, 0.0 );
  34543. var b = new Color( 0.0, 0.5, 0.0 );
  34544. var c = new Color( 1.0, 0.0, 0.0 );
  34545. var d = new Color( 1.0, 1.0, 1.0 );
  34546. assert.strictEqual( a.toJSON(), 0x000000, "Check black" );
  34547. assert.strictEqual( b.toJSON(), 0x007F00, "Check half-blue" );
  34548. assert.strictEqual( c.toJSON(), 0xFF0000, "Check red" );
  34549. assert.strictEqual( d.toJSON(), 0xFFFFFF, "Check white" );
  34550. } );
  34551. // OTHERS
  34552. QUnit.test( "setWithNum", ( assert ) => {
  34553. var c = new Color();
  34554. c.set( 0xFF0000 );
  34555. assert.ok( c.r == 1, "Red: " + c.r );
  34556. assert.ok( c.g === 0, "Green: " + c.g );
  34557. assert.ok( c.b === 0, "Blue: " + c.b );
  34558. } );
  34559. QUnit.test( "setWithString", ( assert ) => {
  34560. var c = new Color();
  34561. c.set( 'silver' );
  34562. assert.ok( c.getHex() == 0xC0C0C0, "Hex c: " + c.getHex() );
  34563. } );
  34564. QUnit.test( "setStyleRGBRed", ( assert ) => {
  34565. var c = new Color();
  34566. c.setStyle( 'rgb(255,0,0)' );
  34567. assert.ok( c.r == 1, "Red: " + c.r );
  34568. assert.ok( c.g === 0, "Green: " + c.g );
  34569. assert.ok( c.b === 0, "Blue: " + c.b );
  34570. } );
  34571. QUnit.test( "setStyleRGBARed", ( assert ) => {
  34572. var c = new Color();
  34573. c.setStyle( 'rgba(255,0,0,0.5)' );
  34574. assert.ok( c.r == 1, "Red: " + c.r );
  34575. assert.ok( c.g === 0, "Green: " + c.g );
  34576. assert.ok( c.b === 0, "Blue: " + c.b );
  34577. } );
  34578. QUnit.test( "setStyleRGBRedWithSpaces", ( assert ) => {
  34579. var c = new Color();
  34580. c.setStyle( 'rgb( 255 , 0, 0 )' );
  34581. assert.ok( c.r == 1, "Red: " + c.r );
  34582. assert.ok( c.g === 0, "Green: " + c.g );
  34583. assert.ok( c.b === 0, "Blue: " + c.b );
  34584. } );
  34585. QUnit.test( "setStyleRGBARedWithSpaces", ( assert ) => {
  34586. var c = new Color();
  34587. c.setStyle( 'rgba( 255, 0, 0 , 1 )' );
  34588. assert.ok( c.r == 1, "Red: " + c.r );
  34589. assert.ok( c.g === 0, "Green: " + c.g );
  34590. assert.ok( c.b === 0, "Blue: " + c.b );
  34591. } );
  34592. QUnit.test( "setStyleRGBPercent", ( assert ) => {
  34593. var c = new Color();
  34594. c.setStyle( 'rgb(100%,50%,10%)' );
  34595. assert.ok( c.r == 1, "Red: " + c.r );
  34596. assert.ok( c.g == 0.5, "Green: " + c.g );
  34597. assert.ok( c.b == 0.1, "Blue: " + c.b );
  34598. } );
  34599. QUnit.test( "setStyleRGBAPercent", ( assert ) => {
  34600. var c = new Color();
  34601. c.setStyle( 'rgba(100%,50%,10%, 0.5)' );
  34602. assert.ok( c.r == 1, "Red: " + c.r );
  34603. assert.ok( c.g == 0.5, "Green: " + c.g );
  34604. assert.ok( c.b == 0.1, "Blue: " + c.b );
  34605. } );
  34606. QUnit.test( "setStyleRGBPercentWithSpaces", ( assert ) => {
  34607. var c = new Color();
  34608. c.setStyle( 'rgb( 100% ,50% , 10% )' );
  34609. assert.ok( c.r == 1, "Red: " + c.r );
  34610. assert.ok( c.g == 0.5, "Green: " + c.g );
  34611. assert.ok( c.b == 0.1, "Blue: " + c.b );
  34612. } );
  34613. QUnit.test( "setStyleRGBAPercentWithSpaces", ( assert ) => {
  34614. var c = new Color();
  34615. c.setStyle( 'rgba( 100% ,50% , 10%, 0.5 )' );
  34616. assert.ok( c.r == 1, "Red: " + c.r );
  34617. assert.ok( c.g == 0.5, "Green: " + c.g );
  34618. assert.ok( c.b == 0.1, "Blue: " + c.b );
  34619. } );
  34620. QUnit.test( "setStyleHSLRed", ( assert ) => {
  34621. var c = new Color();
  34622. c.setStyle( 'hsl(360,100%,50%)' );
  34623. assert.ok( c.r == 1, "Red: " + c.r );
  34624. assert.ok( c.g === 0, "Green: " + c.g );
  34625. assert.ok( c.b === 0, "Blue: " + c.b );
  34626. } );
  34627. QUnit.test( "setStyleHSLARed", ( assert ) => {
  34628. var c = new Color();
  34629. c.setStyle( 'hsla(360,100%,50%,0.5)' );
  34630. assert.ok( c.r == 1, "Red: " + c.r );
  34631. assert.ok( c.g === 0, "Green: " + c.g );
  34632. assert.ok( c.b === 0, "Blue: " + c.b );
  34633. } );
  34634. QUnit.test( "setStyleHSLRedWithSpaces", ( assert ) => {
  34635. var c = new Color();
  34636. c.setStyle( 'hsl(360, 100% , 50% )' );
  34637. assert.ok( c.r == 1, "Red: " + c.r );
  34638. assert.ok( c.g === 0, "Green: " + c.g );
  34639. assert.ok( c.b === 0, "Blue: " + c.b );
  34640. } );
  34641. QUnit.test( "setStyleHSLARedWithSpaces", ( assert ) => {
  34642. var c = new Color();
  34643. c.setStyle( 'hsla( 360, 100% , 50%, 0.5 )' );
  34644. assert.ok( c.r == 1, "Red: " + c.r );
  34645. assert.ok( c.g === 0, "Green: " + c.g );
  34646. assert.ok( c.b === 0, "Blue: " + c.b );
  34647. } );
  34648. QUnit.test( "setStyleHexSkyBlue", ( assert ) => {
  34649. var c = new Color();
  34650. c.setStyle( '#87CEEB' );
  34651. assert.ok( c.getHex() == 0x87CEEB, "Hex c: " + c.getHex() );
  34652. } );
  34653. QUnit.test( "setStyleHexSkyBlueMixed", ( assert ) => {
  34654. var c = new Color();
  34655. c.setStyle( '#87cEeB' );
  34656. assert.ok( c.getHex() == 0x87CEEB, "Hex c: " + c.getHex() );
  34657. } );
  34658. QUnit.test( "setStyleHex2Olive", ( assert ) => {
  34659. var c = new Color();
  34660. c.setStyle( '#F00' );
  34661. assert.ok( c.getHex() == 0xFF0000, "Hex c: " + c.getHex() );
  34662. } );
  34663. QUnit.test( "setStyleHex2OliveMixed", ( assert ) => {
  34664. var c = new Color();
  34665. c.setStyle( '#f00' );
  34666. assert.ok( c.getHex() == 0xFF0000, "Hex c: " + c.getHex() );
  34667. } );
  34668. QUnit.test( "setStyleColorName", ( assert ) => {
  34669. var c = new Color();
  34670. c.setStyle( 'powderblue' );
  34671. assert.ok( c.getHex() == 0xB0E0E6, "Hex c: " + c.getHex() );
  34672. } );
  34673. } );
  34674. } );
  34675. /**
  34676. * @author Mugen87 / https://github.com/Mugen87
  34677. *
  34678. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  34679. *
  34680. */
  34681. function Cylindrical( radius, theta, y ) {
  34682. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  34683. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  34684. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  34685. return this;
  34686. }
  34687. Object.assign( Cylindrical.prototype, {
  34688. set: function ( radius, theta, y ) {
  34689. this.radius = radius;
  34690. this.theta = theta;
  34691. this.y = y;
  34692. return this;
  34693. },
  34694. clone: function () {
  34695. return new this.constructor().copy( this );
  34696. },
  34697. copy: function ( other ) {
  34698. this.radius = other.radius;
  34699. this.theta = other.theta;
  34700. this.y = other.y;
  34701. return this;
  34702. },
  34703. setFromVector3: function ( vec3 ) {
  34704. this.radius = Math.sqrt( vec3.x * vec3.x + vec3.z * vec3.z );
  34705. this.theta = Math.atan2( vec3.x, vec3.z );
  34706. this.y = vec3.y;
  34707. return this;
  34708. }
  34709. } );
  34710. /**
  34711. * @author moraxy / https://github.com/moraxy
  34712. * @author TristanVALCKE / https://github.com/Itee
  34713. */
  34714. /* global QUnit */
  34715. QUnit.module( 'Maths', () => {
  34716. QUnit.module.todo( 'Cylindrical', () => {
  34717. // INSTANCING
  34718. QUnit.test( "Instancing", ( assert ) => {
  34719. var a = new Cylindrical();
  34720. var radius = 10.0;
  34721. var theta = Math.PI;
  34722. var y$$1 = 5;
  34723. assert.strictEqual( a.radius, 1.0, "Default values: check radius" );
  34724. assert.strictEqual( a.theta, 0, "Default values: check theta" );
  34725. assert.strictEqual( a.y, 0, "Default values: check y" );
  34726. var a = new Cylindrical( radius, theta, y$$1 );
  34727. assert.strictEqual( a.radius, radius, "Custom values: check radius" );
  34728. assert.strictEqual( a.theta, theta, "Custom values: check theta" );
  34729. assert.strictEqual( a.y, y$$1, "Custom values: check y" );
  34730. } );
  34731. // PUBLIC STUFF
  34732. QUnit.test( "set", ( assert ) => {
  34733. var a = new Cylindrical();
  34734. var radius = 10.0;
  34735. var theta = Math.PI;
  34736. var y$$1 = 5;
  34737. a.set( radius, theta, y$$1 );
  34738. assert.strictEqual( a.radius, radius, "Check radius" );
  34739. assert.strictEqual( a.theta, theta, "Check theta" );
  34740. assert.strictEqual( a.y, y$$1, "Check y" );
  34741. } );
  34742. QUnit.test( "clone", ( assert ) => {
  34743. var radius = 10.0;
  34744. var theta = Math.PI;
  34745. var y$$1 = 5;
  34746. var a = new Cylindrical( radius, theta, y$$1 );
  34747. var b = a.clone();
  34748. assert.propEqual( a, b, "Check a and b are equal after clone()" );
  34749. a.radius = 1;
  34750. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  34751. } );
  34752. QUnit.test( "copy", ( assert ) => {
  34753. var radius = 10.0;
  34754. var theta = Math.PI;
  34755. var y$$1 = 5;
  34756. var a = new Cylindrical( radius, theta, y$$1 );
  34757. var b = new Cylindrical().copy( a );
  34758. assert.propEqual( a, b, "Check a and b are equal after copy()" );
  34759. a.radius = 1;
  34760. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  34761. } );
  34762. QUnit.test( "setFromVector3", ( assert ) => {
  34763. var a = new Cylindrical( 1, 1, 1 );
  34764. var b = new Vector3( 0, 0, 0 );
  34765. var c = new Vector3( 3, - 1, - 3 );
  34766. var expected = new Cylindrical( Math.sqrt( 9 + 9 ), Math.atan2( 3, - 3 ), - 1 );
  34767. a.setFromVector3( b );
  34768. assert.strictEqual( a.radius, 0, "Zero-length vector: check radius" );
  34769. assert.strictEqual( a.theta, 0, "Zero-length vector: check theta" );
  34770. assert.strictEqual( a.y, 0, "Zero-length vector: check y" );
  34771. a.setFromVector3( c );
  34772. assert.ok( Math.abs( a.radius - expected.radius ) <= eps, "Normal vector: check radius" );
  34773. assert.ok( Math.abs( a.theta - expected.theta ) <= eps, "Normal vector: check theta" );
  34774. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Normal vector: check y" );
  34775. } );
  34776. } );
  34777. } );
  34778. /**
  34779. * @author bhouston / http://exocortex.com
  34780. * @author TristanVALCKE / https://github.com/Itee
  34781. */
  34782. /* global QUnit */
  34783. const eulerZero = new Euler( 0, 0, 0, "XYZ" );
  34784. const eulerAxyz = new Euler( 1, 0, 0, "XYZ" );
  34785. const eulerAzyx = new Euler( 0, 1, 0, "ZYX" );
  34786. function matrixEquals4( a, b, tolerance ) {
  34787. tolerance = tolerance || 0.0001;
  34788. if ( a.elements.length != b.elements.length ) {
  34789. return false;
  34790. }
  34791. for ( var i = 0, il = a.elements.length; i < il; i ++ ) {
  34792. var delta = a.elements[ i ] - b.elements[ i ];
  34793. if ( delta > tolerance ) {
  34794. return false;
  34795. }
  34796. }
  34797. return true;
  34798. }
  34799. function eulerEquals( a, b, tolerance ) {
  34800. tolerance = tolerance || 0.0001;
  34801. var diff = Math.abs( a.x - b.x ) + Math.abs( a.y - b.y ) + Math.abs( a.z - b.z );
  34802. return ( diff < tolerance );
  34803. }
  34804. function quatEquals( a, b, tolerance ) {
  34805. tolerance = tolerance || 0.0001;
  34806. 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 );
  34807. return ( diff < tolerance );
  34808. }
  34809. QUnit.module( 'Maths', () => {
  34810. QUnit.module.todo( 'Euler', () => {
  34811. // INSTANCING
  34812. QUnit.test( "Instancing", ( assert ) => {
  34813. var a = new Euler();
  34814. assert.ok( a.equals( eulerZero ), "Passed!" );
  34815. assert.ok( ! a.equals( eulerAxyz ), "Passed!" );
  34816. assert.ok( ! a.equals( eulerAzyx ), "Passed!" );
  34817. } );
  34818. // STATIC STUFF
  34819. QUnit.test( "RotationOrders", ( assert ) => {
  34820. assert.ok( false, "everything's gonna be alright" );
  34821. } );
  34822. QUnit.test( "DefaultOrder", ( assert ) => {
  34823. assert.ok( false, "everything's gonna be alright" );
  34824. } );
  34825. // PROPERTIES STUFF
  34826. QUnit.test( "x", ( assert ) => {
  34827. assert.ok( false, "everything's gonna be alright" );
  34828. } );
  34829. QUnit.test( "y", ( assert ) => {
  34830. assert.ok( false, "everything's gonna be alright" );
  34831. } );
  34832. QUnit.test( "z", ( assert ) => {
  34833. assert.ok( false, "everything's gonna be alright" );
  34834. } );
  34835. QUnit.test( "order", ( assert ) => {
  34836. assert.ok( false, "everything's gonna be alright" );
  34837. } );
  34838. // PUBLIC STUFF
  34839. QUnit.test( "isEuler", ( assert ) => {
  34840. assert.ok( false, "everything's gonna be alright" );
  34841. } );
  34842. QUnit.test( "set/setFromVector3/toVector3", ( assert ) => {
  34843. var a = new Euler();
  34844. a.set( 0, 1, 0, "ZYX" );
  34845. assert.ok( a.equals( eulerAzyx ), "Passed!" );
  34846. assert.ok( ! a.equals( eulerAxyz ), "Passed!" );
  34847. assert.ok( ! a.equals( eulerZero ), "Passed!" );
  34848. var vec = new Vector3( 0, 1, 0 );
  34849. var b = new Euler().setFromVector3( vec, "ZYX" );
  34850. assert.ok( a.equals( b ), "Passed!" );
  34851. var c = b.toVector3();
  34852. assert.ok( c.equals( vec ), "Passed!" );
  34853. } );
  34854. QUnit.test( "clone/copy/equals", ( assert ) => {
  34855. var a = eulerAxyz.clone();
  34856. assert.ok( a.equals( eulerAxyz ), "Passed!" );
  34857. assert.ok( ! a.equals( eulerZero ), "Passed!" );
  34858. assert.ok( ! a.equals( eulerAzyx ), "Passed!" );
  34859. a.copy( eulerAzyx );
  34860. assert.ok( a.equals( eulerAzyx ), "Passed!" );
  34861. assert.ok( ! a.equals( eulerAxyz ), "Passed!" );
  34862. assert.ok( ! a.equals( eulerZero ), "Passed!" );
  34863. } );
  34864. QUnit.test( "Quaternion.setFromEuler/Euler.fromQuaternion", ( assert ) => {
  34865. var testValues = [ eulerZero, eulerAxyz, eulerAzyx ];
  34866. for ( var i = 0; i < testValues.length; i ++ ) {
  34867. var v = testValues[ i ];
  34868. var q = new Quaternion().setFromEuler( v );
  34869. var v2 = new Euler().setFromQuaternion( q, v.order );
  34870. var q2 = new Quaternion().setFromEuler( v2 );
  34871. assert.ok( quatEquals( q, q2 ), "Passed!" );
  34872. }
  34873. } );
  34874. QUnit.test( "Matrix4.setFromEuler/Euler.fromRotationMatrix", ( assert ) => {
  34875. var testValues = [ eulerZero, eulerAxyz, eulerAzyx ];
  34876. for ( var i = 0; i < testValues.length; i ++ ) {
  34877. var v = testValues[ i ];
  34878. var m = new Matrix4().makeRotationFromEuler( v );
  34879. var v2 = new Euler().setFromRotationMatrix( m, v.order );
  34880. var m2 = new Matrix4().makeRotationFromEuler( v2 );
  34881. assert.ok( matrixEquals4( m, m2, 0.0001 ), "Passed!" );
  34882. }
  34883. } );
  34884. QUnit.test( "reorder", ( assert ) => {
  34885. var testValues = [ eulerZero, eulerAxyz, eulerAzyx ];
  34886. for ( var i = 0; i < testValues.length; i ++ ) {
  34887. var v = testValues[ i ];
  34888. var q = new Quaternion().setFromEuler( v );
  34889. v.reorder( 'YZX' );
  34890. var q2 = new Quaternion().setFromEuler( v );
  34891. assert.ok( quatEquals( q, q2 ), "Passed!" );
  34892. v.reorder( 'ZXY' );
  34893. var q3 = new Quaternion().setFromEuler( v );
  34894. assert.ok( quatEquals( q, q3 ), "Passed!" );
  34895. }
  34896. } );
  34897. QUnit.test( "set/get properties, check callbacks", ( assert ) => {
  34898. var a = new Euler();
  34899. a.onChange( function () {
  34900. assert.step( "set: onChange called" );
  34901. } );
  34902. assert.expect( 8 );
  34903. // should be 4 calls to onChangeCallback
  34904. a.x = 1;
  34905. a.y = 2;
  34906. a.z = 3;
  34907. a.order = "ZYX";
  34908. assert.strictEqual( a.x, 1, "get: check x" );
  34909. assert.strictEqual( a.y, 2, "get: check y" );
  34910. assert.strictEqual( a.z, 3, "get: check z" );
  34911. assert.strictEqual( a.order, "ZYX", "get: check order" );
  34912. } );
  34913. QUnit.test( "clone/copy, check callbacks", ( assert ) => {
  34914. assert.expect( 3 );
  34915. var a = new Euler( 1, 2, 3, "ZXY" );
  34916. var b = new Euler( 4, 5, 6, "XZY" );
  34917. var cb = function () {
  34918. assert.step( "onChange called" );
  34919. };
  34920. a.onChange( cb );
  34921. b.onChange( cb );
  34922. // clone doesn't trigger onChange
  34923. var a = b.clone();
  34924. assert.ok( a.equals( b ), "clone: check if a equals b" );
  34925. // copy triggers onChange once
  34926. var a = new Euler( 1, 2, 3, "ZXY" );
  34927. a.onChange( cb );
  34928. a.copy( b );
  34929. assert.ok( a.equals( b ), "copy: check if a equals b" );
  34930. } );
  34931. QUnit.test( "toArray", ( assert ) => {
  34932. var order = "YXZ";
  34933. var a = new Euler( x, y, z, order );
  34934. var array = a.toArray();
  34935. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  34936. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  34937. assert.strictEqual( array[ 2 ], z, "No array, no offset: check z" );
  34938. assert.strictEqual( array[ 3 ], order, "No array, no offset: check order" );
  34939. var array = [];
  34940. a.toArray( array );
  34941. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  34942. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  34943. assert.strictEqual( array[ 2 ], z, "With array, no offset: check z" );
  34944. assert.strictEqual( array[ 3 ], order, "With array, no offset: check order" );
  34945. var array = [];
  34946. a.toArray( array, 1 );
  34947. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  34948. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  34949. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  34950. assert.strictEqual( array[ 3 ], z, "With array and offset: check z" );
  34951. assert.strictEqual( array[ 4 ], order, "With array and offset: check order" );
  34952. } );
  34953. QUnit.test( "fromArray", ( assert ) => {
  34954. assert.expect( 10 );
  34955. var a = new Euler();
  34956. var array = [ x, y, z ];
  34957. var cb = function () {
  34958. assert.step( "onChange called" );
  34959. };
  34960. a.onChange( cb );
  34961. a.fromArray( array );
  34962. assert.strictEqual( a.x, x, "No order: check x" );
  34963. assert.strictEqual( a.y, y, "No order: check y" );
  34964. assert.strictEqual( a.z, z, "No order: check z" );
  34965. assert.strictEqual( a.order, "XYZ", "No order: check order" );
  34966. var a = new Euler();
  34967. var array = [ x, y, z, "ZXY" ];
  34968. a.onChange( cb );
  34969. a.fromArray( array );
  34970. assert.strictEqual( a.x, x, "With order: check x" );
  34971. assert.strictEqual( a.y, y, "With order: check y" );
  34972. assert.strictEqual( a.z, z, "With order: check z" );
  34973. assert.strictEqual( a.order, "ZXY", "With order: check order" );
  34974. } );
  34975. QUnit.test( "onChange", ( assert ) => {
  34976. assert.ok( false, "everything's gonna be alright" );
  34977. } );
  34978. QUnit.test( "onChangeCallback", ( assert ) => {
  34979. assert.ok( false, "everything's gonna be alright" );
  34980. } );
  34981. // OTHERS
  34982. QUnit.test( "gimbalLocalQuat", ( assert ) => {
  34983. // known problematic quaternions
  34984. var q1 = new Quaternion( 0.5207769385244341, - 0.4783214164122354, 0.520776938524434, 0.47832141641223547 );
  34985. var q2 = new Quaternion( 0.11284905712620674, 0.6980437630368944, - 0.11284905712620674, 0.6980437630368944 );
  34986. var eulerOrder = "ZYX";
  34987. // create Euler directly from a Quaternion
  34988. var eViaQ1 = new Euler().setFromQuaternion( q1, eulerOrder ); // there is likely a bug here
  34989. // create Euler from Quaternion via an intermediate Matrix4
  34990. var mViaQ1 = new Matrix4().makeRotationFromQuaternion( q1 );
  34991. var eViaMViaQ1 = new Euler().setFromRotationMatrix( mViaQ1, eulerOrder );
  34992. // the results here are different
  34993. assert.ok( eulerEquals( eViaQ1, eViaMViaQ1 ), "Passed!" ); // this result is correct
  34994. } );
  34995. } );
  34996. } );
  34997. /**
  34998. * @author bhouston / http://exocortex.com
  34999. * @author TristanVALCKE / https://github.com/Itee
  35000. */
  35001. /* global QUnit */
  35002. const unit3 = new Vector3( 1, 0, 0 );
  35003. QUnit.module( 'Maths', () => {
  35004. QUnit.module.todo( 'Frustum', () => {
  35005. // INSTANCING
  35006. QUnit.test( "Instancing", ( assert ) => {
  35007. var a = new Frustum();
  35008. assert.ok( a.planes !== undefined, "Passed!" );
  35009. assert.ok( a.planes.length === 6, "Passed!" );
  35010. var pDefault = new Plane();
  35011. for ( var i = 0; i < 6; i ++ ) {
  35012. assert.ok( a.planes[ i ].equals( pDefault ), "Passed!" );
  35013. }
  35014. var p0 = new Plane( unit3, - 1 );
  35015. var p1 = new Plane( unit3, 1 );
  35016. var p2 = new Plane( unit3, 2 );
  35017. var p3 = new Plane( unit3, 3 );
  35018. var p4 = new Plane( unit3, 4 );
  35019. var p5 = new Plane( unit3, 5 );
  35020. var a = new Frustum( p0, p1, p2, p3, p4, p5 );
  35021. assert.ok( a.planes[ 0 ].equals( p0 ), "Passed!" );
  35022. assert.ok( a.planes[ 1 ].equals( p1 ), "Passed!" );
  35023. assert.ok( a.planes[ 2 ].equals( p2 ), "Passed!" );
  35024. assert.ok( a.planes[ 3 ].equals( p3 ), "Passed!" );
  35025. assert.ok( a.planes[ 4 ].equals( p4 ), "Passed!" );
  35026. assert.ok( a.planes[ 5 ].equals( p5 ), "Passed!" );
  35027. } );
  35028. // PUBLIC STUFF
  35029. QUnit.test( "set", ( assert ) => {
  35030. var a = new Frustum();
  35031. var p0 = new Plane( unit3, - 1 );
  35032. var p1 = new Plane( unit3, 1 );
  35033. var p2 = new Plane( unit3, 2 );
  35034. var p3 = new Plane( unit3, 3 );
  35035. var p4 = new Plane( unit3, 4 );
  35036. var p5 = new Plane( unit3, 5 );
  35037. a.set( p0, p1, p2, p3, p4, p5 );
  35038. assert.ok( a.planes[ 0 ].equals( p0 ), "Check plane #0" );
  35039. assert.ok( a.planes[ 1 ].equals( p1 ), "Check plane #1" );
  35040. assert.ok( a.planes[ 2 ].equals( p2 ), "Check plane #2" );
  35041. assert.ok( a.planes[ 3 ].equals( p3 ), "Check plane #3" );
  35042. assert.ok( a.planes[ 4 ].equals( p4 ), "Check plane #4" );
  35043. assert.ok( a.planes[ 5 ].equals( p5 ), "Check plane #5" );
  35044. } );
  35045. QUnit.test( "clone", ( assert ) => {
  35046. var p0 = new Plane( unit3, - 1 );
  35047. var p1 = new Plane( unit3, 1 );
  35048. var p2 = new Plane( unit3, 2 );
  35049. var p3 = new Plane( unit3, 3 );
  35050. var p4 = new Plane( unit3, 4 );
  35051. var p5 = new Plane( unit3, 5 );
  35052. var b = new Frustum( p0, p1, p2, p3, p4, p5 );
  35053. var a = b.clone();
  35054. assert.ok( a.planes[ 0 ].equals( p0 ), "Passed!" );
  35055. assert.ok( a.planes[ 1 ].equals( p1 ), "Passed!" );
  35056. assert.ok( a.planes[ 2 ].equals( p2 ), "Passed!" );
  35057. assert.ok( a.planes[ 3 ].equals( p3 ), "Passed!" );
  35058. assert.ok( a.planes[ 4 ].equals( p4 ), "Passed!" );
  35059. assert.ok( a.planes[ 5 ].equals( p5 ), "Passed!" );
  35060. // ensure it is a true copy by modifying source
  35061. a.planes[ 0 ].copy( p1 );
  35062. assert.ok( b.planes[ 0 ].equals( p0 ), "Passed!" );
  35063. } );
  35064. QUnit.test( "copy", ( assert ) => {
  35065. var p0 = new Plane( unit3, - 1 );
  35066. var p1 = new Plane( unit3, 1 );
  35067. var p2 = new Plane( unit3, 2 );
  35068. var p3 = new Plane( unit3, 3 );
  35069. var p4 = new Plane( unit3, 4 );
  35070. var p5 = new Plane( unit3, 5 );
  35071. var b = new Frustum( p0, p1, p2, p3, p4, p5 );
  35072. var a = new Frustum().copy( b );
  35073. assert.ok( a.planes[ 0 ].equals( p0 ), "Passed!" );
  35074. assert.ok( a.planes[ 1 ].equals( p1 ), "Passed!" );
  35075. assert.ok( a.planes[ 2 ].equals( p2 ), "Passed!" );
  35076. assert.ok( a.planes[ 3 ].equals( p3 ), "Passed!" );
  35077. assert.ok( a.planes[ 4 ].equals( p4 ), "Passed!" );
  35078. assert.ok( a.planes[ 5 ].equals( p5 ), "Passed!" );
  35079. // ensure it is a true copy by modifying source
  35080. b.planes[ 0 ] = p1;
  35081. assert.ok( a.planes[ 0 ].equals( p0 ), "Passed!" );
  35082. } );
  35083. QUnit.test( "setFromMatrix/makeOrthographic/containsPoint", ( assert ) => {
  35084. var m = new Matrix4().makeOrthographic( - 1, 1, - 1, 1, 1, 100 );
  35085. var a = new Frustum().setFromMatrix( m );
  35086. assert.ok( ! a.containsPoint( new Vector3( 0, 0, 0 ) ), "Passed!" );
  35087. assert.ok( a.containsPoint( new Vector3( 0, 0, - 50 ) ), "Passed!" );
  35088. assert.ok( a.containsPoint( new Vector3( 0, 0, - 1.001 ) ), "Passed!" );
  35089. assert.ok( a.containsPoint( new Vector3( - 1, - 1, - 1.001 ) ), "Passed!" );
  35090. assert.ok( ! a.containsPoint( new Vector3( - 1.1, - 1.1, - 1.001 ) ), "Passed!" );
  35091. assert.ok( a.containsPoint( new Vector3( 1, 1, - 1.001 ) ), "Passed!" );
  35092. assert.ok( ! a.containsPoint( new Vector3( 1.1, 1.1, - 1.001 ) ), "Passed!" );
  35093. assert.ok( a.containsPoint( new Vector3( 0, 0, - 100 ) ), "Passed!" );
  35094. assert.ok( a.containsPoint( new Vector3( - 1, - 1, - 100 ) ), "Passed!" );
  35095. assert.ok( ! a.containsPoint( new Vector3( - 1.1, - 1.1, - 100.1 ) ), "Passed!" );
  35096. assert.ok( a.containsPoint( new Vector3( 1, 1, - 100 ) ), "Passed!" );
  35097. assert.ok( ! a.containsPoint( new Vector3( 1.1, 1.1, - 100.1 ) ), "Passed!" );
  35098. assert.ok( ! a.containsPoint( new Vector3( 0, 0, - 101 ) ), "Passed!" );
  35099. } );
  35100. QUnit.test( "setFromMatrix/makePerspective/containsPoint", ( assert ) => {
  35101. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  35102. var a = new Frustum().setFromMatrix( m );
  35103. assert.ok( ! a.containsPoint( new Vector3( 0, 0, 0 ) ), "Passed!" );
  35104. assert.ok( a.containsPoint( new Vector3( 0, 0, - 50 ) ), "Passed!" );
  35105. assert.ok( a.containsPoint( new Vector3( 0, 0, - 1.001 ) ), "Passed!" );
  35106. assert.ok( a.containsPoint( new Vector3( - 1, - 1, - 1.001 ) ), "Passed!" );
  35107. assert.ok( ! a.containsPoint( new Vector3( - 1.1, - 1.1, - 1.001 ) ), "Passed!" );
  35108. assert.ok( a.containsPoint( new Vector3( 1, 1, - 1.001 ) ), "Passed!" );
  35109. assert.ok( ! a.containsPoint( new Vector3( 1.1, 1.1, - 1.001 ) ), "Passed!" );
  35110. assert.ok( a.containsPoint( new Vector3( 0, 0, - 99.999 ) ), "Passed!" );
  35111. assert.ok( a.containsPoint( new Vector3( - 99.999, - 99.999, - 99.999 ) ), "Passed!" );
  35112. assert.ok( ! a.containsPoint( new Vector3( - 100.1, - 100.1, - 100.1 ) ), "Passed!" );
  35113. assert.ok( a.containsPoint( new Vector3( 99.999, 99.999, - 99.999 ) ), "Passed!" );
  35114. assert.ok( ! a.containsPoint( new Vector3( 100.1, 100.1, - 100.1 ) ), "Passed!" );
  35115. assert.ok( ! a.containsPoint( new Vector3( 0, 0, - 101 ) ), "Passed!" );
  35116. } );
  35117. QUnit.test( "setFromMatrix/makePerspective/intersectsSphere", ( assert ) => {
  35118. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  35119. var a = new Frustum().setFromMatrix( m );
  35120. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 0, 0, 0 ), 0 ) ), "Passed!" );
  35121. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 0, 0, 0 ), 0.9 ) ), "Passed!" );
  35122. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, 0 ), 1.1 ) ), "Passed!" );
  35123. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 50 ), 0 ) ), "Passed!" );
  35124. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 1.001 ), 0 ) ), "Passed!" );
  35125. assert.ok( a.intersectsSphere( new Sphere( new Vector3( - 1, - 1, - 1.001 ), 0 ) ), "Passed!" );
  35126. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( - 1.1, - 1.1, - 1.001 ), 0 ) ), "Passed!" );
  35127. assert.ok( a.intersectsSphere( new Sphere( new Vector3( - 1.1, - 1.1, - 1.001 ), 0.5 ) ), "Passed!" );
  35128. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 1, 1, - 1.001 ), 0 ) ), "Passed!" );
  35129. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 1.1, 1.1, - 1.001 ), 0 ) ), "Passed!" );
  35130. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 1.1, 1.1, - 1.001 ), 0.5 ) ), "Passed!" );
  35131. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 99.999 ), 0 ) ), "Passed!" );
  35132. assert.ok( a.intersectsSphere( new Sphere( new Vector3( - 99.999, - 99.999, - 99.999 ), 0 ) ), "Passed!" );
  35133. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( - 100.1, - 100.1, - 100.1 ), 0 ) ), "Passed!" );
  35134. assert.ok( a.intersectsSphere( new Sphere( new Vector3( - 100.1, - 100.1, - 100.1 ), 0.5 ) ), "Passed!" );
  35135. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 99.999, 99.999, - 99.999 ), 0 ) ), "Passed!" );
  35136. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 100.1, 100.1, - 100.1 ), 0 ) ), "Passed!" );
  35137. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 100.1, 100.1, - 100.1 ), 0.2 ) ), "Passed!" );
  35138. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 101 ), 0 ) ), "Passed!" );
  35139. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 101 ), 1.1 ) ), "Passed!" );
  35140. } );
  35141. QUnit.test( "intersectsObject", ( assert ) => {
  35142. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  35143. var a = new Frustum().setFromMatrix( m );
  35144. var object = new Mesh( new BoxGeometry( 1, 1, 1 ) );
  35145. var intersects;
  35146. intersects = a.intersectsObject( object );
  35147. assert.notOk( intersects, "No intersection" );
  35148. object.position.set( - 1, - 1, - 1 );
  35149. object.updateMatrixWorld();
  35150. intersects = a.intersectsObject( object );
  35151. assert.ok( intersects, "Successful intersection" );
  35152. object.position.set( 1, 1, 1 );
  35153. object.updateMatrixWorld();
  35154. intersects = a.intersectsObject( object );
  35155. assert.notOk( intersects, "No intersection" );
  35156. } );
  35157. QUnit.test( "intersectsSprite", ( assert ) => {
  35158. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  35159. var a = new Frustum().setFromMatrix( m );
  35160. var sprite = new Sprite();
  35161. var intersects;
  35162. intersects = a.intersectsSprite( sprite );
  35163. assert.notOk( intersects, "No intersection" );
  35164. sprite.position.set( - 1, - 1, - 1 );
  35165. sprite.updateMatrixWorld();
  35166. intersects = a.intersectsSprite( sprite );
  35167. assert.ok( intersects, "Successful intersection" );
  35168. } );
  35169. QUnit.test( "intersectsSphere", ( assert ) => {
  35170. assert.ok( false, "everything's gonna be alright" );
  35171. } );
  35172. QUnit.test( "intersectsBox", ( assert ) => {
  35173. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  35174. var a = new Frustum().setFromMatrix( m );
  35175. var box = new Box3( zero3.clone(), one3.clone() );
  35176. var intersects;
  35177. intersects = a.intersectsBox( box );
  35178. assert.notOk( intersects, "No intersection" );
  35179. box.translate( - 1, - 1, - 1 );
  35180. intersects = a.intersectsBox( box );
  35181. assert.ok( intersects, "Successful intersection" );
  35182. } );
  35183. QUnit.test( "containsPoint", ( assert ) => {
  35184. assert.ok( false, "everything's gonna be alright" );
  35185. } );
  35186. } );
  35187. } );
  35188. /**
  35189. * @author tschw
  35190. * @author TristanVALCKE / https://github.com/Itee
  35191. */
  35192. /* global QUnit */
  35193. QUnit.module( 'Maths', () => {
  35194. QUnit.module.todo( 'Interpolant', () => {
  35195. // Since this is an abstract base class, we have to make it concrete in order
  35196. // to QUnit.test its functionality...
  35197. function Mock( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  35198. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  35199. }
  35200. Mock.prototype = Object.create( Interpolant.prototype );
  35201. Mock.prototype.intervalChanged_ = function intervalChanged( i1, t0, t1 ) {
  35202. Mock.captureCall( arguments );
  35203. };
  35204. Mock.prototype.interpolate_ = function interpolate( i1, t0, t, t1 ) {
  35205. Mock.captureCall( arguments );
  35206. return this.copySampleValue_( i1 - 1 );
  35207. };
  35208. Mock.prototype.beforeStart_ = function beforeStart( i, t, t0 ) {
  35209. Mock.captureCall( arguments );
  35210. return this.copySampleValue_( i );
  35211. };
  35212. Mock.prototype.afterEnd_ = function afterEnd( i, tN, t ) {
  35213. Mock.captureCall( arguments );
  35214. return this.copySampleValue_( i );
  35215. };
  35216. // Call capturing facility
  35217. Mock.calls = null;
  35218. Mock.captureCall = function ( args ) {
  35219. if ( Mock.calls !== null ) {
  35220. Mock.calls.push( {
  35221. func: Mock.captureCall.caller.name,
  35222. args: Array.prototype.slice.call( args )
  35223. } );
  35224. }
  35225. };
  35226. // Tests
  35227. // INSTANCING
  35228. QUnit.test( "Instancing", ( assert ) => {
  35229. assert.ok( false, "everything's gonna be alright" );
  35230. } );
  35231. // PUBLIC STUFF
  35232. QUnit.test( "evaluate", ( assert ) => {
  35233. assert.ok( false, "everything's gonna be alright" );
  35234. } );
  35235. // PRIVATE STUFF
  35236. QUnit.test( "DefaultSettings_", ( assert ) => {
  35237. assert.ok( false, "everything's gonna be alright" );
  35238. } );
  35239. QUnit.test( "getSettings_", ( assert ) => {
  35240. assert.ok( false, "everything's gonna be alright" );
  35241. } );
  35242. QUnit.test( "copySampleValue_", ( assert ) => {
  35243. var interpolant = new Mock( null, [ 1, 11, 2, 22, 3, 33 ], 2, [] );
  35244. assert.deepEqual( interpolant.copySampleValue_( 0 ), [ 1, 11 ], "sample fetch (0)" );
  35245. assert.deepEqual( interpolant.copySampleValue_( 1 ), [ 2, 22 ], "sample fetch (1)" );
  35246. assert.deepEqual( interpolant.copySampleValue_( 2 ), [ 3, 33 ], "first sample (2)" );
  35247. } );
  35248. QUnit.test( "evaluate -> intervalChanged_ / interpolate_", ( assert ) => {
  35249. var actual, expect;
  35250. var interpolant = new Mock( [ 11, 22, 33, 44, 55, 66, 77, 88, 99 ], null, 0, null );
  35251. Mock.calls = [];
  35252. interpolant.evaluate( 11 );
  35253. actual = Mock.calls[ 0 ];
  35254. expect = {
  35255. func: 'intervalChanged',
  35256. args: [ 1, 11, 22 ]
  35257. };
  35258. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35259. actual = Mock.calls[ 1 ];
  35260. expect = {
  35261. func: 'interpolate',
  35262. args: [ 1, 11, 11, 22 ]
  35263. };
  35264. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35265. assert.ok( Mock.calls.length === 2, "no further calls" );
  35266. Mock.calls = [];
  35267. interpolant.evaluate( 12 ); // same interval
  35268. actual = Mock.calls[ 0 ];
  35269. expect = {
  35270. func: 'interpolate',
  35271. args: [ 1, 11, 12, 22 ]
  35272. };
  35273. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35274. assert.ok( Mock.calls.length === 1, "no further calls" );
  35275. Mock.calls = [];
  35276. interpolant.evaluate( 22 ); // step forward
  35277. actual = Mock.calls[ 0 ];
  35278. expect = {
  35279. func: 'intervalChanged',
  35280. args: [ 2, 22, 33 ]
  35281. };
  35282. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35283. actual = Mock.calls[ 1 ];
  35284. expect = {
  35285. func: 'interpolate',
  35286. args: [ 2, 22, 22, 33 ]
  35287. };
  35288. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35289. assert.ok( Mock.calls.length === 2 );
  35290. Mock.calls = [];
  35291. interpolant.evaluate( 21 ); // step back
  35292. actual = Mock.calls[ 0 ];
  35293. expect = {
  35294. func: 'intervalChanged',
  35295. args: [ 1, 11, 22 ]
  35296. };
  35297. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35298. actual = Mock.calls[ 1 ];
  35299. expect = {
  35300. func: 'interpolate',
  35301. args: [ 1, 11, 21, 22 ]
  35302. };
  35303. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35304. assert.ok( Mock.calls.length === 2, "no further calls" );
  35305. Mock.calls = [];
  35306. interpolant.evaluate( 20 ); // same interval
  35307. actual = Mock.calls[ 0 ];
  35308. expect = {
  35309. func: 'interpolate',
  35310. args: [ 1, 11, 20, 22 ]
  35311. };
  35312. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35313. assert.ok( Mock.calls.length === 1, "no further calls" );
  35314. Mock.calls = [];
  35315. interpolant.evaluate( 43 ); // two steps forward
  35316. actual = Mock.calls[ 0 ];
  35317. expect = {
  35318. func: 'intervalChanged',
  35319. args: [ 3, 33, 44 ]
  35320. };
  35321. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35322. actual = Mock.calls[ 1 ];
  35323. expect = {
  35324. func: 'interpolate',
  35325. args: [ 3, 33, 43, 44 ]
  35326. };
  35327. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35328. assert.ok( Mock.calls.length === 2, "no further calls" );
  35329. Mock.calls = [];
  35330. interpolant.evaluate( 12 ); // two steps back
  35331. actual = Mock.calls[ 0 ];
  35332. expect = {
  35333. func: 'intervalChanged',
  35334. args: [ 1, 11, 22 ]
  35335. };
  35336. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35337. actual = Mock.calls[ 1 ];
  35338. expect = {
  35339. func: 'interpolate',
  35340. args: [ 1, 11, 12, 22 ]
  35341. };
  35342. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35343. assert.ok( Mock.calls.length === 2, "no further calls" );
  35344. Mock.calls = [];
  35345. interpolant.evaluate( 77 ); // random access
  35346. actual = Mock.calls[ 0 ];
  35347. expect = {
  35348. func: 'intervalChanged',
  35349. args: [ 7, 77, 88 ]
  35350. };
  35351. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35352. actual = Mock.calls[ 1 ];
  35353. expect = {
  35354. func: 'interpolate',
  35355. args: [ 7, 77, 77, 88 ]
  35356. };
  35357. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35358. assert.ok( Mock.calls.length === 2, "no further calls" );
  35359. Mock.calls = [];
  35360. interpolant.evaluate( 80 ); // same interval
  35361. actual = Mock.calls[ 0 ];
  35362. expect = {
  35363. func: 'interpolate',
  35364. args: [ 7, 77, 80, 88 ]
  35365. };
  35366. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35367. assert.ok( Mock.calls.length === 1, "no further calls" );
  35368. Mock.calls = [];
  35369. interpolant.evaluate( 36 ); // random access
  35370. actual = Mock.calls[ 0 ];
  35371. expect = {
  35372. func: 'intervalChanged',
  35373. args: [ 3, 33, 44 ]
  35374. };
  35375. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35376. actual = Mock.calls[ 1 ];
  35377. expect = {
  35378. func: 'interpolate',
  35379. args: [ 3, 33, 36, 44 ]
  35380. };
  35381. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35382. assert.ok( Mock.calls.length === 2, "no further calls" );
  35383. Mock.calls = [];
  35384. interpolant.evaluate( 24 ); // fast reset / loop (2nd)
  35385. actual = Mock.calls[ 0 ];
  35386. expect = {
  35387. func: 'intervalChanged',
  35388. args: [ 2, 22, 33 ]
  35389. };
  35390. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35391. actual = Mock.calls[ 1 ];
  35392. expect = {
  35393. func: 'interpolate',
  35394. args: [ 2, 22, 24, 33 ]
  35395. };
  35396. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35397. assert.ok( Mock.calls.length === 2, "no further calls" );
  35398. Mock.calls = [];
  35399. interpolant.evaluate( 16 ); // fast reset / loop (2nd)
  35400. actual = Mock.calls[ 0 ];
  35401. expect = {
  35402. func: 'intervalChanged',
  35403. args: [ 1, 11, 22 ]
  35404. };
  35405. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35406. actual = Mock.calls[ 1 ];
  35407. expect = {
  35408. func: 'interpolate',
  35409. args: [ 1, 11, 16, 22 ]
  35410. };
  35411. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35412. assert.ok( Mock.calls.length === 2, "no further calls" );
  35413. } );
  35414. QUnit.test( "evaulate -> beforeStart_ [once]", ( assert ) => {
  35415. var actual, expect;
  35416. var interpolant = new Mock( [ 11, 22, 33 ], null, 0, null );
  35417. Mock.calls = [];
  35418. interpolant.evaluate( 10 );
  35419. actual = Mock.calls[ 0 ];
  35420. expect = {
  35421. func: 'beforeStart',
  35422. args: [ 0, 10, 11 ]
  35423. };
  35424. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35425. assert.ok( Mock.calls.length === 1, "no further calls" );
  35426. // Check operation resumes normally and intervalChanged gets called
  35427. Mock.calls = [];
  35428. interpolant.evaluate( 11 );
  35429. actual = Mock.calls[ 0 ];
  35430. expect = {
  35431. func: 'intervalChanged',
  35432. args: [ 1, 11, 22 ]
  35433. };
  35434. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35435. actual = Mock.calls[ 1 ];
  35436. expect = {
  35437. func: 'interpolate',
  35438. args: [ 1, 11, 11, 22 ]
  35439. };
  35440. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35441. assert.ok( Mock.calls.length === 2, "no further calls" );
  35442. // Back off-bounds
  35443. Mock.calls = [];
  35444. interpolant.evaluate( 10 );
  35445. actual = Mock.calls[ 0 ];
  35446. expect = {
  35447. func: 'beforeStart',
  35448. args: [ 0, 10, 11 ]
  35449. };
  35450. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35451. assert.ok( Mock.calls.length === 1, "no further calls" );
  35452. } );
  35453. QUnit.test( "evaluate -> beforeStart_ [twice]", ( assert ) => {
  35454. var actual, expect;
  35455. var interpolant = new Mock( [ 11, 22, 33 ], null, 0, null );
  35456. Mock.calls = [];
  35457. interpolant.evaluate( 10 );
  35458. actual = Mock.calls[ 0 ];
  35459. expect = {
  35460. func: 'beforeStart',
  35461. args: [ 0, 10, 11 ]
  35462. };
  35463. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35464. assert.ok( Mock.calls.length === 1, "no further calls" );
  35465. Mock.calls = []; // again - consider changed state
  35466. interpolant.evaluate( 10 );
  35467. actual = Mock.calls[ 0 ];
  35468. expect = {
  35469. func: 'beforeStart',
  35470. args: [ 0, 10, 11 ]
  35471. };
  35472. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35473. assert.ok( Mock.calls.length === 1, "no further calls" );
  35474. // Check operation resumes normally and intervalChanged gets called
  35475. Mock.calls = [];
  35476. interpolant.evaluate( 11 );
  35477. actual = Mock.calls[ 0 ];
  35478. expect = {
  35479. func: 'intervalChanged',
  35480. args: [ 1, 11, 22 ]
  35481. };
  35482. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35483. actual = Mock.calls[ 1 ];
  35484. expect = {
  35485. func: 'interpolate',
  35486. args: [ 1, 11, 11, 22 ]
  35487. };
  35488. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35489. assert.ok( Mock.calls.length === 2, "no further calls" );
  35490. } );
  35491. QUnit.test( "evaluate -> afterEnd_ [once]", ( assert ) => {
  35492. var actual, expect;
  35493. var interpolant = new Mock( [ 11, 22, 33 ], null, 0, null );
  35494. Mock.calls = [];
  35495. interpolant.evaluate( 33 );
  35496. actual = Mock.calls[ 0 ];
  35497. expect = {
  35498. func: 'afterEnd',
  35499. args: [ 2, 33, 33 ]
  35500. };
  35501. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35502. assert.ok( Mock.calls.length === 1, "no further calls" );
  35503. // Check operation resumes normally and intervalChanged gets called
  35504. Mock.calls = [];
  35505. interpolant.evaluate( 32 );
  35506. actual = Mock.calls[ 0 ];
  35507. expect = {
  35508. func: 'intervalChanged',
  35509. args: [ 2, 22, 33 ]
  35510. };
  35511. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35512. actual = Mock.calls[ 1 ];
  35513. expect = {
  35514. func: 'interpolate',
  35515. args: [ 2, 22, 32, 33 ]
  35516. };
  35517. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35518. assert.ok( Mock.calls.length === 2, "no further calls" );
  35519. // Back off-bounds
  35520. Mock.calls = [];
  35521. interpolant.evaluate( 33 );
  35522. actual = Mock.calls[ 0 ];
  35523. expect = {
  35524. func: 'afterEnd',
  35525. args: [ 2, 33, 33 ]
  35526. };
  35527. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35528. assert.ok( Mock.calls.length === 1, "no further calls" );
  35529. } );
  35530. QUnit.test( "evaluate -> afterEnd_ [twice]", ( assert ) => {
  35531. var actual, expect;
  35532. var interpolant = new Mock( [ 11, 22, 33 ], null, 0, null );
  35533. Mock.calls = [];
  35534. interpolant.evaluate( 33 );
  35535. actual = Mock.calls[ 0 ];
  35536. expect = {
  35537. func: 'afterEnd',
  35538. args: [ 2, 33, 33 ]
  35539. };
  35540. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35541. assert.ok( Mock.calls.length === 1, "no further calls" );
  35542. Mock.calls = []; // again - consider changed state
  35543. interpolant.evaluate( 33 );
  35544. actual = Mock.calls[ 0 ];
  35545. expect = {
  35546. func: 'afterEnd',
  35547. args: [ 2, 33, 33 ]
  35548. };
  35549. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35550. assert.ok( Mock.calls.length === 1, "no further calls" );
  35551. // Check operation resumes normally and intervalChanged gets called
  35552. Mock.calls = [];
  35553. interpolant.evaluate( 32 );
  35554. actual = Mock.calls[ 0 ];
  35555. expect = {
  35556. func: 'intervalChanged',
  35557. args: [ 2, 22, 33 ]
  35558. };
  35559. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35560. actual = Mock.calls[ 1 ];
  35561. expect = {
  35562. func: 'interpolate',
  35563. args: [ 2, 22, 32, 33 ]
  35564. };
  35565. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35566. assert.ok( Mock.calls.length === 2, "no further calls" );
  35567. } );
  35568. } );
  35569. } );
  35570. /**
  35571. * @author bhouston / http://exocortex.com
  35572. * @author TristanVALCKE / https://github.com/Itee
  35573. */
  35574. /* global QUnit */
  35575. QUnit.module( 'Maths', () => {
  35576. QUnit.module.todo( 'Line3', () => {
  35577. // INSTANCING
  35578. QUnit.test( "Instancing", ( assert ) => {
  35579. var a = new Line3();
  35580. assert.ok( a.start.equals( zero3 ), "Passed!" );
  35581. assert.ok( a.end.equals( zero3 ), "Passed!" );
  35582. var a = new Line3( two3.clone(), one3.clone() );
  35583. assert.ok( a.start.equals( two3 ), "Passed!" );
  35584. assert.ok( a.end.equals( one3 ), "Passed!" );
  35585. } );
  35586. // PUBLIC STUFF
  35587. QUnit.test( "set", ( assert ) => {
  35588. var a = new Line3();
  35589. a.set( one3, one3 );
  35590. assert.ok( a.start.equals( one3 ), "Passed!" );
  35591. assert.ok( a.end.equals( one3 ), "Passed!" );
  35592. } );
  35593. QUnit.test( "copy/equals", ( assert ) => {
  35594. var a = new Line3( zero3.clone(), one3.clone() );
  35595. var b = new Line3().copy( a );
  35596. assert.ok( b.start.equals( zero3 ), "Passed!" );
  35597. assert.ok( b.end.equals( one3 ), "Passed!" );
  35598. // ensure that it is a true copy
  35599. a.start = zero3;
  35600. a.end = one3;
  35601. assert.ok( b.start.equals( zero3 ), "Passed!" );
  35602. assert.ok( b.end.equals( one3 ), "Passed!" );
  35603. } );
  35604. QUnit.test( "clone/equal", ( assert ) => {
  35605. var a = new Line3();
  35606. var b = new Line3( zero3, new Vector3( 1, 1, 1 ) );
  35607. var c = new Line3( zero3, new Vector3( 1, 1, 0 ) );
  35608. assert.notOk( a.equals( b ), "Check a and b aren't equal" );
  35609. assert.notOk( a.equals( c ), "Check a and c aren't equal" );
  35610. assert.notOk( b.equals( c ), "Check b and c aren't equal" );
  35611. var a = b.clone();
  35612. assert.ok( a.equals( b ), "Check a and b are equal after clone()" );
  35613. assert.notOk( a.equals( c ), "Check a and c aren't equal after clone()" );
  35614. a.set( zero3, zero3 );
  35615. assert.notOk( a.equals( b ), "Check a and b are not equal after modification" );
  35616. } );
  35617. QUnit.test( "getCenter", ( assert ) => {
  35618. assert.ok( false, "everything's gonna be alright" );
  35619. } );
  35620. QUnit.test( "delta", ( assert ) => {
  35621. assert.ok( false, "everything's gonna be alright" );
  35622. } );
  35623. QUnit.test( "distanceSq", ( assert ) => {
  35624. assert.ok( false, "everything's gonna be alright" );
  35625. } );
  35626. QUnit.test( "distance", ( assert ) => {
  35627. var a = new Line3( zero3, zero3 );
  35628. var b = new Line3( zero3, one3 );
  35629. var c = new Line3( one3.clone().negate(), one3 );
  35630. var d = new Line3( two3.clone().multiplyScalar( - 2 ), two3.clone().negate() );
  35631. assert.numEqual( a.distance(), 0, "Check distance for zero-length line" );
  35632. assert.numEqual( b.distance(), Math.sqrt( 3 ), "Check distance for simple line" );
  35633. assert.numEqual( c.distance(), Math.sqrt( 12 ), "Check distance for negative to positive endpoints" );
  35634. assert.numEqual( d.distance(), Math.sqrt( 12 ), "Check distance for negative to negative endpoints" );
  35635. } );
  35636. QUnit.test( "at", ( assert ) => {
  35637. var a = new Line3( one3.clone(), new Vector3( 1, 1, 2 ) );
  35638. assert.ok( a.at( - 1 ).distanceTo( new Vector3( 1, 1, 0 ) ) < 0.0001, "Passed!" );
  35639. assert.ok( a.at( 0 ).distanceTo( one3.clone() ) < 0.0001, "Passed!" );
  35640. assert.ok( a.at( 1 ).distanceTo( new Vector3( 1, 1, 2 ) ) < 0.0001, "Passed!" );
  35641. assert.ok( a.at( 2 ).distanceTo( new Vector3( 1, 1, 3 ) ) < 0.0001, "Passed!" );
  35642. } );
  35643. QUnit.test( "closestPointToPoint/closestPointToPointParameter", ( assert ) => {
  35644. var a = new Line3( one3.clone(), new Vector3( 1, 1, 2 ) );
  35645. // nearby the ray
  35646. assert.ok( a.closestPointToPointParameter( zero3.clone(), true ) == 0, "Passed!" );
  35647. var b1 = a.closestPointToPoint( zero3.clone(), true );
  35648. assert.ok( b1.distanceTo( new Vector3( 1, 1, 1 ) ) < 0.0001, "Passed!" );
  35649. // nearby the ray
  35650. assert.ok( a.closestPointToPointParameter( zero3.clone(), false ) == - 1, "Passed!" );
  35651. var b2 = a.closestPointToPoint( zero3.clone(), false );
  35652. assert.ok( b2.distanceTo( new Vector3( 1, 1, 0 ) ) < 0.0001, "Passed!" );
  35653. // nearby the ray
  35654. assert.ok( a.closestPointToPointParameter( new Vector3( 1, 1, 5 ), true ) == 1, "Passed!" );
  35655. var b = a.closestPointToPoint( new Vector3( 1, 1, 5 ), true );
  35656. assert.ok( b.distanceTo( new Vector3( 1, 1, 2 ) ) < 0.0001, "Passed!" );
  35657. // exactly on the ray
  35658. assert.ok( a.closestPointToPointParameter( one3.clone(), true ) == 0, "Passed!" );
  35659. var c = a.closestPointToPoint( one3.clone(), true );
  35660. assert.ok( c.distanceTo( one3.clone() ) < 0.0001, "Passed!" );
  35661. } );
  35662. QUnit.test( "applyMatrix4", ( assert ) => {
  35663. var a = new Line3( zero3.clone(), two3.clone() );
  35664. var b = new Vector4( two3.x, two3.y, two3.z, 1 );
  35665. var m = new Matrix4().makeTranslation( x, y, z );
  35666. var v = new Vector3( x, y, z );
  35667. a.applyMatrix4( m );
  35668. assert.ok( a.start.equals( v ), "Translation: check start" );
  35669. assert.ok( a.end.equals( new Vector3( 2 + x, 2 + y, 2 + z ) ), "Translation: check start" );
  35670. // reset starting conditions
  35671. a.set( zero3.clone(), two3.clone() );
  35672. m.makeRotationX( Math.PI );
  35673. a.applyMatrix4( m );
  35674. b.applyMatrix4( m );
  35675. assert.ok( a.start.equals( zero3 ), "Rotation: check start" );
  35676. assert.numEqual( a.end.x, b.x / b.w, "Rotation: check end.x" );
  35677. assert.numEqual( a.end.y, b.y / b.w, "Rotation: check end.y" );
  35678. assert.numEqual( a.end.z, b.z / b.w, "Rotation: check end.z" );
  35679. // reset starting conditions
  35680. a.set( zero3.clone(), two3.clone() );
  35681. b.set( two3.x, two3.y, two3.z, 1 );
  35682. m.setPosition( v );
  35683. a.applyMatrix4( m );
  35684. b.applyMatrix4( m );
  35685. assert.ok( a.start.equals( v ), "Both: check start" );
  35686. assert.numEqual( a.end.x, b.x / b.w, "Both: check end.x" );
  35687. assert.numEqual( a.end.y, b.y / b.w, "Both: check end.y" );
  35688. assert.numEqual( a.end.z, b.z / b.w, "Both: check end.z" );
  35689. } );
  35690. QUnit.test( "equals", ( assert ) => {
  35691. assert.ok( false, "everything's gonna be alright" );
  35692. } );
  35693. } );
  35694. } );
  35695. /**
  35696. * @author humbletim / https://github.com/humbletim
  35697. * @author TristanVALCKE / https://github.com/Itee
  35698. */
  35699. /* global QUnit */
  35700. QUnit.module( 'Maths', () => {
  35701. QUnit.module.todo( 'Math', () => {
  35702. // PUBLIC STUFF
  35703. QUnit.test( "generateUUID", ( assert ) => {
  35704. var a = _Math.generateUUID();
  35705. var regex = /[A-Z0-9]{8}-[A-Z0-9]{4}-4[A-Z0-9]{3}-[A-Z0-9]{4}-[A-Z0-9]{12}/i;
  35706. // note the fixed '4' here ----------^
  35707. assert.ok( regex.test( a ), "Generated UUID matches the expected pattern" );
  35708. } );
  35709. QUnit.test( "clamp", ( assert ) => {
  35710. assert.strictEqual( _Math.clamp( 0.5, 0, 1 ), 0.5, "Value already within limits" );
  35711. assert.strictEqual( _Math.clamp( 0, 0, 1 ), 0, "Value equal to one limit" );
  35712. assert.strictEqual( _Math.clamp( - 0.1, 0, 1 ), 0, "Value too low" );
  35713. assert.strictEqual( _Math.clamp( 1.1, 0, 1 ), 1, "Value too high" );
  35714. } );
  35715. QUnit.test( "euclideanModulo", ( assert ) => {
  35716. assert.ok( isNaN( _Math.euclideanModulo( 6, 0 ) ), "Division by zero returns NaN" );
  35717. assert.strictEqual( _Math.euclideanModulo( 6, 1 ), 0, "Divison by trivial divisor" );
  35718. assert.strictEqual( _Math.euclideanModulo( 6, 2 ), 0, "Divison by non-trivial divisor" );
  35719. assert.strictEqual( _Math.euclideanModulo( 6, 5 ), 1, "Divison by itself - 1" );
  35720. assert.strictEqual( _Math.euclideanModulo( 6, 6 ), 0, "Divison by itself" );
  35721. assert.strictEqual( _Math.euclideanModulo( 6, 7 ), 6, "Divison by itself + 1" );
  35722. } );
  35723. QUnit.test( "mapLinear", ( assert ) => {
  35724. assert.strictEqual( _Math.mapLinear( 0.5, 0, 1, 0, 10 ), 5, "Value within range" );
  35725. assert.strictEqual( _Math.mapLinear( 0.0, 0, 1, 0, 10 ), 0, "Value equal to lower boundary" );
  35726. assert.strictEqual( _Math.mapLinear( 1.0, 0, 1, 0, 10 ), 10, "Value equal to upper boundary" );
  35727. } );
  35728. QUnit.test( "lerp", ( assert ) => {
  35729. assert.ok( false, "everything's gonna be alright" );
  35730. } );
  35731. QUnit.test( "smoothstep", ( assert ) => {
  35732. assert.strictEqual( _Math.smoothstep( - 1, 0, 2 ), 0, "Value lower than minimum" );
  35733. assert.strictEqual( _Math.smoothstep( 0, 0, 2 ), 0, "Value equal to minimum" );
  35734. assert.strictEqual( _Math.smoothstep( 0.5, 0, 2 ), 0.15625, "Value within limits" );
  35735. assert.strictEqual( _Math.smoothstep( 1, 0, 2 ), 0.5, "Value within limits" );
  35736. assert.strictEqual( _Math.smoothstep( 1.5, 0, 2 ), 0.84375, "Value within limits" );
  35737. assert.strictEqual( _Math.smoothstep( 2, 0, 2 ), 1, "Value equal to maximum" );
  35738. assert.strictEqual( _Math.smoothstep( 3, 0, 2 ), 1, "Value highter than maximum" );
  35739. } );
  35740. QUnit.test( "smootherstep", ( assert ) => {
  35741. assert.ok( false, "everything's gonna be alright" );
  35742. } );
  35743. QUnit.test( "randInt", ( assert ) => {
  35744. var low = 1, high = 3;
  35745. var a = _Math.randInt( low, high );
  35746. assert.ok( a >= low, "Value equal to or higher than lower limit" );
  35747. assert.ok( a <= high, "Value equal to or lower than upper limit" );
  35748. } );
  35749. QUnit.test( "randFloat", ( assert ) => {
  35750. var low = 1, high = 3;
  35751. var a = _Math.randFloat( low, high );
  35752. assert.ok( a >= low, "Value equal to or higher than lower limit" );
  35753. assert.ok( a <= high, "Value equal to or lower than upper limit" );
  35754. } );
  35755. QUnit.test( "randFloatSpread", ( assert ) => {
  35756. var a = _Math.randFloatSpread( 3 );
  35757. assert.ok( a > - 3 / 2, "Value higher than lower limit" );
  35758. assert.ok( a < 3 / 2, "Value lower than upper limit" );
  35759. } );
  35760. QUnit.test( "degToRad", ( assert ) => {
  35761. assert.strictEqual( _Math.degToRad( 0 ), 0, "0 degrees" );
  35762. assert.strictEqual( _Math.degToRad( 90 ), Math.PI / 2, "90 degrees" );
  35763. assert.strictEqual( _Math.degToRad( 180 ), Math.PI, "180 degrees" );
  35764. assert.strictEqual( _Math.degToRad( 360 ), Math.PI * 2, "360 degrees" );
  35765. } );
  35766. QUnit.test( "radToDeg", ( assert ) => {
  35767. assert.strictEqual( _Math.radToDeg( 0 ), 0, "0 radians" );
  35768. assert.strictEqual( _Math.radToDeg( Math.PI / 2 ), 90, "Math.PI / 2 radians" );
  35769. assert.strictEqual( _Math.radToDeg( Math.PI ), 180, "Math.PI radians" );
  35770. assert.strictEqual( _Math.radToDeg( Math.PI * 2 ), 360, "Math.PI * 2 radians" );
  35771. } );
  35772. QUnit.test( "isPowerOfTwo", ( assert ) => {
  35773. assert.strictEqual( _Math.isPowerOfTwo( 0 ), false, "0 is not a PoT" );
  35774. assert.strictEqual( _Math.isPowerOfTwo( 1 ), true, "1 is a PoT" );
  35775. assert.strictEqual( _Math.isPowerOfTwo( 2 ), true, "2 is a PoT" );
  35776. assert.strictEqual( _Math.isPowerOfTwo( 3 ), false, "3 is not a PoT" );
  35777. assert.strictEqual( _Math.isPowerOfTwo( 4 ), true, "4 is a PoT" );
  35778. } );
  35779. QUnit.test( "ceilPowerOfTwo", ( assert ) => {
  35780. assert.strictEqual( _Math.ceilPowerOfTwo( 1 ), 1, "Closest higher PoT to 1 is 1" );
  35781. assert.strictEqual( _Math.ceilPowerOfTwo( 3 ), 4, "Closest higher PoT to 3 is 4" );
  35782. assert.strictEqual( _Math.ceilPowerOfTwo( 4 ), 4, "Closest higher PoT to 4 is 4" );
  35783. } );
  35784. QUnit.test( "floorPowerOfTwo", ( assert ) => {
  35785. assert.strictEqual( _Math.floorPowerOfTwo( 1 ), 1, "Closest lower PoT to 1 is 1" );
  35786. assert.strictEqual( _Math.floorPowerOfTwo( 3 ), 2, "Closest lower PoT to 3 is 2" );
  35787. assert.strictEqual( _Math.floorPowerOfTwo( 4 ), 4, "Closest lower PoT to 4 is 4" );
  35788. } );
  35789. } );
  35790. } );
  35791. /**
  35792. * @author bhouston / http://exocortex.com
  35793. * @author TristanVALCKE / https://github.com/Itee
  35794. */
  35795. /* global QUnit */
  35796. function matrixEquals3( a, b, tolerance ) {
  35797. tolerance = tolerance || 0.0001;
  35798. if ( a.elements.length != b.elements.length ) {
  35799. return false;
  35800. }
  35801. for ( var i = 0, il = a.elements.length; i < il; i ++ ) {
  35802. var delta = a.elements[ i ] - b.elements[ i ];
  35803. if ( delta > tolerance ) {
  35804. return false;
  35805. }
  35806. }
  35807. return true;
  35808. }
  35809. function toMatrix4( m3 ) {
  35810. var result = new Matrix4();
  35811. var re = result.elements;
  35812. var me = m3.elements;
  35813. re[ 0 ] = me[ 0 ];
  35814. re[ 1 ] = me[ 1 ];
  35815. re[ 2 ] = me[ 2 ];
  35816. re[ 4 ] = me[ 3 ];
  35817. re[ 5 ] = me[ 4 ];
  35818. re[ 6 ] = me[ 5 ];
  35819. re[ 8 ] = me[ 6 ];
  35820. re[ 9 ] = me[ 7 ];
  35821. re[ 10 ] = me[ 8 ];
  35822. return result;
  35823. }
  35824. QUnit.module( 'Maths', () => {
  35825. QUnit.module.todo( 'Matrix3', () => {
  35826. // INSTANCING
  35827. QUnit.test( "Instancing", ( assert ) => {
  35828. var a = new Matrix3();
  35829. assert.ok( a.determinant() == 1, "Passed!" );
  35830. var b = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35831. assert.ok( b.elements[ 0 ] == 0 );
  35832. assert.ok( b.elements[ 1 ] == 3 );
  35833. assert.ok( b.elements[ 2 ] == 6 );
  35834. assert.ok( b.elements[ 3 ] == 1 );
  35835. assert.ok( b.elements[ 4 ] == 4 );
  35836. assert.ok( b.elements[ 5 ] == 7 );
  35837. assert.ok( b.elements[ 6 ] == 2 );
  35838. assert.ok( b.elements[ 7 ] == 5 );
  35839. assert.ok( b.elements[ 8 ] == 8 );
  35840. assert.ok( ! matrixEquals3( a, b ), "Passed!" );
  35841. } );
  35842. // PUBLIC STUFF
  35843. QUnit.test( "isMatrix3", ( assert ) => {
  35844. assert.ok( false, "everything's gonna be alright" );
  35845. } );
  35846. QUnit.test( "set", ( assert ) => {
  35847. var b = new Matrix3();
  35848. assert.ok( b.determinant() == 1, "Passed!" );
  35849. b.set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35850. assert.ok( b.elements[ 0 ] == 0 );
  35851. assert.ok( b.elements[ 1 ] == 3 );
  35852. assert.ok( b.elements[ 2 ] == 6 );
  35853. assert.ok( b.elements[ 3 ] == 1 );
  35854. assert.ok( b.elements[ 4 ] == 4 );
  35855. assert.ok( b.elements[ 5 ] == 7 );
  35856. assert.ok( b.elements[ 6 ] == 2 );
  35857. assert.ok( b.elements[ 7 ] == 5 );
  35858. assert.ok( b.elements[ 8 ] == 8 );
  35859. } );
  35860. QUnit.test( "identity", ( assert ) => {
  35861. var b = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35862. assert.ok( b.elements[ 0 ] == 0 );
  35863. assert.ok( b.elements[ 1 ] == 3 );
  35864. assert.ok( b.elements[ 2 ] == 6 );
  35865. assert.ok( b.elements[ 3 ] == 1 );
  35866. assert.ok( b.elements[ 4 ] == 4 );
  35867. assert.ok( b.elements[ 5 ] == 7 );
  35868. assert.ok( b.elements[ 6 ] == 2 );
  35869. assert.ok( b.elements[ 7 ] == 5 );
  35870. assert.ok( b.elements[ 8 ] == 8 );
  35871. var a = new Matrix3();
  35872. assert.ok( ! matrixEquals3( a, b ), "Passed!" );
  35873. b.identity();
  35874. assert.ok( matrixEquals3( a, b ), "Passed!" );
  35875. } );
  35876. QUnit.test( "clone", ( assert ) => {
  35877. var a = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35878. var b = a.clone();
  35879. assert.ok( matrixEquals3( a, b ), "Passed!" );
  35880. // ensure that it is a true copy
  35881. a.elements[ 0 ] = 2;
  35882. assert.ok( ! matrixEquals3( a, b ), "Passed!" );
  35883. } );
  35884. QUnit.test( "copy", ( assert ) => {
  35885. var a = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35886. var b = new Matrix3().copy( a );
  35887. assert.ok( matrixEquals3( a, b ), "Passed!" );
  35888. // ensure that it is a true copy
  35889. a.elements[ 0 ] = 2;
  35890. assert.ok( ! matrixEquals3( a, b ), "Passed!" );
  35891. } );
  35892. QUnit.test( "setFromMatrix4", ( assert ) => {
  35893. assert.ok( false, "everything's gonna be alright" );
  35894. } );
  35895. QUnit.test( "applyToBufferAttribute", ( assert ) => {
  35896. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  35897. var attr = new Float32BufferAttribute( [ 1, 2, 1, 3, 0, 3 ], 3 );
  35898. var expected = new Float32Array( [ 8, 20, 32, 12, 30, 48 ] );
  35899. var applied = a.applyToBufferAttribute( attr );
  35900. assert.deepEqual( applied.array, expected, "Check resulting buffer" );
  35901. } );
  35902. QUnit.test( "multiply/premultiply", ( assert ) => {
  35903. // both simply just wrap multiplyMatrices
  35904. var a = new Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  35905. var b = new Matrix3().set( 29, 31, 37, 41, 43, 47, 53, 59, 61 );
  35906. var expectedMultiply = [ 446, 1343, 2491, 486, 1457, 2701, 520, 1569, 2925 ];
  35907. var expectedPremultiply = [ 904, 1182, 1556, 1131, 1489, 1967, 1399, 1845, 2435 ];
  35908. a.multiply( b );
  35909. assert.deepEqual( a.elements, expectedMultiply, "multiply: check result" );
  35910. a.set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  35911. a.premultiply( b );
  35912. assert.deepEqual( a.elements, expectedPremultiply, "premultiply: check result" );
  35913. } );
  35914. QUnit.test( "multiplyMatrices", ( assert ) => {
  35915. // Reference:
  35916. //
  35917. // #!/usr/bin/env python
  35918. // from __future__ import print_function
  35919. // import numpy as np
  35920. // print(
  35921. // np.dot(
  35922. // np.reshape([2, 3, 5, 7, 11, 13, 17, 19, 23], (3, 3)),
  35923. // np.reshape([29, 31, 37, 41, 43, 47, 53, 59, 61], (3, 3))
  35924. // )
  35925. // )
  35926. //
  35927. // [[ 446 486 520]
  35928. // [1343 1457 1569]
  35929. // [2491 2701 2925]]
  35930. var lhs = new Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  35931. var rhs = new Matrix3().set( 29, 31, 37, 41, 43, 47, 53, 59, 61 );
  35932. var ans = new Matrix3();
  35933. ans.multiplyMatrices( lhs, rhs );
  35934. assert.ok( ans.elements[ 0 ] == 446 );
  35935. assert.ok( ans.elements[ 1 ] == 1343 );
  35936. assert.ok( ans.elements[ 2 ] == 2491 );
  35937. assert.ok( ans.elements[ 3 ] == 486 );
  35938. assert.ok( ans.elements[ 4 ] == 1457 );
  35939. assert.ok( ans.elements[ 5 ] == 2701 );
  35940. assert.ok( ans.elements[ 6 ] == 520 );
  35941. assert.ok( ans.elements[ 7 ] == 1569 );
  35942. assert.ok( ans.elements[ 8 ] == 2925 );
  35943. } );
  35944. QUnit.test( "multiplyScalar", ( assert ) => {
  35945. var b = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35946. assert.ok( b.elements[ 0 ] == 0 );
  35947. assert.ok( b.elements[ 1 ] == 3 );
  35948. assert.ok( b.elements[ 2 ] == 6 );
  35949. assert.ok( b.elements[ 3 ] == 1 );
  35950. assert.ok( b.elements[ 4 ] == 4 );
  35951. assert.ok( b.elements[ 5 ] == 7 );
  35952. assert.ok( b.elements[ 6 ] == 2 );
  35953. assert.ok( b.elements[ 7 ] == 5 );
  35954. assert.ok( b.elements[ 8 ] == 8 );
  35955. b.multiplyScalar( 2 );
  35956. assert.ok( b.elements[ 0 ] == 0 * 2 );
  35957. assert.ok( b.elements[ 1 ] == 3 * 2 );
  35958. assert.ok( b.elements[ 2 ] == 6 * 2 );
  35959. assert.ok( b.elements[ 3 ] == 1 * 2 );
  35960. assert.ok( b.elements[ 4 ] == 4 * 2 );
  35961. assert.ok( b.elements[ 5 ] == 7 * 2 );
  35962. assert.ok( b.elements[ 6 ] == 2 * 2 );
  35963. assert.ok( b.elements[ 7 ] == 5 * 2 );
  35964. assert.ok( b.elements[ 8 ] == 8 * 2 );
  35965. } );
  35966. QUnit.test( "determinant", ( assert ) => {
  35967. var a = new Matrix3();
  35968. assert.ok( a.determinant() == 1, "Passed!" );
  35969. a.elements[ 0 ] = 2;
  35970. assert.ok( a.determinant() == 2, "Passed!" );
  35971. a.elements[ 0 ] = 0;
  35972. assert.ok( a.determinant() == 0, "Passed!" );
  35973. // calculated via http://www.euclideanspace.com/maths/algebra/matrix/functions/determinant/threeD/index.htm
  35974. a.set( 2, 3, 4, 5, 13, 7, 8, 9, 11 );
  35975. assert.ok( a.determinant() == - 73, "Passed!" );
  35976. } );
  35977. QUnit.test( "getInverse", ( assert ) => {
  35978. var identity = new Matrix3();
  35979. var identity4 = new Matrix4();
  35980. var a = new Matrix3();
  35981. var b = new Matrix3().set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  35982. var c = new Matrix3().set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  35983. b.getInverse( a, false );
  35984. assert.ok( matrixEquals3( a, identity ), "Matrix a is identity matrix" );
  35985. try {
  35986. b.getInverse( c, true );
  35987. assert.ok( false, "Should never get here !" ); // should never get here.
  35988. } catch ( err ) {
  35989. assert.ok( true, "Passed: " + err );
  35990. }
  35991. var testMatrices = [
  35992. new Matrix4().makeRotationX( 0.3 ),
  35993. new Matrix4().makeRotationX( - 0.3 ),
  35994. new Matrix4().makeRotationY( 0.3 ),
  35995. new Matrix4().makeRotationY( - 0.3 ),
  35996. new Matrix4().makeRotationZ( 0.3 ),
  35997. new Matrix4().makeRotationZ( - 0.3 ),
  35998. new Matrix4().makeScale( 1, 2, 3 ),
  35999. new Matrix4().makeScale( 1 / 8, 1 / 2, 1 / 3 )
  36000. ];
  36001. for ( var i = 0, il = testMatrices.length; i < il; i ++ ) {
  36002. var m = testMatrices[ i ];
  36003. a.setFromMatrix4( m );
  36004. var mInverse3 = b.getInverse( a );
  36005. var mInverse = toMatrix4( mInverse3 );
  36006. // the determinant of the inverse should be the reciprocal
  36007. assert.ok( Math.abs( a.determinant() * mInverse3.determinant() - 1 ) < 0.0001, "Passed!" );
  36008. assert.ok( Math.abs( m.determinant() * mInverse.determinant() - 1 ) < 0.0001, "Passed!" );
  36009. var mProduct = new Matrix4().multiplyMatrices( m, mInverse );
  36010. assert.ok( Math.abs( mProduct.determinant() - 1 ) < 0.0001, "Passed!" );
  36011. assert.ok( matrixEquals3( mProduct, identity4 ), "Passed!" );
  36012. }
  36013. } );
  36014. QUnit.test( "transpose", ( assert ) => {
  36015. var a = new Matrix3();
  36016. var b = a.clone().transpose();
  36017. assert.ok( matrixEquals3( a, b ), "Passed!" );
  36018. var b = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  36019. var c = b.clone().transpose();
  36020. assert.ok( ! matrixEquals3( b, c ), "Passed!" );
  36021. c.transpose();
  36022. assert.ok( matrixEquals3( b, c ), "Passed!" );
  36023. } );
  36024. QUnit.test( "getNormalMatrix", ( assert ) => {
  36025. var a = new Matrix3();
  36026. var b = new Matrix4().set(
  36027. 2, 3, 5, 7,
  36028. 11, 13, 17, 19,
  36029. 23, 29, 31, 37,
  36030. 41, 43, 47, 57
  36031. );
  36032. var expected = new Matrix3().set(
  36033. - 1.2857142857142856, 0.7142857142857143, 0.2857142857142857,
  36034. 0.7428571428571429, - 0.7571428571428571, 0.15714285714285714,
  36035. - 0.19999999999999998, 0.3, - 0.09999999999999999
  36036. );
  36037. a.getNormalMatrix( b );
  36038. assert.ok( matrixEquals3( a, expected ), "Check resulting Matrix3" );
  36039. } );
  36040. QUnit.test( "transposeIntoArray", ( assert ) => {
  36041. assert.ok( false, "everything's gonna be alright" );
  36042. } );
  36043. QUnit.test( "setUvTransform", ( assert ) => {
  36044. var a = new Matrix3().set(
  36045. 0.1767766952966369, 0.17677669529663687, 0.32322330470336313,
  36046. - 0.17677669529663687, 0.1767766952966369, 0.5,
  36047. 0, 0, 1
  36048. );
  36049. var b = new Matrix3();
  36050. var params = {
  36051. centerX: 0.5,
  36052. centerY: 0.5,
  36053. offsetX: 0,
  36054. offsetY: 0,
  36055. repeatX: 0.25,
  36056. repeatY: 0.25,
  36057. rotation: 0.7753981633974483
  36058. };
  36059. var expected = new Matrix3().set(
  36060. 0.1785355940258599, 0.17500011904519763, 0.32323214346447127,
  36061. - 0.17500011904519763, 0.1785355940258599, 0.4982322625096689,
  36062. 0, 0, 1
  36063. );
  36064. a.setUvTransform(
  36065. params.offsetX, params.offsetY,
  36066. params.repeatX, params.repeatY,
  36067. params.rotation,
  36068. params.centerX, params.centerY
  36069. );
  36070. b.identity()
  36071. .translate( - params.centerX, - params.centerY )
  36072. .rotate( params.rotation )
  36073. .scale( params.repeatX, params.repeatY )
  36074. .translate( params.centerX, params.centerY )
  36075. .translate( params.offsetX, params.offsetY );
  36076. assert.ok( matrixEquals3( a, expected ), "Check direct method" );
  36077. assert.ok( matrixEquals3( b, expected ), "Check indirect method" );
  36078. } );
  36079. QUnit.test( "scale", ( assert ) => {
  36080. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  36081. var expected = new Matrix3().set(
  36082. 0.25, 0.5, 0.75,
  36083. 1, 1.25, 1.5,
  36084. 7, 8, 9
  36085. );
  36086. a.scale( 0.25, 0.25 );
  36087. assert.ok( matrixEquals3( a, expected ), "Check scaling result" );
  36088. } );
  36089. QUnit.test( "rotate", ( assert ) => {
  36090. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  36091. var expected = new Matrix3().set(
  36092. 3.5355339059327373, 4.949747468305833, 6.363961030678928,
  36093. 2.121320343559643, 2.121320343559643, 2.1213203435596433,
  36094. 7, 8, 9
  36095. );
  36096. a.rotate( Math.PI / 4 );
  36097. assert.ok( matrixEquals3( a, expected ), "Check rotated result" );
  36098. } );
  36099. QUnit.test( "translate", ( assert ) => {
  36100. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  36101. var expected = new Matrix3().set( 22, 26, 30, 53, 61, 69, 7, 8, 9 );
  36102. a.translate( 3, 7 );
  36103. assert.ok( matrixEquals3( a, expected ), "Check translation result" );
  36104. } );
  36105. QUnit.test( "equals", ( assert ) => {
  36106. var a = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  36107. var b = new Matrix3().set( 0, - 1, 2, 3, 4, 5, 6, 7, 8 );
  36108. assert.notOk( a.equals( b ), "Check that a does not equal b" );
  36109. assert.notOk( b.equals( a ), "Check that b does not equal a" );
  36110. a.copy( b );
  36111. assert.ok( a.equals( b ), "Check that a equals b after copy()" );
  36112. assert.ok( b.equals( a ), "Check that b equals a after copy()" );
  36113. } );
  36114. QUnit.test( "fromArray", ( assert ) => {
  36115. assert.ok( false, "everything's gonna be alright" );
  36116. } );
  36117. QUnit.test( "toArray", ( assert ) => {
  36118. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  36119. var noOffset = [ 1, 4, 7, 2, 5, 8, 3, 6, 9 ];
  36120. var withOffset = [ undefined, 1, 4, 7, 2, 5, 8, 3, 6, 9 ];
  36121. var array = a.toArray();
  36122. assert.deepEqual( array, noOffset, "No array, no offset" );
  36123. var array = [];
  36124. a.toArray( array );
  36125. assert.deepEqual( array, noOffset, "With array, no offset" );
  36126. var array = [];
  36127. a.toArray( array, 1 );
  36128. assert.deepEqual( array, withOffset, "With array, with offset" );
  36129. } );
  36130. } );
  36131. } );
  36132. /**
  36133. * @author bhouston / http://exocortex.com
  36134. * @author TristanVALCKE / https://github.com/Itee
  36135. */
  36136. /* global QUnit */
  36137. function matrixEquals4$1( a, b, tolerance ) {
  36138. tolerance = tolerance || 0.0001;
  36139. if ( a.elements.length != b.elements.length ) {
  36140. return false;
  36141. }
  36142. for ( var i = 0, il = a.elements.length; i < il; i ++ ) {
  36143. var delta = a.elements[ i ] - b.elements[ i ];
  36144. if ( delta > tolerance ) {
  36145. return false;
  36146. }
  36147. }
  36148. return true;
  36149. }
  36150. // from Euler.js
  36151. function eulerEquals$1( a, b, tolerance ) {
  36152. tolerance = tolerance || 0.0001;
  36153. var diff = Math.abs( a.x - b.x ) + Math.abs( a.y - b.y ) + Math.abs( a.z - b.z );
  36154. return ( diff < tolerance );
  36155. }
  36156. QUnit.module( 'Maths', () => {
  36157. QUnit.module.todo( 'Matrix4', () => {
  36158. // INSTANCING
  36159. QUnit.test( "Instancing", ( assert ) => {
  36160. var a = new Matrix4();
  36161. assert.ok( a.determinant() == 1, "Passed!" );
  36162. var b = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36163. assert.ok( b.elements[ 0 ] == 0 );
  36164. assert.ok( b.elements[ 1 ] == 4 );
  36165. assert.ok( b.elements[ 2 ] == 8 );
  36166. assert.ok( b.elements[ 3 ] == 12 );
  36167. assert.ok( b.elements[ 4 ] == 1 );
  36168. assert.ok( b.elements[ 5 ] == 5 );
  36169. assert.ok( b.elements[ 6 ] == 9 );
  36170. assert.ok( b.elements[ 7 ] == 13 );
  36171. assert.ok( b.elements[ 8 ] == 2 );
  36172. assert.ok( b.elements[ 9 ] == 6 );
  36173. assert.ok( b.elements[ 10 ] == 10 );
  36174. assert.ok( b.elements[ 11 ] == 14 );
  36175. assert.ok( b.elements[ 12 ] == 3 );
  36176. assert.ok( b.elements[ 13 ] == 7 );
  36177. assert.ok( b.elements[ 14 ] == 11 );
  36178. assert.ok( b.elements[ 15 ] == 15 );
  36179. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  36180. } );
  36181. // PUBLIC STUFF
  36182. QUnit.test( "isMatrix4", ( assert ) => {
  36183. assert.ok( false, "everything's gonna be alright" );
  36184. } );
  36185. QUnit.test( "set", ( assert ) => {
  36186. var b = new Matrix4();
  36187. assert.ok( b.determinant() == 1, "Passed!" );
  36188. b.set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36189. assert.ok( b.elements[ 0 ] == 0 );
  36190. assert.ok( b.elements[ 1 ] == 4 );
  36191. assert.ok( b.elements[ 2 ] == 8 );
  36192. assert.ok( b.elements[ 3 ] == 12 );
  36193. assert.ok( b.elements[ 4 ] == 1 );
  36194. assert.ok( b.elements[ 5 ] == 5 );
  36195. assert.ok( b.elements[ 6 ] == 9 );
  36196. assert.ok( b.elements[ 7 ] == 13 );
  36197. assert.ok( b.elements[ 8 ] == 2 );
  36198. assert.ok( b.elements[ 9 ] == 6 );
  36199. assert.ok( b.elements[ 10 ] == 10 );
  36200. assert.ok( b.elements[ 11 ] == 14 );
  36201. assert.ok( b.elements[ 12 ] == 3 );
  36202. assert.ok( b.elements[ 13 ] == 7 );
  36203. assert.ok( b.elements[ 14 ] == 11 );
  36204. assert.ok( b.elements[ 15 ] == 15 );
  36205. } );
  36206. QUnit.test( "identity", ( assert ) => {
  36207. var b = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36208. assert.ok( b.elements[ 0 ] == 0 );
  36209. assert.ok( b.elements[ 1 ] == 4 );
  36210. assert.ok( b.elements[ 2 ] == 8 );
  36211. assert.ok( b.elements[ 3 ] == 12 );
  36212. assert.ok( b.elements[ 4 ] == 1 );
  36213. assert.ok( b.elements[ 5 ] == 5 );
  36214. assert.ok( b.elements[ 6 ] == 9 );
  36215. assert.ok( b.elements[ 7 ] == 13 );
  36216. assert.ok( b.elements[ 8 ] == 2 );
  36217. assert.ok( b.elements[ 9 ] == 6 );
  36218. assert.ok( b.elements[ 10 ] == 10 );
  36219. assert.ok( b.elements[ 11 ] == 14 );
  36220. assert.ok( b.elements[ 12 ] == 3 );
  36221. assert.ok( b.elements[ 13 ] == 7 );
  36222. assert.ok( b.elements[ 14 ] == 11 );
  36223. assert.ok( b.elements[ 15 ] == 15 );
  36224. var a = new Matrix4();
  36225. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  36226. b.identity();
  36227. assert.ok( matrixEquals4$1( a, b ), "Passed!" );
  36228. } );
  36229. QUnit.test( "clone", ( assert ) => {
  36230. var a = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36231. var b = a.clone();
  36232. assert.ok( matrixEquals4$1( a, b ), "Passed!" );
  36233. // ensure that it is a true copy
  36234. a.elements[ 0 ] = 2;
  36235. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  36236. } );
  36237. QUnit.test( "copy", ( assert ) => {
  36238. var a = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36239. var b = new Matrix4().copy( a );
  36240. assert.ok( matrixEquals4$1( a, b ), "Passed!" );
  36241. // ensure that it is a true copy
  36242. a.elements[ 0 ] = 2;
  36243. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  36244. } );
  36245. QUnit.test( "copyPosition", ( assert ) => {
  36246. var a = new Matrix4().set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  36247. var b = new Matrix4().set( 1, 2, 3, 0, 5, 6, 7, 0, 9, 10, 11, 0, 13, 14, 15, 16 );
  36248. assert.notOk( matrixEquals4$1( a, b ), "a and b initially not equal" );
  36249. b.copyPosition( a );
  36250. assert.ok( matrixEquals4$1( a, b ), "a and b equal after copyPosition()" );
  36251. } );
  36252. QUnit.test( "makeBasis/extractBasis", ( assert ) => {
  36253. var identityBasis = [ new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ) ];
  36254. var a = new Matrix4().makeBasis( identityBasis[ 0 ], identityBasis[ 1 ], identityBasis[ 2 ] );
  36255. var identity = new Matrix4();
  36256. assert.ok( matrixEquals4$1( a, identity ), "Passed!" );
  36257. var testBases = [[ new Vector3( 0, 1, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ) ]];
  36258. for ( var i = 0; i < testBases.length; i ++ ) {
  36259. var testBasis = testBases[ i ];
  36260. var b = new Matrix4().makeBasis( testBasis[ 0 ], testBasis[ 1 ], testBasis[ 2 ] );
  36261. var outBasis = [ new Vector3(), new Vector3(), new Vector3() ];
  36262. b.extractBasis( outBasis[ 0 ], outBasis[ 1 ], outBasis[ 2 ] );
  36263. // check what goes in, is what comes out.
  36264. for ( var j = 0; j < outBasis.length; j ++ ) {
  36265. assert.ok( outBasis[ j ].equals( testBasis[ j ] ), "Passed!" );
  36266. }
  36267. // get the basis out the hard war
  36268. for ( var j = 0; j < identityBasis.length; j ++ ) {
  36269. outBasis[ j ].copy( identityBasis[ j ] );
  36270. outBasis[ j ].applyMatrix4( b );
  36271. }
  36272. // did the multiply method of basis extraction work?
  36273. for ( var j = 0; j < outBasis.length; j ++ ) {
  36274. assert.ok( outBasis[ j ].equals( testBasis[ j ] ), "Passed!" );
  36275. }
  36276. }
  36277. } );
  36278. QUnit.test( "extractRotation", ( assert ) => {
  36279. assert.ok( false, "everything's gonna be alright" );
  36280. } );
  36281. QUnit.test( "makeRotationFromEuler/extractRotation", ( assert ) => {
  36282. var testValues = [
  36283. new Euler( 0, 0, 0, "XYZ" ),
  36284. new Euler( 1, 0, 0, "XYZ" ),
  36285. new Euler( 0, 1, 0, "ZYX" ),
  36286. new Euler( 0, 0, 0.5, "YZX" ),
  36287. new Euler( 0, 0, - 0.5, "YZX" )
  36288. ];
  36289. for ( var i = 0; i < testValues.length; i ++ ) {
  36290. var v = testValues[ i ];
  36291. var m = new Matrix4().makeRotationFromEuler( v );
  36292. var v2 = new Euler().setFromRotationMatrix( m, v.order );
  36293. var m2 = new Matrix4().makeRotationFromEuler( v2 );
  36294. assert.ok( matrixEquals4$1( m, m2, eps ), "makeRotationFromEuler #" + i + ": original and Euler-derived matrices are equal" );
  36295. assert.ok( eulerEquals$1( v, v2, eps ), "makeRotationFromEuler #" + i + ": original and matrix-derived Eulers are equal" );
  36296. var m3 = new Matrix4().extractRotation( m2 );
  36297. var v3 = new Euler().setFromRotationMatrix( m3, v.order );
  36298. assert.ok( matrixEquals4$1( m, m3, eps ), "extractRotation #" + i + ": original and extracted matrices are equal" );
  36299. assert.ok( eulerEquals$1( v, v3, eps ), "extractRotation #" + i + ": original and extracted Eulers are equal" );
  36300. }
  36301. } );
  36302. QUnit.test( "lookAt", ( assert ) => {
  36303. var a = new Matrix4();
  36304. var expected = new Matrix4().identity();
  36305. var eye = new Vector3( 0, 0, 0 );
  36306. var target = new Vector3( 0, 1, - 1 );
  36307. var up = new Vector3( 0, 1, 0 );
  36308. a.lookAt( eye, target, up );
  36309. var rotation = new Euler().setFromRotationMatrix( a );
  36310. assert.numEqual( rotation.x * ( 180 / Math.PI ), 45, "Check the rotation" );
  36311. // eye and target are in the same position
  36312. eye.copy( target );
  36313. a.lookAt( eye, target, up );
  36314. assert.ok( matrixEquals4$1( a, expected ), "Check the result for eye == target" );
  36315. // up and z are parallel
  36316. eye.set( 0, 1, 0 );
  36317. target.set( 0, 0, 0 );
  36318. a.lookAt( eye, target, up );
  36319. expected.set(
  36320. 1, 0, 0, 0,
  36321. 0, 0.0001, 1, 0,
  36322. 0, - 1, 0.0001, 0,
  36323. 0, 0, 0, 1
  36324. );
  36325. assert.ok( matrixEquals4$1( a, expected ), "Check the result for when up and z are parallel" );
  36326. } );
  36327. QUnit.test( "multiply", ( assert ) => {
  36328. assert.ok( false, "everything's gonna be alright" );
  36329. } );
  36330. QUnit.test( "premultiply", ( assert ) => {
  36331. assert.ok( false, "everything's gonna be alright" );
  36332. } );
  36333. QUnit.test( "multiplyMatrices", ( assert ) => {
  36334. // Reference:
  36335. //
  36336. // #!/usr/bin/env python
  36337. // from __future__ import print_function
  36338. // import numpy as np
  36339. // print(
  36340. // np.dot(
  36341. // np.reshape([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53], (4, 4)),
  36342. // np.reshape([59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131], (4, 4))
  36343. // )
  36344. // )
  36345. //
  36346. // [[ 1585 1655 1787 1861]
  36347. // [ 5318 5562 5980 6246]
  36348. // [10514 11006 11840 12378]
  36349. // [15894 16634 17888 18710]]
  36350. var lhs = new Matrix4().set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  36351. var rhs = new Matrix4().set( 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131 );
  36352. var ans = new Matrix4();
  36353. ans.multiplyMatrices( lhs, rhs );
  36354. assert.ok( ans.elements[ 0 ] == 1585 );
  36355. assert.ok( ans.elements[ 1 ] == 5318 );
  36356. assert.ok( ans.elements[ 2 ] == 10514 );
  36357. assert.ok( ans.elements[ 3 ] == 15894 );
  36358. assert.ok( ans.elements[ 4 ] == 1655 );
  36359. assert.ok( ans.elements[ 5 ] == 5562 );
  36360. assert.ok( ans.elements[ 6 ] == 11006 );
  36361. assert.ok( ans.elements[ 7 ] == 16634 );
  36362. assert.ok( ans.elements[ 8 ] == 1787 );
  36363. assert.ok( ans.elements[ 9 ] == 5980 );
  36364. assert.ok( ans.elements[ 10 ] == 11840 );
  36365. assert.ok( ans.elements[ 11 ] == 17888 );
  36366. assert.ok( ans.elements[ 12 ] == 1861 );
  36367. assert.ok( ans.elements[ 13 ] == 6246 );
  36368. assert.ok( ans.elements[ 14 ] == 12378 );
  36369. assert.ok( ans.elements[ 15 ] == 18710 );
  36370. } );
  36371. QUnit.test( "multiplyScalar", ( assert ) => {
  36372. var b = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36373. assert.ok( b.elements[ 0 ] == 0 );
  36374. assert.ok( b.elements[ 1 ] == 4 );
  36375. assert.ok( b.elements[ 2 ] == 8 );
  36376. assert.ok( b.elements[ 3 ] == 12 );
  36377. assert.ok( b.elements[ 4 ] == 1 );
  36378. assert.ok( b.elements[ 5 ] == 5 );
  36379. assert.ok( b.elements[ 6 ] == 9 );
  36380. assert.ok( b.elements[ 7 ] == 13 );
  36381. assert.ok( b.elements[ 8 ] == 2 );
  36382. assert.ok( b.elements[ 9 ] == 6 );
  36383. assert.ok( b.elements[ 10 ] == 10 );
  36384. assert.ok( b.elements[ 11 ] == 14 );
  36385. assert.ok( b.elements[ 12 ] == 3 );
  36386. assert.ok( b.elements[ 13 ] == 7 );
  36387. assert.ok( b.elements[ 14 ] == 11 );
  36388. assert.ok( b.elements[ 15 ] == 15 );
  36389. b.multiplyScalar( 2 );
  36390. assert.ok( b.elements[ 0 ] == 0 * 2 );
  36391. assert.ok( b.elements[ 1 ] == 4 * 2 );
  36392. assert.ok( b.elements[ 2 ] == 8 * 2 );
  36393. assert.ok( b.elements[ 3 ] == 12 * 2 );
  36394. assert.ok( b.elements[ 4 ] == 1 * 2 );
  36395. assert.ok( b.elements[ 5 ] == 5 * 2 );
  36396. assert.ok( b.elements[ 6 ] == 9 * 2 );
  36397. assert.ok( b.elements[ 7 ] == 13 * 2 );
  36398. assert.ok( b.elements[ 8 ] == 2 * 2 );
  36399. assert.ok( b.elements[ 9 ] == 6 * 2 );
  36400. assert.ok( b.elements[ 10 ] == 10 * 2 );
  36401. assert.ok( b.elements[ 11 ] == 14 * 2 );
  36402. assert.ok( b.elements[ 12 ] == 3 * 2 );
  36403. assert.ok( b.elements[ 13 ] == 7 * 2 );
  36404. assert.ok( b.elements[ 14 ] == 11 * 2 );
  36405. assert.ok( b.elements[ 15 ] == 15 * 2 );
  36406. } );
  36407. QUnit.test( "applyToBufferAttribute", ( assert ) => {
  36408. var a = new Matrix4().set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  36409. var attr = new Float32BufferAttribute( [ 1, 2, 1, 3, 0, 3 ], 3 );
  36410. var expected = new Float32BufferAttribute( [
  36411. 0.1666666716337204, 0.4444444477558136, 0.7222222089767456,
  36412. 0.1599999964237213, 0.4399999976158142, 0.7200000286102295
  36413. ], 3 );
  36414. var applied = a.applyToBufferAttribute( attr );
  36415. assert.strictEqual( expected.count, applied.count, "Applied buffer and expected buffer have the same number of entries" );
  36416. for ( var i = 0, l = expected.count; i < l; i ++ ) {
  36417. assert.ok( Math.abs( applied.getX( i ) - expected.getX( i ) ) <= eps, "Check x" );
  36418. assert.ok( Math.abs( applied.getY( i ) - expected.getY( i ) ) <= eps, "Check y" );
  36419. assert.ok( Math.abs( applied.getZ( i ) - expected.getZ( i ) ) <= eps, "Check z" );
  36420. }
  36421. } );
  36422. QUnit.test( "determinant", ( assert ) => {
  36423. var a = new Matrix4();
  36424. assert.ok( a.determinant() == 1, "Passed!" );
  36425. a.elements[ 0 ] = 2;
  36426. assert.ok( a.determinant() == 2, "Passed!" );
  36427. a.elements[ 0 ] = 0;
  36428. assert.ok( a.determinant() == 0, "Passed!" );
  36429. // calculated via http://www.euclideanspace.com/maths/algebra/matrix/functions/determinant/fourD/index.htm
  36430. a.set( 2, 3, 4, 5, - 1, - 21, - 3, - 4, 6, 7, 8, 10, - 8, - 9, - 10, - 12 );
  36431. assert.ok( a.determinant() == 76, "Passed!" );
  36432. } );
  36433. QUnit.test( "transpose", ( assert ) => {
  36434. var a = new Matrix4();
  36435. var b = a.clone().transpose();
  36436. assert.ok( matrixEquals4$1( a, b ), "Passed!" );
  36437. var b = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36438. var c = b.clone().transpose();
  36439. assert.ok( ! matrixEquals4$1( b, c ), "Passed!" );
  36440. c.transpose();
  36441. assert.ok( matrixEquals4$1( b, c ), "Passed!" );
  36442. } );
  36443. QUnit.test( "setPosition", ( assert ) => {
  36444. assert.ok( false, "everything's gonna be alright" );
  36445. } );
  36446. QUnit.test( "getInverse", ( assert ) => {
  36447. var identity = new Matrix4();
  36448. var a = new Matrix4();
  36449. var b = new Matrix4().set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  36450. var c = new Matrix4().set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  36451. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  36452. b.getInverse( a, false );
  36453. assert.ok( matrixEquals4$1( b, new Matrix4() ), "Passed!" );
  36454. try {
  36455. b.getInverse( c, true );
  36456. assert.ok( false, "Passed!" ); // should never get here.
  36457. } catch ( err ) {
  36458. assert.ok( true, "Passed!" );
  36459. }
  36460. var testMatrices = [
  36461. new Matrix4().makeRotationX( 0.3 ),
  36462. new Matrix4().makeRotationX( - 0.3 ),
  36463. new Matrix4().makeRotationY( 0.3 ),
  36464. new Matrix4().makeRotationY( - 0.3 ),
  36465. new Matrix4().makeRotationZ( 0.3 ),
  36466. new Matrix4().makeRotationZ( - 0.3 ),
  36467. new Matrix4().makeScale( 1, 2, 3 ),
  36468. new Matrix4().makeScale( 1 / 8, 1 / 2, 1 / 3 ),
  36469. new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 1000 ),
  36470. new Matrix4().makePerspective( - 16, 16, 9, - 9, 0.1, 10000 ),
  36471. new Matrix4().makeTranslation( 1, 2, 3 )
  36472. ];
  36473. for ( var i = 0, il = testMatrices.length; i < il; i ++ ) {
  36474. var m = testMatrices[ i ];
  36475. var mInverse = new Matrix4().getInverse( m );
  36476. var mSelfInverse = m.clone();
  36477. mSelfInverse.getInverse( mSelfInverse );
  36478. // self-inverse should the same as inverse
  36479. assert.ok( matrixEquals4$1( mSelfInverse, mInverse ), "Passed!" );
  36480. // the determinant of the inverse should be the reciprocal
  36481. assert.ok( Math.abs( m.determinant() * mInverse.determinant() - 1 ) < 0.0001, "Passed!" );
  36482. var mProduct = new Matrix4().multiplyMatrices( m, mInverse );
  36483. // the determinant of the identity matrix is 1
  36484. assert.ok( Math.abs( mProduct.determinant() - 1 ) < 0.0001, "Passed!" );
  36485. assert.ok( matrixEquals4$1( mProduct, identity ), "Passed!" );
  36486. }
  36487. } );
  36488. QUnit.test( "scale", ( assert ) => {
  36489. assert.ok( false, "everything's gonna be alright" );
  36490. } );
  36491. QUnit.test( "getMaxScaleOnAxis", ( assert ) => {
  36492. var a = new Matrix4().set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  36493. var expected = Math.sqrt( 3 * 3 + 7 * 7 + 11 * 11 );
  36494. assert.ok( Math.abs( a.getMaxScaleOnAxis() - expected ) <= eps, "Check result" );
  36495. } );
  36496. QUnit.test( "makeTranslation", ( assert ) => {
  36497. assert.ok( false, "everything's gonna be alright" );
  36498. } );
  36499. QUnit.test( "makeRotationX", ( assert ) => {
  36500. assert.ok( false, "everything's gonna be alright" );
  36501. } );
  36502. QUnit.test( "makeRotationY", ( assert ) => {
  36503. assert.ok( false, "everything's gonna be alright" );
  36504. } );
  36505. QUnit.test( "makeRotationZ", ( assert ) => {
  36506. assert.ok( false, "everything's gonna be alright" );
  36507. } );
  36508. QUnit.test( "makeRotationAxis", ( assert ) => {
  36509. var axis = new Vector3( 1.5, 0.0, 1.0 ).normalize();
  36510. var radians = _Math.degToRad( 45 );
  36511. var a = new Matrix4().makeRotationAxis( axis, radians );
  36512. var expected = new Matrix4().set(
  36513. 0.9098790095958609, - 0.39223227027636803, 0.13518148560620882, 0,
  36514. 0.39223227027636803, 0.7071067811865476, - 0.588348405414552, 0,
  36515. 0.13518148560620882, 0.588348405414552, 0.7972277715906868, 0,
  36516. 0, 0, 0, 1
  36517. );
  36518. assert.ok( matrixEquals4$1( a, expected ), "Check numeric result" );
  36519. } );
  36520. QUnit.test( "makeScale", ( assert ) => {
  36521. assert.ok( false, "everything's gonna be alright" );
  36522. } );
  36523. QUnit.test( "makeShear", ( assert ) => {
  36524. assert.ok( false, "everything's gonna be alright" );
  36525. } );
  36526. QUnit.test( "compose/decompose", ( assert ) => {
  36527. var tValues = [
  36528. new Vector3(),
  36529. new Vector3( 3, 0, 0 ),
  36530. new Vector3( 0, 4, 0 ),
  36531. new Vector3( 0, 0, 5 ),
  36532. new Vector3( - 6, 0, 0 ),
  36533. new Vector3( 0, - 7, 0 ),
  36534. new Vector3( 0, 0, - 8 ),
  36535. new Vector3( - 2, 5, - 9 ),
  36536. new Vector3( - 2, - 5, - 9 )
  36537. ];
  36538. var sValues = [
  36539. new Vector3( 1, 1, 1 ),
  36540. new Vector3( 2, 2, 2 ),
  36541. new Vector3( 1, - 1, 1 ),
  36542. new Vector3( - 1, 1, 1 ),
  36543. new Vector3( 1, 1, - 1 ),
  36544. new Vector3( 2, - 2, 1 ),
  36545. new Vector3( - 1, 2, - 2 ),
  36546. new Vector3( - 1, - 1, - 1 ),
  36547. new Vector3( - 2, - 2, - 2 )
  36548. ];
  36549. var rValues = [
  36550. new Quaternion(),
  36551. new Quaternion().setFromEuler( new Euler( 1, 1, 0 ) ),
  36552. new Quaternion().setFromEuler( new Euler( 1, - 1, 1 ) ),
  36553. new Quaternion( 0, 0.9238795292366128, 0, 0.38268342717215614 )
  36554. ];
  36555. for ( var ti = 0; ti < tValues.length; ti ++ ) {
  36556. for ( var si = 0; si < sValues.length; si ++ ) {
  36557. for ( var ri = 0; ri < rValues.length; ri ++ ) {
  36558. var t = tValues[ ti ];
  36559. var s = sValues[ si ];
  36560. var r = rValues[ ri ];
  36561. var m = new Matrix4().compose( t, r, s );
  36562. var t2 = new Vector3();
  36563. var r2 = new Quaternion();
  36564. var s2 = new Vector3();
  36565. m.decompose( t2, r2, s2 );
  36566. var m2 = new Matrix4().compose( t2, r2, s2 );
  36567. /*
  36568. // debug code
  36569. var matrixIsSame = matrixEquals4( m, m2 );
  36570. if ( ! matrixIsSame ) {
  36571. console.log( t, s, r );
  36572. console.log( t2, s2, r2 );
  36573. console.log( m, m2 );
  36574. }
  36575. */
  36576. assert.ok( matrixEquals4$1( m, m2 ), "Passed!" );
  36577. }
  36578. }
  36579. }
  36580. } );
  36581. QUnit.test( "makePerspective", ( assert ) => {
  36582. assert.ok( false, "everything's gonna be alright" );
  36583. } );
  36584. QUnit.test( "makeOrthographic", ( assert ) => {
  36585. var a = new Matrix4().makeOrthographic( - 1, 1, - 1, 1, 1, 100 );
  36586. var expected = new Matrix4().set(
  36587. 1, 0, 0, 0,
  36588. 0, - 1, 0, 0,
  36589. 0, 0, - 2 / 99, - 101 / 99,
  36590. 0, 0, 0, 1
  36591. );
  36592. assert.ok( matrixEquals4$1( a, expected ), "Check result" );
  36593. } );
  36594. QUnit.test( "equals", ( assert ) => {
  36595. var a = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  36596. var b = new Matrix4().set( 0, - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  36597. assert.notOk( a.equals( b ), "Check that a does not equal b" );
  36598. assert.notOk( b.equals( a ), "Check that b does not equal a" );
  36599. a.copy( b );
  36600. assert.ok( a.equals( b ), "Check that a equals b after copy()" );
  36601. assert.ok( b.equals( a ), "Check that b equals a after copy()" );
  36602. } );
  36603. QUnit.test( "fromArray", ( assert ) => {
  36604. assert.ok( false, "everything's gonna be alright" );
  36605. } );
  36606. QUnit.test( "toArray", ( assert ) => {
  36607. var a = new Matrix4().set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  36608. var noOffset = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ];
  36609. var withOffset = [ undefined, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ];
  36610. var array = a.toArray();
  36611. assert.deepEqual( array, noOffset, "No array, no offset" );
  36612. var array = [];
  36613. a.toArray( array );
  36614. assert.deepEqual( array, noOffset, "With array, no offset" );
  36615. var array = [];
  36616. a.toArray( array, 1 );
  36617. assert.deepEqual( array, withOffset, "With array, with offset" );
  36618. } );
  36619. } );
  36620. } );
  36621. /**
  36622. * @author bhouston / http://exocortex.com
  36623. * @author TristanVALCKE / https://github.com/Itee
  36624. */
  36625. /* global QUnit */
  36626. function comparePlane( a, b, threshold ) {
  36627. threshold = threshold || 0.0001;
  36628. return ( a.normal.distanceTo( b.normal ) < threshold &&
  36629. Math.abs( a.constant - b.constant ) < threshold );
  36630. }
  36631. QUnit.module( 'Maths', () => {
  36632. QUnit.module.todo( 'Plane', () => {
  36633. // INSTANCING
  36634. QUnit.test( "Instancing", ( assert ) => {
  36635. var a = new Plane();
  36636. assert.ok( a.normal.x == 1, "Passed!" );
  36637. assert.ok( a.normal.y == 0, "Passed!" );
  36638. assert.ok( a.normal.z == 0, "Passed!" );
  36639. assert.ok( a.constant == 0, "Passed!" );
  36640. var a = new Plane( one3.clone(), 0 );
  36641. assert.ok( a.normal.x == 1, "Passed!" );
  36642. assert.ok( a.normal.y == 1, "Passed!" );
  36643. assert.ok( a.normal.z == 1, "Passed!" );
  36644. assert.ok( a.constant == 0, "Passed!" );
  36645. var a = new Plane( one3.clone(), 1 );
  36646. assert.ok( a.normal.x == 1, "Passed!" );
  36647. assert.ok( a.normal.y == 1, "Passed!" );
  36648. assert.ok( a.normal.z == 1, "Passed!" );
  36649. assert.ok( a.constant == 1, "Passed!" );
  36650. } );
  36651. // PUBLIC STUFF
  36652. QUnit.test( "isPlane", ( assert ) => {
  36653. assert.ok( false, "everything's gonna be alright" );
  36654. } );
  36655. QUnit.test( "set", ( assert ) => {
  36656. var a = new Plane();
  36657. assert.ok( a.normal.x == 1, "Passed!" );
  36658. assert.ok( a.normal.y == 0, "Passed!" );
  36659. assert.ok( a.normal.z == 0, "Passed!" );
  36660. assert.ok( a.constant == 0, "Passed!" );
  36661. var b = a.clone().set( new Vector3( x, y, z ), w );
  36662. assert.ok( b.normal.x == x, "Passed!" );
  36663. assert.ok( b.normal.y == y, "Passed!" );
  36664. assert.ok( b.normal.z == z, "Passed!" );
  36665. assert.ok( b.constant == w, "Passed!" );
  36666. } );
  36667. QUnit.test( "setComponents", ( assert ) => {
  36668. var a = new Plane();
  36669. assert.ok( a.normal.x == 1, "Passed!" );
  36670. assert.ok( a.normal.y == 0, "Passed!" );
  36671. assert.ok( a.normal.z == 0, "Passed!" );
  36672. assert.ok( a.constant == 0, "Passed!" );
  36673. var b = a.clone().setComponents( x, y, z, w );
  36674. assert.ok( b.normal.x == x, "Passed!" );
  36675. assert.ok( b.normal.y == y, "Passed!" );
  36676. assert.ok( b.normal.z == z, "Passed!" );
  36677. assert.ok( b.constant == w, "Passed!" );
  36678. } );
  36679. QUnit.test( "setFromNormalAndCoplanarPoint", ( assert ) => {
  36680. var normal = one3.clone().normalize();
  36681. var a = new Plane().setFromNormalAndCoplanarPoint( normal, zero3 );
  36682. assert.ok( a.normal.equals( normal ), "Passed!" );
  36683. assert.ok( a.constant == 0, "Passed!" );
  36684. } );
  36685. QUnit.test( "setFromCoplanarPoints", ( assert ) => {
  36686. var a = new Plane();
  36687. var v1 = new Vector3( 2.0, 0.5, 0.25 );
  36688. var v2 = new Vector3( 2.0, - 0.5, 1.25 );
  36689. var v3 = new Vector3( 2.0, - 3.5, 2.2 );
  36690. var normal = new Vector3( 1, 0, 0 );
  36691. var constant = - 2;
  36692. a.setFromCoplanarPoints( v1, v2, v3 );
  36693. assert.ok( a.normal.equals( normal ), "Check normal" );
  36694. assert.strictEqual( a.constant, constant, "Check constant" );
  36695. } );
  36696. QUnit.test( "clone", ( assert ) => {
  36697. assert.ok( false, "everything's gonna be alright" );
  36698. } );
  36699. QUnit.test( "copy", ( assert ) => {
  36700. var a = new Plane( new Vector3( x, y, z ), w );
  36701. var b = new Plane().copy( a );
  36702. assert.ok( b.normal.x == x, "Passed!" );
  36703. assert.ok( b.normal.y == y, "Passed!" );
  36704. assert.ok( b.normal.z == z, "Passed!" );
  36705. assert.ok( b.constant == w, "Passed!" );
  36706. // ensure that it is a true copy
  36707. a.normal.x = 0;
  36708. a.normal.y = - 1;
  36709. a.normal.z = - 2;
  36710. a.constant = - 3;
  36711. assert.ok( b.normal.x == x, "Passed!" );
  36712. assert.ok( b.normal.y == y, "Passed!" );
  36713. assert.ok( b.normal.z == z, "Passed!" );
  36714. assert.ok( b.constant == w, "Passed!" );
  36715. } );
  36716. QUnit.test( "normalize", ( assert ) => {
  36717. var a = new Plane( new Vector3( 2, 0, 0 ), 2 );
  36718. a.normalize();
  36719. assert.ok( a.normal.length() == 1, "Passed!" );
  36720. assert.ok( a.normal.equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  36721. assert.ok( a.constant == 1, "Passed!" );
  36722. } );
  36723. QUnit.test( "negate/distanceToPoint", ( assert ) => {
  36724. var a = new Plane( new Vector3( 2, 0, 0 ), - 2 );
  36725. a.normalize();
  36726. assert.ok( a.distanceToPoint( new Vector3( 4, 0, 0 ) ) === 3, "Passed!" );
  36727. assert.ok( a.distanceToPoint( new Vector3( 1, 0, 0 ) ) === 0, "Passed!" );
  36728. a.negate();
  36729. assert.ok( a.distanceToPoint( new Vector3( 4, 0, 0 ) ) === - 3, "Passed!" );
  36730. assert.ok( a.distanceToPoint( new Vector3( 1, 0, 0 ) ) === 0, "Passed!" );
  36731. } );
  36732. QUnit.test( "distanceToPoint", ( assert ) => {
  36733. var a = new Plane( new Vector3( 2, 0, 0 ), - 2 );
  36734. a.normalize();
  36735. assert.ok( a.distanceToPoint( a.projectPoint( zero3.clone() ) ) === 0, "Passed!" );
  36736. assert.ok( a.distanceToPoint( new Vector3( 4, 0, 0 ) ) === 3, "Passed!" );
  36737. } );
  36738. QUnit.test( "distanceToSphere", ( assert ) => {
  36739. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  36740. var b = new Sphere( new Vector3( 2, 0, 0 ), 1 );
  36741. assert.ok( a.distanceToSphere( b ) === 1, "Passed!" );
  36742. a.set( new Vector3( 1, 0, 0 ), 2 );
  36743. assert.ok( a.distanceToSphere( b ) === 3, "Passed!" );
  36744. a.set( new Vector3( 1, 0, 0 ), - 2 );
  36745. assert.ok( a.distanceToSphere( b ) === - 1, "Passed!" );
  36746. } );
  36747. QUnit.test( "projectPoint", ( assert ) => {
  36748. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  36749. assert.ok( a.projectPoint( new Vector3( 10, 0, 0 ) ).equals( zero3 ), "Passed!" );
  36750. assert.ok( a.projectPoint( new Vector3( - 10, 0, 0 ) ).equals( zero3 ), "Passed!" );
  36751. var a = new Plane( new Vector3( 0, 1, 0 ), - 1 );
  36752. assert.ok( a.projectPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  36753. assert.ok( a.projectPoint( new Vector3( 0, 1, 0 ) ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  36754. } );
  36755. QUnit.test( "isInterestionLine/intersectLine", ( assert ) => {
  36756. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  36757. var l1 = new Line3( new Vector3( - 10, 0, 0 ), new Vector3( 10, 0, 0 ) );
  36758. assert.ok( a.intersectsLine( l1 ), "Passed!" );
  36759. assert.ok( a.intersectLine( l1 ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  36760. var a = new Plane( new Vector3( 1, 0, 0 ), - 3 );
  36761. assert.ok( a.intersectsLine( l1 ), "Passed!" );
  36762. assert.ok( a.intersectLine( l1 ).equals( new Vector3( 3, 0, 0 ) ), "Passed!" );
  36763. var a = new Plane( new Vector3( 1, 0, 0 ), - 11 );
  36764. assert.ok( ! a.intersectsLine( l1 ), "Passed!" );
  36765. assert.ok( a.intersectLine( l1 ) === undefined, "Passed!" );
  36766. var a = new Plane( new Vector3( 1, 0, 0 ), 11 );
  36767. assert.ok( ! a.intersectsLine( l1 ), "Passed!" );
  36768. assert.ok( a.intersectLine( l1 ) === undefined, "Passed!" );
  36769. } );
  36770. QUnit.test( "intersectsBox", ( assert ) => {
  36771. assert.ok( false, "everything's gonna be alright" );
  36772. } );
  36773. QUnit.test( "intersectsSphere", ( assert ) => {
  36774. assert.ok( false, "everything's gonna be alright" );
  36775. } );
  36776. QUnit.test( "coplanarPoint", ( assert ) => {
  36777. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  36778. assert.ok( a.distanceToPoint( a.coplanarPoint() ) === 0, "Passed!" );
  36779. var a = new Plane( new Vector3( 0, 1, 0 ), - 1 );
  36780. assert.ok( a.distanceToPoint( a.coplanarPoint() ) === 0, "Passed!" );
  36781. } );
  36782. QUnit.test( "applyMatrix4/translate", ( assert ) => {
  36783. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  36784. var m = new Matrix4();
  36785. m.makeRotationZ( Math.PI * 0.5 );
  36786. assert.ok( comparePlane( a.clone().applyMatrix4( m ), new Plane( new Vector3( 0, 1, 0 ), 0 ) ), "Passed!" );
  36787. var a = new Plane( new Vector3( 0, 1, 0 ), - 1 );
  36788. assert.ok( comparePlane( a.clone().applyMatrix4( m ), new Plane( new Vector3( - 1, 0, 0 ), - 1 ) ), "Passed!" );
  36789. m.makeTranslation( 1, 1, 1 );
  36790. assert.ok( comparePlane( a.clone().applyMatrix4( m ), a.clone().translate( new Vector3( 1, 1, 1 ) ) ), "Passed!" );
  36791. } );
  36792. QUnit.test( "equals", ( assert ) => {
  36793. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  36794. var b = new Plane( new Vector3( 1, 0, 0 ), 1 );
  36795. var c = new Plane( new Vector3( 0, 1, 0 ), 0 );
  36796. assert.ok( a.normal.equals( b.normal ), "Normals: equal" );
  36797. assert.notOk( a.normal.equals( c.normal ), "Normals: not equal" );
  36798. assert.notStrictEqual( a.constant, b.constant, "Constants: not equal" );
  36799. assert.strictEqual( a.constant, c.constant, "Constants: equal" );
  36800. assert.notOk( a.equals( b ), "Planes: not equal" );
  36801. assert.notOk( a.equals( c ), "Planes: not equal" );
  36802. a.copy( b );
  36803. assert.ok( a.normal.equals( b.normal ), "Normals after copy(): equal" );
  36804. assert.strictEqual( a.constant, b.constant, "Constants after copy(): equal" );
  36805. assert.ok( a.equals( b ), "Planes after copy(): equal" );
  36806. } );
  36807. } );
  36808. } );
  36809. QUnit.module( "Plane" );
  36810. /**
  36811. * @author bhouston / http://exocortex.com
  36812. * @author tschw
  36813. * @author TristanVALCKE / https://github.com/Itee
  36814. */
  36815. /* global QUnit */
  36816. const orders = [ 'XYZ', 'YXZ', 'ZXY', 'ZYX', 'YZX', 'XZY' ];
  36817. const eulerAngles = new Euler( 0.1, - 0.3, 0.25 );
  36818. function qSub( a, b ) {
  36819. var result = new Quaternion();
  36820. result.copy( a );
  36821. result.x -= b.x;
  36822. result.y -= b.y;
  36823. result.z -= b.z;
  36824. result.w -= b.w;
  36825. return result;
  36826. }
  36827. function doSlerpObject( aArr, bArr, t ) {
  36828. var a = new Quaternion().fromArray( aArr ),
  36829. b = new Quaternion().fromArray( bArr ),
  36830. c = new Quaternion().fromArray( aArr );
  36831. c.slerp( b, t );
  36832. return {
  36833. equals: function ( x$$1, y$$1, z$$1, w$$1, maxError ) {
  36834. if ( maxError === undefined ) maxError = Number.EPSILON;
  36835. return Math.abs( x$$1 - c.x ) <= maxError &&
  36836. Math.abs( y$$1 - c.y ) <= maxError &&
  36837. Math.abs( z$$1 - c.z ) <= maxError &&
  36838. Math.abs( w$$1 - c.w ) <= maxError;
  36839. },
  36840. length: c.length(),
  36841. dotA: c.dot( a ),
  36842. dotB: c.dot( b )
  36843. };
  36844. }
  36845. function doSlerpArray( a, b, t ) {
  36846. var result = [ 0, 0, 0, 0 ];
  36847. Quaternion.slerpFlat( result, 0, a, 0, b, 0, t );
  36848. function arrDot( a, b ) {
  36849. return a[ 0 ] * b[ 0 ] + a[ 1 ] * b[ 1 ] +
  36850. a[ 2 ] * b[ 2 ] + a[ 3 ] * b[ 3 ];
  36851. }
  36852. return {
  36853. equals: function ( x$$1, y$$1, z$$1, w$$1, maxError ) {
  36854. if ( maxError === undefined ) maxError = Number.EPSILON;
  36855. return Math.abs( x$$1 - result[ 0 ] ) <= maxError &&
  36856. Math.abs( y$$1 - result[ 1 ] ) <= maxError &&
  36857. Math.abs( z$$1 - result[ 2 ] ) <= maxError &&
  36858. Math.abs( w$$1 - result[ 3 ] ) <= maxError;
  36859. },
  36860. length: Math.sqrt( arrDot( result, result ) ),
  36861. dotA: arrDot( result, a ),
  36862. dotB: arrDot( result, b )
  36863. };
  36864. }
  36865. function slerpTestSkeleton( doSlerp, maxError, assert ) {
  36866. var a, b, result;
  36867. a = [
  36868. 0.6753410084407496,
  36869. 0.4087830051091744,
  36870. 0.32856700410659473,
  36871. 0.5185120064806223
  36872. ];
  36873. b = [
  36874. 0.6602792107657797,
  36875. 0.43647413932562285,
  36876. 0.35119011210236006,
  36877. 0.5001871596632682
  36878. ];
  36879. var maxNormError = 0;
  36880. function isNormal( result ) {
  36881. var normError = Math.abs( 1 - result.length );
  36882. maxNormError = Math.max( maxNormError, normError );
  36883. return normError <= maxError;
  36884. }
  36885. result = doSlerp( a, b, 0 );
  36886. assert.ok( result.equals(
  36887. a[ 0 ], a[ 1 ], a[ 2 ], a[ 3 ], 0 ), "Exactly A @ t = 0" );
  36888. result = doSlerp( a, b, 1 );
  36889. assert.ok( result.equals(
  36890. b[ 0 ], b[ 1 ], b[ 2 ], b[ 3 ], 0 ), "Exactly B @ t = 1" );
  36891. result = doSlerp( a, b, 0.5 );
  36892. assert.ok( Math.abs( result.dotA - result.dotB ) <= Number.EPSILON, "Symmetry at 0.5" );
  36893. assert.ok( isNormal( result ), "Approximately normal (at 0.5)" );
  36894. result = doSlerp( a, b, 0.25 );
  36895. assert.ok( result.dotA > result.dotB, "Interpolating at 0.25" );
  36896. assert.ok( isNormal( result ), "Approximately normal (at 0.25)" );
  36897. result = doSlerp( a, b, 0.75 );
  36898. assert.ok( result.dotA < result.dotB, "Interpolating at 0.75" );
  36899. assert.ok( isNormal( result ), "Approximately normal (at 0.75)" );
  36900. var D = Math.SQRT1_2;
  36901. result = doSlerp( [ 1, 0, 0, 0 ], [ 0, 0, 1, 0 ], 0.5 );
  36902. assert.ok( result.equals( D, 0, D, 0 ), "X/Z diagonal from axes" );
  36903. assert.ok( isNormal( result ), "Approximately normal (X/Z diagonal)" );
  36904. result = doSlerp( [ 0, D, 0, D ], [ 0, - D, 0, D ], 0.5 );
  36905. assert.ok( result.equals( 0, 0, 0, 1 ), "W-Unit from diagonals" );
  36906. assert.ok( isNormal( result ), "Approximately normal (W-Unit)" );
  36907. }
  36908. QUnit.module( 'Maths', () => {
  36909. QUnit.module.todo( 'Quaternion', () => {
  36910. // INSTANCING
  36911. QUnit.test( "Instancing", ( assert ) => {
  36912. var a = new Quaternion();
  36913. assert.ok( a.x == 0, "Passed!" );
  36914. assert.ok( a.y == 0, "Passed!" );
  36915. assert.ok( a.z == 0, "Passed!" );
  36916. assert.ok( a.w == 1, "Passed!" );
  36917. var a = new Quaternion( x, y, z, w );
  36918. assert.ok( a.x === x, "Passed!" );
  36919. assert.ok( a.y === y, "Passed!" );
  36920. assert.ok( a.z === z, "Passed!" );
  36921. assert.ok( a.w === w, "Passed!" );
  36922. } );
  36923. // STATIC STUFF
  36924. QUnit.test( "slerp", ( assert ) => {
  36925. slerpTestSkeleton( doSlerpObject, Number.EPSILON, assert );
  36926. } );
  36927. QUnit.test( "slerpFlat", ( assert ) => {
  36928. slerpTestSkeleton( doSlerpArray, Number.EPSILON, assert );
  36929. } );
  36930. // PROPERTIES
  36931. QUnit.test( "properties", ( assert ) => {
  36932. assert.expect( 8 );
  36933. var a = new Quaternion();
  36934. a.onChange( function () {
  36935. assert.ok( true, "onChange called" );
  36936. } );
  36937. a.x = x;
  36938. a.y = y;
  36939. a.z = z;
  36940. a.w = w;
  36941. assert.strictEqual( a.x, x, "Check x" );
  36942. assert.strictEqual( a.y, y, "Check y" );
  36943. assert.strictEqual( a.z, z, "Check z" );
  36944. assert.strictEqual( a.w, w, "Check w" );
  36945. } );
  36946. QUnit.test( "x", ( assert ) => {
  36947. assert.ok( false, "everything's gonna be alright" );
  36948. } );
  36949. QUnit.test( "y", ( assert ) => {
  36950. assert.ok( false, "everything's gonna be alright" );
  36951. } );
  36952. QUnit.test( "z", ( assert ) => {
  36953. assert.ok( false, "everything's gonna be alright" );
  36954. } );
  36955. QUnit.test( "w", ( assert ) => {
  36956. assert.ok( false, "everything's gonna be alright" );
  36957. } );
  36958. // PUBLIC STUFF
  36959. QUnit.test( "set", ( assert ) => {
  36960. var a = new Quaternion();
  36961. assert.ok( a.x == 0, "Passed!" );
  36962. assert.ok( a.y == 0, "Passed!" );
  36963. assert.ok( a.z == 0, "Passed!" );
  36964. assert.ok( a.w == 1, "Passed!" );
  36965. a.set( x, y, z, w );
  36966. assert.ok( a.x == x, "Passed!" );
  36967. assert.ok( a.y == y, "Passed!" );
  36968. assert.ok( a.z === z, "Passed!" );
  36969. assert.ok( a.w === w, "Passed!" );
  36970. } );
  36971. QUnit.test( "clone", ( assert ) => {
  36972. assert.ok( false, "everything's gonna be alright" );
  36973. } );
  36974. QUnit.test( "copy", ( assert ) => {
  36975. var a = new Quaternion( x, y, z, w );
  36976. var b = new Quaternion().copy( a );
  36977. assert.ok( b.x == x, "Passed!" );
  36978. assert.ok( b.y == y, "Passed!" );
  36979. assert.ok( b.z == z, "Passed!" );
  36980. assert.ok( b.w == w, "Passed!" );
  36981. // ensure that it is a true copy
  36982. a.x = 0;
  36983. a.y = - 1;
  36984. a.z = 0;
  36985. a.w = - 1;
  36986. assert.ok( b.x == x, "Passed!" );
  36987. assert.ok( b.y == y, "Passed!" );
  36988. } );
  36989. QUnit.test( "setFromEuler/setFromQuaternion", ( assert ) => {
  36990. var angles = [ new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ) ];
  36991. // ensure euler conversion to/from Quaternion matches.
  36992. for ( var i = 0; i < orders.length; i ++ ) {
  36993. for ( var j = 0; j < angles.length; j ++ ) {
  36994. var eulers2 = new Euler().setFromQuaternion( new Quaternion().setFromEuler( new Euler( angles[ j ].x, angles[ j ].y, angles[ j ].z, orders[ i ] ) ), orders[ i ] );
  36995. var newAngle = new Vector3( eulers2.x, eulers2.y, eulers2.z );
  36996. assert.ok( newAngle.distanceTo( angles[ j ] ) < 0.001, "Passed!" );
  36997. }
  36998. }
  36999. } );
  37000. QUnit.test( "setFromAxisAngle", ( assert ) => {
  37001. // TODO: find cases to validate.
  37002. // assert.ok( true, "Passed!" );
  37003. var zero = new Quaternion();
  37004. var a = new Quaternion().setFromAxisAngle( new Vector3( 1, 0, 0 ), 0 );
  37005. assert.ok( a.equals( zero ), "Passed!" );
  37006. a = new Quaternion().setFromAxisAngle( new Vector3( 0, 1, 0 ), 0 );
  37007. assert.ok( a.equals( zero ), "Passed!" );
  37008. a = new Quaternion().setFromAxisAngle( new Vector3( 0, 0, 1 ), 0 );
  37009. assert.ok( a.equals( zero ), "Passed!" );
  37010. var b1 = new Quaternion().setFromAxisAngle( new Vector3( 1, 0, 0 ), Math.PI );
  37011. assert.ok( ! a.equals( b1 ), "Passed!" );
  37012. var b2 = new Quaternion().setFromAxisAngle( new Vector3( 1, 0, 0 ), - Math.PI );
  37013. assert.ok( ! a.equals( b2 ), "Passed!" );
  37014. b1.multiply( b2 );
  37015. assert.ok( a.equals( b1 ), "Passed!" );
  37016. } );
  37017. QUnit.test( "setFromEuler/setFromRotationMatrix", ( assert ) => {
  37018. // ensure euler conversion for Quaternion matches that of Matrix4
  37019. for ( var i = 0; i < orders.length; i ++ ) {
  37020. var q = new Quaternion().setFromEuler( eulerAngles, orders[ i ] );
  37021. var m = new Matrix4().makeRotationFromEuler( eulerAngles, orders[ i ] );
  37022. var q2 = new Quaternion().setFromRotationMatrix( m );
  37023. assert.ok( qSub( q, q2 ).length() < 0.001, "Passed!" );
  37024. }
  37025. } );
  37026. QUnit.test( "setFromRotationMatrix", ( assert ) => {
  37027. // contrived examples purely to please the god of code coverage...
  37028. // match conditions in various 'else [if]' blocks
  37029. var a = new Quaternion();
  37030. var q = new Quaternion( - 9, - 2, 3, - 4 ).normalize();
  37031. var m = new Matrix4().makeRotationFromQuaternion( q );
  37032. var expected = new Vector4( 0.8581163303210332, 0.19069251784911848, - 0.2860387767736777, 0.38138503569823695 );
  37033. a.setFromRotationMatrix( m );
  37034. assert.ok( Math.abs( a.x - expected.x ) <= eps, "m11 > m22 && m11 > m33: check x" );
  37035. assert.ok( Math.abs( a.y - expected.y ) <= eps, "m11 > m22 && m11 > m33: check y" );
  37036. assert.ok( Math.abs( a.z - expected.z ) <= eps, "m11 > m22 && m11 > m33: check z" );
  37037. assert.ok( Math.abs( a.w - expected.w ) <= eps, "m11 > m22 && m11 > m33: check w" );
  37038. var q = new Quaternion( - 1, - 2, 1, - 1 ).normalize();
  37039. m.makeRotationFromQuaternion( q );
  37040. var expected = new Vector4( 0.37796447300922714, 0.7559289460184544, - 0.37796447300922714, 0.37796447300922714 );
  37041. a.setFromRotationMatrix( m );
  37042. assert.ok( Math.abs( a.x - expected.x ) <= eps, "m22 > m33: check x" );
  37043. assert.ok( Math.abs( a.y - expected.y ) <= eps, "m22 > m33: check y" );
  37044. assert.ok( Math.abs( a.z - expected.z ) <= eps, "m22 > m33: check z" );
  37045. assert.ok( Math.abs( a.w - expected.w ) <= eps, "m22 > m33: check w" );
  37046. } );
  37047. QUnit.test( "setFromUnitVectors", ( assert ) => {
  37048. var a = new Quaternion();
  37049. var b = new Vector3( 1, 0, 0 );
  37050. var c = new Vector3( 0, 1, 0 );
  37051. var expected = new Quaternion( 0, 0, Math.sqrt( 2 ) / 2, Math.sqrt( 2 ) / 2 );
  37052. a.setFromUnitVectors( b, c );
  37053. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  37054. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  37055. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  37056. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Check w" );
  37057. } );
  37058. QUnit.test( "inverse/conjugate", ( assert ) => {
  37059. var a = new Quaternion( x, y, z, w );
  37060. // TODO: add better validation here.
  37061. var b = a.clone().conjugate();
  37062. assert.ok( a.x == - b.x, "Passed!" );
  37063. assert.ok( a.y == - b.y, "Passed!" );
  37064. assert.ok( a.z == - b.z, "Passed!" );
  37065. assert.ok( a.w == b.w, "Passed!" );
  37066. } );
  37067. QUnit.test( "inverse", ( assert ) => {
  37068. assert.expect( 6 );
  37069. var a = new Quaternion( x, y, z, w );
  37070. var inverted = new Quaternion( - 0.2721655269759087, - 0.408248290463863, - 0.5443310539518174, 0.6804138174397717 );
  37071. a.onChange( function () {
  37072. assert.ok( true, "onChange called" );
  37073. } );
  37074. a.inverse();
  37075. assert.ok( Math.abs( a.x - inverted.x ) <= eps, "Check x" );
  37076. assert.ok( Math.abs( a.y - inverted.y ) <= eps, "Check y" );
  37077. assert.ok( Math.abs( a.z - inverted.z ) <= eps, "Check z" );
  37078. assert.ok( Math.abs( a.w - inverted.w ) <= eps, "Check w" );
  37079. } );
  37080. QUnit.test( "dot", ( assert ) => {
  37081. assert.ok( false, "everything's gonna be alright" );
  37082. } );
  37083. QUnit.test( "normalize/length/lengthSq", ( assert ) => {
  37084. var a = new Quaternion( x, y, z, w );
  37085. var b = new Quaternion( - x, - y, - z, - w );
  37086. assert.ok( a.length() != 1, "Passed!" );
  37087. assert.ok( a.lengthSq() != 1, "Passed!" );
  37088. a.normalize();
  37089. assert.ok( a.length() == 1, "Passed!" );
  37090. assert.ok( a.lengthSq() == 1, "Passed!" );
  37091. a.set( 0, 0, 0, 0 );
  37092. assert.ok( a.lengthSq() == 0, "Passed!" );
  37093. assert.ok( a.length() == 0, "Passed!" );
  37094. a.normalize();
  37095. assert.ok( a.lengthSq() == 1, "Passed!" );
  37096. assert.ok( a.length() == 1, "Passed!" );
  37097. } );
  37098. QUnit.test( "multiplyQuaternions/multiply", ( assert ) => {
  37099. var angles = [ new Euler( 1, 0, 0 ), new Euler( 0, 1, 0 ), new Euler( 0, 0, 1 ) ];
  37100. var q1 = new Quaternion().setFromEuler( angles[ 0 ], "XYZ" );
  37101. var q2 = new Quaternion().setFromEuler( angles[ 1 ], "XYZ" );
  37102. var q3 = new Quaternion().setFromEuler( angles[ 2 ], "XYZ" );
  37103. var q = new Quaternion().multiplyQuaternions( q1, q2 ).multiply( q3 );
  37104. var m1 = new Matrix4().makeRotationFromEuler( angles[ 0 ], "XYZ" );
  37105. var m2 = new Matrix4().makeRotationFromEuler( angles[ 1 ], "XYZ" );
  37106. var m3 = new Matrix4().makeRotationFromEuler( angles[ 2 ], "XYZ" );
  37107. var m = new Matrix4().multiplyMatrices( m1, m2 ).multiply( m3 );
  37108. var qFromM = new Quaternion().setFromRotationMatrix( m );
  37109. assert.ok( qSub( q, qFromM ).length() < 0.001, "Passed!" );
  37110. } );
  37111. QUnit.test( "premultiply", ( assert ) => {
  37112. var a = new Quaternion( x, y, z, w );
  37113. var b = new Quaternion( 2 * x, - y, - 2 * z, w );
  37114. var expected = new Quaternion( 42, - 32, - 2, 58 );
  37115. a.premultiply( b );
  37116. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  37117. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  37118. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  37119. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Check w" );
  37120. } );
  37121. QUnit.test( "slerp", ( assert ) => {
  37122. assert.ok( false, "everything's gonna be alright" );
  37123. } );
  37124. QUnit.test( "equals", ( assert ) => {
  37125. var a = new Quaternion( x, y, z, w );
  37126. var b = new Quaternion( - x, - y, - z, - w );
  37127. assert.ok( a.x != b.x, "Passed!" );
  37128. assert.ok( a.y != b.y, "Passed!" );
  37129. assert.ok( ! a.equals( b ), "Passed!" );
  37130. assert.ok( ! b.equals( a ), "Passed!" );
  37131. a.copy( b );
  37132. assert.ok( a.x == b.x, "Passed!" );
  37133. assert.ok( a.y == b.y, "Passed!" );
  37134. assert.ok( a.equals( b ), "Passed!" );
  37135. assert.ok( b.equals( a ), "Passed!" );
  37136. } );
  37137. QUnit.test( "fromArray", ( assert ) => {
  37138. assert.ok( false, "everything's gonna be alright" );
  37139. } );
  37140. QUnit.test( "toArray", ( assert ) => {
  37141. var a = new Quaternion( x, y, z, w );
  37142. var array = a.toArray();
  37143. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  37144. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  37145. assert.strictEqual( array[ 2 ], z, "No array, no offset: check z" );
  37146. assert.strictEqual( array[ 3 ], w, "No array, no offset: check w" );
  37147. var array = [];
  37148. a.toArray( array );
  37149. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  37150. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  37151. assert.strictEqual( array[ 2 ], z, "With array, no offset: check z" );
  37152. assert.strictEqual( array[ 3 ], w, "With array, no offset: check w" );
  37153. var array = [];
  37154. a.toArray( array, 1 );
  37155. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  37156. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  37157. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  37158. assert.strictEqual( array[ 3 ], z, "With array and offset: check z" );
  37159. assert.strictEqual( array[ 4 ], w, "With array and offset: check w" );
  37160. } );
  37161. QUnit.test( "onChange", ( assert ) => {
  37162. assert.ok( false, "everything's gonna be alright" );
  37163. } );
  37164. QUnit.test( "onChangeCallback", ( assert ) => {
  37165. assert.ok( false, "everything's gonna be alright" );
  37166. } );
  37167. // OTHERS
  37168. QUnit.test( "multiplyVector3", ( assert ) => {
  37169. var angles = [ new Euler( 1, 0, 0 ), new Euler( 0, 1, 0 ), new Euler( 0, 0, 1 ) ];
  37170. // ensure euler conversion for Quaternion matches that of Matrix4
  37171. for ( var i = 0; i < orders.length; i ++ ) {
  37172. for ( var j = 0; j < angles.length; j ++ ) {
  37173. var q = new Quaternion().setFromEuler( angles[ j ], orders[ i ] );
  37174. var m = new Matrix4().makeRotationFromEuler( angles[ j ], orders[ i ] );
  37175. var v0 = new Vector3( 1, 0, 0 );
  37176. var qv = v0.clone().applyQuaternion( q );
  37177. var mv = v0.clone().applyMatrix4( m );
  37178. assert.ok( qv.distanceTo( mv ) < 0.001, "Passed!" );
  37179. }
  37180. }
  37181. } );
  37182. } );
  37183. } );
  37184. QUnit.module( "Quaternion" );
  37185. /**
  37186. * @author bhouston / http://exocortex.com
  37187. * @author TristanVALCKE / https://github.com/Itee
  37188. */
  37189. /* global QUnit */
  37190. QUnit.module( 'Maths', () => {
  37191. QUnit.module.todo( 'Ray', () => {
  37192. // INSTANCING
  37193. QUnit.test( "Instancing", ( assert ) => {
  37194. var a = new Ray();
  37195. assert.ok( a.origin.equals( zero3 ), "Passed!" );
  37196. assert.ok( a.direction.equals( zero3 ), "Passed!" );
  37197. var a = new Ray( two3.clone(), one3.clone() );
  37198. assert.ok( a.origin.equals( two3 ), "Passed!" );
  37199. assert.ok( a.direction.equals( one3 ), "Passed!" );
  37200. } );
  37201. // PUBLIC STUFF
  37202. QUnit.test( "isRay", ( assert ) => {
  37203. assert.ok( false, "everything's gonna be alright" );
  37204. } );
  37205. QUnit.test( "set", ( assert ) => {
  37206. var a = new Ray();
  37207. a.set( one3, one3 );
  37208. assert.ok( a.origin.equals( one3 ), "Passed!" );
  37209. assert.ok( a.direction.equals( one3 ), "Passed!" );
  37210. } );
  37211. QUnit.test( "recast/clone", ( assert ) => {
  37212. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37213. assert.ok( a.recast( 0 ).equals( a ), "Passed!" );
  37214. var b = a.clone();
  37215. assert.ok( b.recast( - 1 ).equals( new Ray( new Vector3( 1, 1, 0 ), new Vector3( 0, 0, 1 ) ) ), "Passed!" );
  37216. var c = a.clone();
  37217. assert.ok( c.recast( 1 ).equals( new Ray( new Vector3( 1, 1, 2 ), new Vector3( 0, 0, 1 ) ) ), "Passed!" );
  37218. var d = a.clone();
  37219. var e = d.clone().recast( 1 );
  37220. assert.ok( d.equals( a ), "Passed!" );
  37221. assert.ok( ! e.equals( d ), "Passed!" );
  37222. assert.ok( e.equals( c ), "Passed!" );
  37223. } );
  37224. QUnit.test( "copy/equals", ( assert ) => {
  37225. var a = new Ray( zero3.clone(), one3.clone() );
  37226. var b = new Ray().copy( a );
  37227. assert.ok( b.origin.equals( zero3 ), "Passed!" );
  37228. assert.ok( b.direction.equals( one3 ), "Passed!" );
  37229. // ensure that it is a true copy
  37230. a.origin = zero3;
  37231. a.direction = one3;
  37232. assert.ok( b.origin.equals( zero3 ), "Passed!" );
  37233. assert.ok( b.direction.equals( one3 ), "Passed!" );
  37234. } );
  37235. QUnit.test( "at", ( assert ) => {
  37236. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37237. assert.ok( a.at( 0 ).equals( one3 ), "Passed!" );
  37238. assert.ok( a.at( - 1 ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
  37239. assert.ok( a.at( 1 ).equals( new Vector3( 1, 1, 2 ) ), "Passed!" );
  37240. } );
  37241. QUnit.test( "lookAt", ( assert ) => {
  37242. var a = new Ray( two3.clone(), one3.clone() );
  37243. var target = one3.clone();
  37244. var expected = target.sub( two3 ).normalize();
  37245. a.lookAt( target );
  37246. assert.ok( a.direction.equals( expected ), "Check if we're looking in the right direction" );
  37247. } );
  37248. QUnit.test( "closestPointToPoint", ( assert ) => {
  37249. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37250. // behind the ray
  37251. var b = a.closestPointToPoint( zero3 );
  37252. assert.ok( b.equals( one3 ), "Passed!" );
  37253. // front of the ray
  37254. var c = a.closestPointToPoint( new Vector3( 0, 0, 50 ) );
  37255. assert.ok( c.equals( new Vector3( 1, 1, 50 ) ), "Passed!" );
  37256. // exactly on the ray
  37257. var d = a.closestPointToPoint( one3 );
  37258. assert.ok( d.equals( one3 ), "Passed!" );
  37259. } );
  37260. QUnit.test( "distanceToPoint", ( assert ) => {
  37261. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37262. // behind the ray
  37263. var b = a.distanceToPoint( zero3 );
  37264. assert.ok( b === Math.sqrt( 3 ), "Passed!" );
  37265. // front of the ray
  37266. var c = a.distanceToPoint( new Vector3( 0, 0, 50 ) );
  37267. assert.ok( c === Math.sqrt( 2 ), "Passed!" );
  37268. // exactly on the ray
  37269. var d = a.distanceToPoint( one3 );
  37270. assert.ok( d === 0, "Passed!" );
  37271. } );
  37272. QUnit.test( "distanceSqToPoint", ( assert ) => {
  37273. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37274. // behind the ray
  37275. var b = a.distanceSqToPoint( zero3 );
  37276. assert.ok( b === 3, "Passed!" );
  37277. // front of the ray
  37278. var c = a.distanceSqToPoint( new Vector3( 0, 0, 50 ) );
  37279. assert.ok( c === 2, "Passed!" );
  37280. // exactly on the ray
  37281. var d = a.distanceSqToPoint( one3 );
  37282. assert.ok( d === 0, "Passed!" );
  37283. } );
  37284. QUnit.test( "distanceSqToSegment", ( assert ) => {
  37285. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37286. var ptOnLine = new Vector3();
  37287. var ptOnSegment = new Vector3();
  37288. //segment in front of the ray
  37289. var v0 = new Vector3( 3, 5, 50 );
  37290. var v1 = new Vector3( 50, 50, 50 ); // just a far away point
  37291. var distSqr = a.distanceSqToSegment( v0, v1, ptOnLine, ptOnSegment );
  37292. assert.ok( ptOnSegment.distanceTo( v0 ) < 0.0001, "Passed!" );
  37293. assert.ok( ptOnLine.distanceTo( new Vector3( 1, 1, 50 ) ) < 0.0001, "Passed!" );
  37294. // ((3-1) * (3-1) + (5-1) * (5-1) = 4 + 16 = 20
  37295. assert.ok( Math.abs( distSqr - 20 ) < 0.0001, "Passed!" );
  37296. //segment behind the ray
  37297. var v0 = new Vector3( - 50, - 50, - 50 ); // just a far away point
  37298. var v1 = new Vector3( - 3, - 5, - 4 );
  37299. var distSqr = a.distanceSqToSegment( v0, v1, ptOnLine, ptOnSegment );
  37300. assert.ok( ptOnSegment.distanceTo( v1 ) < 0.0001, "Passed!" );
  37301. assert.ok( ptOnLine.distanceTo( one3 ) < 0.0001, "Passed!" );
  37302. // ((-3-1) * (-3-1) + (-5-1) * (-5-1) + (-4-1) + (-4-1) = 16 + 36 + 25 = 77
  37303. assert.ok( Math.abs( distSqr - 77 ) < 0.0001, "Passed!" );
  37304. //exact intersection between the ray and the segment
  37305. var v0 = new Vector3( - 50, - 50, - 50 );
  37306. var v1 = new Vector3( 50, 50, 50 );
  37307. var distSqr = a.distanceSqToSegment( v0, v1, ptOnLine, ptOnSegment );
  37308. assert.ok( ptOnSegment.distanceTo( one3 ) < 0.0001, "Passed!" );
  37309. assert.ok( ptOnLine.distanceTo( one3 ) < 0.0001, "Passed!" );
  37310. assert.ok( distSqr < 0.0001, "Passed!" );
  37311. } );
  37312. QUnit.test( "intersectSphere", ( assert ) => {
  37313. var TOL = 0.0001;
  37314. // ray a0 origin located at ( 0, 0, 0 ) and points outward in negative-z direction
  37315. var a0 = new Ray( zero3.clone(), new Vector3( 0, 0, - 1 ) );
  37316. // ray a1 origin located at ( 1, 1, 1 ) and points left in negative-x direction
  37317. var a1 = new Ray( one3.clone(), new Vector3( - 1, 0, 0 ) );
  37318. // sphere (radius of 2) located behind ray a0, should result in null
  37319. var b = new Sphere( new Vector3( 0, 0, 3 ), 2 );
  37320. assert.ok( a0.intersectSphere( b ) === null, "Passed!" );
  37321. // sphere (radius of 2) located in front of, but too far right of ray a0, should result in null
  37322. var b = new Sphere( new Vector3( 3, 0, - 1 ), 2 );
  37323. assert.ok( a0.intersectSphere( b ) === null, "Passed!" );
  37324. // sphere (radius of 2) located below ray a1, should result in null
  37325. var b = new Sphere( new Vector3( 1, - 2, 1 ), 2 );
  37326. assert.ok( a1.intersectSphere( b ) === null, "Passed!" );
  37327. // sphere (radius of 1) located to the left of ray a1, should result in intersection at 0, 1, 1
  37328. var b = new Sphere( new Vector3( - 1, 1, 1 ), 1 );
  37329. assert.ok( a1.intersectSphere( b ).distanceTo( new Vector3( 0, 1, 1 ) ) < TOL, "Passed!" );
  37330. // sphere (radius of 1) located in front of ray a0, should result in intersection at 0, 0, -1
  37331. var b = new Sphere( new Vector3( 0, 0, - 2 ), 1 );
  37332. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
  37333. // 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
  37334. var b = new Sphere( new Vector3( 2, 0, - 1 ), 2 );
  37335. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
  37336. // same situation as above, but move the sphere a fraction more to the right, and ray a0 should now just miss
  37337. var b = new Sphere( new Vector3( 2.01, 0, - 1 ), 2 );
  37338. assert.ok( a0.intersectSphere( b ) === null, "Passed!" );
  37339. // following QUnit.tests are for situations where the ray origin is inside the sphere
  37340. // sphere (radius of 1) center located at ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 1,
  37341. // is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -1
  37342. // thus keeping the intersection point always in front of the ray.
  37343. var b = new Sphere( zero3.clone(), 1 );
  37344. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
  37345. // sphere (radius of 4) center located behind ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 5,
  37346. // is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -3
  37347. // thus keeping the intersection point always in front of the ray.
  37348. var b = new Sphere( new Vector3( 0, 0, 1 ), 4 );
  37349. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 3 ) ) < TOL, "Passed!" );
  37350. // 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,
  37351. // is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -5
  37352. // thus keeping the intersection point always in front of the ray.
  37353. var b = new Sphere( new Vector3( 0, 0, - 1 ), 4 );
  37354. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 5 ) ) < TOL, "Passed!" );
  37355. } );
  37356. QUnit.test( "intersectsSphere", ( assert ) => {
  37357. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37358. var b = new Sphere( zero3, 0.5 );
  37359. var c = new Sphere( zero3, 1.5 );
  37360. var d = new Sphere( one3, 0.1 );
  37361. var e = new Sphere( two3, 0.1 );
  37362. var f = new Sphere( two3, 1 );
  37363. assert.ok( ! a.intersectsSphere( b ), "Passed!" );
  37364. assert.ok( ! a.intersectsSphere( c ), "Passed!" );
  37365. assert.ok( a.intersectsSphere( d ), "Passed!" );
  37366. assert.ok( ! a.intersectsSphere( e ), "Passed!" );
  37367. assert.ok( ! a.intersectsSphere( f ), "Passed!" );
  37368. } );
  37369. QUnit.test( "distanceToPlane", ( assert ) => {
  37370. assert.ok( false, "everything's gonna be alright" );
  37371. } );
  37372. QUnit.test( "intersectPlane", ( assert ) => {
  37373. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37374. // parallel plane behind
  37375. var b = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), new Vector3( 1, 1, - 1 ) );
  37376. assert.ok( a.intersectPlane( b ) === null, "Passed!" );
  37377. // parallel plane coincident with origin
  37378. var c = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), new Vector3( 1, 1, 0 ) );
  37379. assert.ok( a.intersectPlane( c ) === null, "Passed!" );
  37380. // parallel plane infront
  37381. var d = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), new Vector3( 1, 1, 1 ) );
  37382. assert.ok( a.intersectPlane( d ).equals( a.origin ), "Passed!" );
  37383. // perpendical ray that overlaps exactly
  37384. var e = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), one3 );
  37385. assert.ok( a.intersectPlane( e ).equals( a.origin ), "Passed!" );
  37386. // perpendical ray that doesn't overlap
  37387. var f = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), zero3 );
  37388. assert.ok( a.intersectPlane( f ) === null, "Passed!" );
  37389. } );
  37390. QUnit.test( "intersectsPlane", ( assert ) => {
  37391. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37392. // parallel plane in front of the ray
  37393. var b = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), one3.clone().sub( new Vector3( 0, 0, - 1 ) ) );
  37394. assert.ok( a.intersectsPlane( b ), "Passed!" );
  37395. // parallel plane coincident with origin
  37396. var c = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), one3.clone().sub( new Vector3( 0, 0, 0 ) ) );
  37397. assert.ok( a.intersectsPlane( c ), "Passed!" );
  37398. // parallel plane behind the ray
  37399. var d = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), one3.clone().sub( new Vector3( 0, 0, 1 ) ) );
  37400. assert.ok( ! a.intersectsPlane( d ), "Passed!" );
  37401. // perpendical ray that overlaps exactly
  37402. var e = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), one3 );
  37403. assert.ok( a.intersectsPlane( e ), "Passed!" );
  37404. // perpendical ray that doesn't overlap
  37405. var f = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), zero3 );
  37406. assert.ok( ! a.intersectsPlane( f ), "Passed!" );
  37407. } );
  37408. QUnit.test( "intersectBox", ( assert ) => {
  37409. var TOL = 0.0001;
  37410. var box = new Box3( new Vector3( - 1, - 1, - 1 ), new Vector3( 1, 1, 1 ) );
  37411. var a = new Ray( new Vector3( - 2, 0, 0 ), new Vector3( 1, 0, 0 ) );
  37412. //ray should intersect box at -1,0,0
  37413. assert.ok( a.intersectsBox( box ) === true, "Passed!" );
  37414. assert.ok( a.intersectBox( box ).distanceTo( new Vector3( - 1, 0, 0 ) ) < TOL, "Passed!" );
  37415. var b = new Ray( new Vector3( - 2, 0, 0 ), new Vector3( - 1, 0, 0 ) );
  37416. //ray is point away from box, it should not intersect
  37417. assert.ok( b.intersectsBox( box ) === false, "Passed!" );
  37418. assert.ok( b.intersectBox( box ) === null, "Passed!" );
  37419. var c = new Ray( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ) );
  37420. // ray is inside box, should return exit point
  37421. assert.ok( c.intersectsBox( box ) === true, "Passed!" );
  37422. assert.ok( c.intersectBox( box ).distanceTo( new Vector3( 1, 0, 0 ) ) < TOL, "Passed!" );
  37423. var d = new Ray( new Vector3( 0, 2, 1 ), new Vector3( 0, - 1, - 1 ).normalize() );
  37424. //tilted ray should intersect box at 0,1,0
  37425. assert.ok( d.intersectsBox( box ) === true, "Passed!" );
  37426. assert.ok( d.intersectBox( box ).distanceTo( new Vector3( 0, 1, 0 ) ) < TOL, "Passed!" );
  37427. var e = new Ray( new Vector3( 1, - 2, 1 ), new Vector3( 0, 1, 0 ).normalize() );
  37428. //handle case where ray is coplanar with one of the boxes side - box in front of ray
  37429. assert.ok( e.intersectsBox( box ) === true, "Passed!" );
  37430. assert.ok( e.intersectBox( box ).distanceTo( new Vector3( 1, - 1, 1 ) ) < TOL, "Passed!" );
  37431. var f = new Ray( new Vector3( 1, - 2, 0 ), new Vector3( 0, - 1, 0 ).normalize() );
  37432. //handle case where ray is coplanar with one of the boxes side - box behind ray
  37433. assert.ok( f.intersectsBox( box ) === false, "Passed!" );
  37434. assert.ok( f.intersectBox( box ) == null, "Passed!" );
  37435. } );
  37436. QUnit.test( "intersectsBox", ( assert ) => {
  37437. assert.ok( false, "everything's gonna be alright" );
  37438. } );
  37439. QUnit.test( "intersectTriangle", ( assert ) => {
  37440. var ray = new Ray();
  37441. var a = new Vector3( 1, 1, 0 );
  37442. var b = new Vector3( 0, 1, 1 );
  37443. var c = new Vector3( 1, 0, 1 );
  37444. var intersect;
  37445. // DdN == 0
  37446. ray.set( ray.origin, zero3.clone() );
  37447. intersect = ray.intersectTriangle( a, b, c, false );
  37448. assert.strictEqual( intersect, null, "No intersection if direction == zero" );
  37449. // DdN > 0, backfaceCulling = true
  37450. ray.set( ray.origin, one3.clone() );
  37451. intersect = ray.intersectTriangle( a, b, c, true );
  37452. assert.strictEqual( intersect, null, "No intersection with backside faces if backfaceCulling is true" );
  37453. // DdN > 0
  37454. ray.set( ray.origin, one3.clone() );
  37455. intersect = ray.intersectTriangle( a, b, c, false );
  37456. assert.ok( Math.abs( intersect.x - 2 / 3 ) <= eps, "Successful intersection: check x" );
  37457. assert.ok( Math.abs( intersect.y - 2 / 3 ) <= eps, "Successful intersection: check y" );
  37458. assert.ok( Math.abs( intersect.z - 2 / 3 ) <= eps, "Successful intersection: check z" );
  37459. // DdN > 0, DdQxE2 < 0
  37460. b.multiplyScalar( - 1 );
  37461. intersect = ray.intersectTriangle( a, b, c, false );
  37462. assert.strictEqual( intersect, null, "No intersection" );
  37463. // DdN > 0, DdE1xQ < 0
  37464. a.multiplyScalar( - 1 );
  37465. intersect = ray.intersectTriangle( a, b, c, false );
  37466. assert.strictEqual( intersect, null, "No intersection" );
  37467. // DdN > 0, DdQxE2 + DdE1xQ > DdN
  37468. b.multiplyScalar( - 1 );
  37469. intersect = ray.intersectTriangle( a, b, c, false );
  37470. assert.strictEqual( intersect, null, "No intersection" );
  37471. // DdN < 0, QdN < 0
  37472. a.multiplyScalar( - 1 );
  37473. b.multiplyScalar( - 1 );
  37474. ray.direction.multiplyScalar( - 1 );
  37475. intersect = ray.intersectTriangle( a, b, c, false );
  37476. assert.strictEqual( intersect, null, "No intersection when looking in the wrong direction" );
  37477. } );
  37478. QUnit.test( "applyMatrix4", ( assert ) => {
  37479. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37480. var m = new Matrix4();
  37481. assert.ok( a.clone().applyMatrix4( m ).equals( a ), "Passed!" );
  37482. var a = new Ray( zero3.clone(), new Vector3( 0, 0, 1 ) );
  37483. m.makeRotationZ( Math.PI );
  37484. assert.ok( a.clone().applyMatrix4( m ).equals( a ), "Passed!" );
  37485. m.makeRotationX( Math.PI );
  37486. var b = a.clone();
  37487. b.direction.negate();
  37488. var a2 = a.clone().applyMatrix4( m );
  37489. assert.ok( a2.origin.distanceTo( b.origin ) < 0.0001, "Passed!" );
  37490. assert.ok( a2.direction.distanceTo( b.direction ) < 0.0001, "Passed!" );
  37491. a.origin = new Vector3( 0, 0, 1 );
  37492. b.origin = new Vector3( 0, 0, - 1 );
  37493. var a2 = a.clone().applyMatrix4( m );
  37494. assert.ok( a2.origin.distanceTo( b.origin ) < 0.0001, "Passed!" );
  37495. assert.ok( a2.direction.distanceTo( b.direction ) < 0.0001, "Passed!" );
  37496. } );
  37497. QUnit.test( "equals", ( assert ) => {
  37498. assert.ok( false, "everything's gonna be alright" );
  37499. } );
  37500. } );
  37501. } );
  37502. /**
  37503. * @author bhouston / http://exocortex.com
  37504. * @author TristanVALCKE / https://github.com/Itee
  37505. */
  37506. /* global QUnit */
  37507. QUnit.module( 'Maths', () => {
  37508. QUnit.module.todo( 'Sphere', () => {
  37509. // INSTANCING
  37510. QUnit.test( "Instancing", ( assert ) => {
  37511. var a = new Sphere();
  37512. assert.ok( a.center.equals( zero3 ), "Passed!" );
  37513. assert.ok( a.radius == 0, "Passed!" );
  37514. var a = new Sphere( one3.clone(), 1 );
  37515. assert.ok( a.center.equals( one3 ), "Passed!" );
  37516. assert.ok( a.radius == 1, "Passed!" );
  37517. } );
  37518. // PUBLIC STUFF
  37519. QUnit.test( "isSphere", ( assert ) => {
  37520. assert.ok( false, "everything's gonna be alright" );
  37521. } );
  37522. QUnit.test( "set", ( assert ) => {
  37523. var a = new Sphere();
  37524. assert.ok( a.center.equals( zero3 ), "Passed!" );
  37525. assert.ok( a.radius == 0, "Passed!" );
  37526. a.set( one3, 1 );
  37527. assert.ok( a.center.equals( one3 ), "Passed!" );
  37528. assert.ok( a.radius == 1, "Passed!" );
  37529. } );
  37530. QUnit.test( "setFromPoints", ( assert ) => {
  37531. var a = new Sphere();
  37532. var expectedCenter = new Vector3( 0.9330126941204071, 0, 0 );
  37533. var expectedRadius = 1.3676668773461689;
  37534. var optionalCenter = new Vector3( 1, 1, 1 );
  37535. var points = [
  37536. new Vector3( 1, 1, 0 ), new Vector3( 1, 1, 0 ),
  37537. new Vector3( 1, 1, 0 ), new Vector3( 1, 1, 0 ),
  37538. new Vector3( 1, 1, 0 ), new Vector3( 0.8660253882408142, 0.5, 0 ),
  37539. new Vector3( - 0, 0.5, 0.8660253882408142 ), new Vector3( 1.8660253882408142, 0.5, 0 ),
  37540. new Vector3( 0, 0.5, - 0.8660253882408142 ), new Vector3( 0.8660253882408142, 0.5, - 0 ),
  37541. new Vector3( 0.8660253882408142, - 0.5, 0 ), new Vector3( - 0, - 0.5, 0.8660253882408142 ),
  37542. new Vector3( 1.8660253882408142, - 0.5, 0 ), new Vector3( 0, - 0.5, - 0.8660253882408142 ),
  37543. new Vector3( 0.8660253882408142, - 0.5, - 0 ), new Vector3( - 0, - 1, 0 ),
  37544. new Vector3( - 0, - 1, 0 ), new Vector3( 0, - 1, 0 ),
  37545. new Vector3( 0, - 1, - 0 ), new Vector3( - 0, - 1, - 0 ),
  37546. ];
  37547. a.setFromPoints( points );
  37548. assert.ok( Math.abs( a.center.x - expectedCenter.x ) <= eps, "Default center: check center.x" );
  37549. assert.ok( Math.abs( a.center.y - expectedCenter.y ) <= eps, "Default center: check center.y" );
  37550. assert.ok( Math.abs( a.center.z - expectedCenter.z ) <= eps, "Default center: check center.z" );
  37551. assert.ok( Math.abs( a.radius - expectedRadius ) <= eps, "Default center: check radius" );
  37552. var expectedRadius = 2.5946195770400102;
  37553. a.setFromPoints( points, optionalCenter );
  37554. assert.ok( Math.abs( a.center.x - optionalCenter.x ) <= eps, "Optional center: check center.x" );
  37555. assert.ok( Math.abs( a.center.y - optionalCenter.y ) <= eps, "Optional center: check center.y" );
  37556. assert.ok( Math.abs( a.center.z - optionalCenter.z ) <= eps, "Optional center: check center.z" );
  37557. assert.ok( Math.abs( a.radius - expectedRadius ) <= eps, "Optional center: check radius" );
  37558. } );
  37559. QUnit.test( "clone", ( assert ) => {
  37560. assert.ok( false, "everything's gonna be alright" );
  37561. } );
  37562. QUnit.test( "copy", ( assert ) => {
  37563. var a = new Sphere( one3.clone(), 1 );
  37564. var b = new Sphere().copy( a );
  37565. assert.ok( b.center.equals( one3 ), "Passed!" );
  37566. assert.ok( b.radius == 1, "Passed!" );
  37567. // ensure that it is a true copy
  37568. a.center = zero3;
  37569. a.radius = 0;
  37570. assert.ok( b.center.equals( one3 ), "Passed!" );
  37571. assert.ok( b.radius == 1, "Passed!" );
  37572. } );
  37573. QUnit.test( "empty", ( assert ) => {
  37574. var a = new Sphere();
  37575. assert.ok( a.empty(), "Passed!" );
  37576. a.set( one3, 1 );
  37577. assert.ok( ! a.empty(), "Passed!" );
  37578. } );
  37579. QUnit.test( "containsPoint", ( assert ) => {
  37580. var a = new Sphere( one3.clone(), 1 );
  37581. assert.ok( ! a.containsPoint( zero3 ), "Passed!" );
  37582. assert.ok( a.containsPoint( one3 ), "Passed!" );
  37583. } );
  37584. QUnit.test( "distanceToPoint", ( assert ) => {
  37585. var a = new Sphere( one3.clone(), 1 );
  37586. assert.ok( ( a.distanceToPoint( zero3 ) - 0.7320 ) < 0.001, "Passed!" );
  37587. assert.ok( a.distanceToPoint( one3 ) === - 1, "Passed!" );
  37588. } );
  37589. QUnit.test( "intersectsSphere", ( assert ) => {
  37590. var a = new Sphere( one3.clone(), 1 );
  37591. var b = new Sphere( zero3.clone(), 1 );
  37592. var c = new Sphere( zero3.clone(), 0.25 );
  37593. assert.ok( a.intersectsSphere( b ), "Passed!" );
  37594. assert.ok( ! a.intersectsSphere( c ), "Passed!" );
  37595. } );
  37596. QUnit.test( "intersectsBox", ( assert ) => {
  37597. var a = new Sphere();
  37598. var b = new Sphere( new Vector3( - 5, - 5, - 5 ) );
  37599. var box = new Box3( zero3, one3 );
  37600. assert.strictEqual( a.intersectsBox( box ), true, "Check default sphere" );
  37601. assert.strictEqual( b.intersectsBox( box ), false, "Check shifted sphere" );
  37602. } );
  37603. QUnit.test( "intersectsPlane", ( assert ) => {
  37604. var a = new Sphere( zero3.clone(), 1 );
  37605. var b = new Plane( new Vector3( 0, 1, 0 ), 1 );
  37606. var c = new Plane( new Vector3( 0, 1, 0 ), 1.25 );
  37607. var d = new Plane( new Vector3( 0, - 1, 0 ), 1.25 );
  37608. assert.ok( a.intersectsPlane( b ), "Passed!" );
  37609. assert.ok( ! a.intersectsPlane( c ), "Passed!" );
  37610. assert.ok( ! a.intersectsPlane( d ), "Passed!" );
  37611. } );
  37612. QUnit.test( "clampPoint", ( assert ) => {
  37613. var a = new Sphere( one3.clone(), 1 );
  37614. assert.ok( a.clampPoint( new Vector3( 1, 1, 3 ) ).equals( new Vector3( 1, 1, 2 ) ), "Passed!" );
  37615. assert.ok( a.clampPoint( new Vector3( 1, 1, - 3 ) ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
  37616. } );
  37617. QUnit.test( "getBoundingBox", ( assert ) => {
  37618. var a = new Sphere( one3.clone(), 1 );
  37619. assert.ok( a.getBoundingBox().equals( new Box3( zero3, two3 ) ), "Passed!" );
  37620. a.set( zero3, 0 );
  37621. assert.ok( a.getBoundingBox().equals( new Box3( zero3, zero3 ) ), "Passed!" );
  37622. } );
  37623. QUnit.test( "applyMatrix4", ( assert ) => {
  37624. var a = new Sphere( one3.clone(), 1 );
  37625. var m = new Matrix4().makeTranslation( 1, - 2, 1 );
  37626. assert.ok( a.clone().applyMatrix4( m ).getBoundingBox().equals( a.getBoundingBox().applyMatrix4( m ) ), "Passed!" );
  37627. } );
  37628. QUnit.test( "translate", ( assert ) => {
  37629. var a = new Sphere( one3.clone(), 1 );
  37630. a.translate( one3.clone().negate() );
  37631. assert.ok( a.center.equals( zero3 ), "Passed!" );
  37632. } );
  37633. QUnit.test( "equals", ( assert ) => {
  37634. var a = new Sphere();
  37635. var b = new Sphere( new Vector3( 1, 0, 0 ) );
  37636. var c = new Sphere( new Vector3( 1, 0, 0 ), 1.0 );
  37637. assert.strictEqual( a.equals( b ), false, "a does not equal b" );
  37638. assert.strictEqual( a.equals( c ), false, "a does not equal c" );
  37639. assert.strictEqual( b.equals( c ), false, "b does not equal c" );
  37640. a.copy( b );
  37641. assert.strictEqual( a.equals( b ), true, "a equals b after copy()" );
  37642. } );
  37643. } );
  37644. } );
  37645. /**
  37646. * @author bhouston / http://clara.io
  37647. * @author WestLangley / http://github.com/WestLangley
  37648. *
  37649. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  37650. *
  37651. * The poles (phi) are at the positive and negative y axis.
  37652. * The equator starts at positive z.
  37653. */
  37654. function Spherical( radius, phi, theta ) {
  37655. this.radius = ( radius !== undefined ) ? radius : 1.0;
  37656. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  37657. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  37658. return this;
  37659. }
  37660. Object.assign( Spherical.prototype, {
  37661. set: function ( radius, phi, theta ) {
  37662. this.radius = radius;
  37663. this.phi = phi;
  37664. this.theta = theta;
  37665. return this;
  37666. },
  37667. clone: function () {
  37668. return new this.constructor().copy( this );
  37669. },
  37670. copy: function ( other ) {
  37671. this.radius = other.radius;
  37672. this.phi = other.phi;
  37673. this.theta = other.theta;
  37674. return this;
  37675. },
  37676. // restrict phi to be betwee EPS and PI-EPS
  37677. makeSafe: function () {
  37678. var EPS = 0.000001;
  37679. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  37680. return this;
  37681. },
  37682. setFromVector3: function ( vec3 ) {
  37683. this.radius = vec3.length();
  37684. if ( this.radius === 0 ) {
  37685. this.theta = 0;
  37686. this.phi = 0;
  37687. } else {
  37688. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  37689. this.phi = Math.acos( _Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  37690. }
  37691. return this;
  37692. }
  37693. } );
  37694. /**
  37695. * @author moraxy / https://github.com/moraxy
  37696. * @author TristanVALCKE / https://github.com/Itee
  37697. */
  37698. /* global QUnit */
  37699. QUnit.module( 'Maths', () => {
  37700. QUnit.module.todo( 'Spherical', () => {
  37701. // INSTANCING
  37702. QUnit.test( "Instancing", ( assert ) => {
  37703. var a = new Spherical();
  37704. var radius = 10.0;
  37705. var phi = Math.acos( - 0.5 );
  37706. var theta = Math.sqrt( Math.PI ) * phi;
  37707. assert.strictEqual( a.radius, 1.0, "Default values: check radius" );
  37708. assert.strictEqual( a.phi, 0, "Default values: check phi" );
  37709. assert.strictEqual( a.theta, 0, "Default values: check theta" );
  37710. var a = new Spherical( radius, phi, theta );
  37711. assert.strictEqual( a.radius, radius, "Custom values: check radius" );
  37712. assert.strictEqual( a.phi, phi, "Custom values: check phi" );
  37713. assert.strictEqual( a.theta, theta, "Custom values: check theta" );
  37714. } );
  37715. // PUBLIC STUFF
  37716. QUnit.test( "isSpherical", ( assert ) => {
  37717. assert.ok( false, "everything's gonna be alright" );
  37718. } );
  37719. QUnit.test( "set", ( assert ) => {
  37720. var a = new Spherical();
  37721. var radius = 10.0;
  37722. var phi = Math.acos( - 0.5 );
  37723. var theta = Math.sqrt( Math.PI ) * phi;
  37724. a.set( radius, phi, theta );
  37725. assert.strictEqual( a.radius, radius, "Check radius" );
  37726. assert.strictEqual( a.phi, phi, "Check phi" );
  37727. assert.strictEqual( a.theta, theta, "Check theta" );
  37728. } );
  37729. QUnit.test( "clone", ( assert ) => {
  37730. var radius = 10.0;
  37731. var phi = Math.acos( - 0.5 );
  37732. var theta = Math.sqrt( Math.PI ) * phi;
  37733. var a = new Spherical( radius, phi, theta );
  37734. var b = a.clone();
  37735. assert.propEqual( a, b, "Check a and b are equal after clone()" );
  37736. a.radius = 2.0;
  37737. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  37738. } );
  37739. QUnit.test( "copy", ( assert ) => {
  37740. var radius = 10.0;
  37741. var phi = Math.acos( - 0.5 );
  37742. var theta = Math.sqrt( Math.PI ) * phi;
  37743. var a = new Spherical( radius, phi, theta );
  37744. var b = new Spherical().copy( a );
  37745. assert.propEqual( a, b, "Check a and b are equal after copy()" );
  37746. a.radius = 2.0;
  37747. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  37748. } );
  37749. QUnit.test( "makeSafe", ( assert ) => {
  37750. var EPS = 0.000001; // from source
  37751. var tooLow = 0.0;
  37752. var tooHigh = Math.PI;
  37753. var justRight = 1.5;
  37754. var a = new Spherical( 1, tooLow, 0 );
  37755. a.makeSafe();
  37756. assert.strictEqual( a.phi, EPS, "Check if small values are set to EPS" );
  37757. a.set( 1, tooHigh, 0 );
  37758. a.makeSafe();
  37759. assert.strictEqual( a.phi, Math.PI - EPS, "Check if high values are set to (Math.PI - EPS)" );
  37760. a.set( 1, justRight, 0 );
  37761. a.makeSafe();
  37762. assert.strictEqual( a.phi, justRight, "Check that valid values don't get changed" );
  37763. } );
  37764. QUnit.test( "setFromVector3", ( assert ) => {
  37765. var a = new Spherical( 1, 1, 1 );
  37766. var b = new Vector3( 0, 0, 0 );
  37767. var c = new Vector3( Math.PI, 1, - Math.PI );
  37768. var expected = new Spherical( 4.554032147688322, 1.3494066171539107, 2.356194490192345 );
  37769. a.setFromVector3( b );
  37770. assert.strictEqual( a.radius, 0, "Zero-length vector: check radius" );
  37771. assert.strictEqual( a.phi, 0, "Zero-length vector: check phi" );
  37772. assert.strictEqual( a.theta, 0, "Zero-length vector: check theta" );
  37773. a.setFromVector3( c );
  37774. assert.ok( Math.abs( a.radius - expected.radius ) <= eps, "Normal vector: check radius" );
  37775. assert.ok( Math.abs( a.phi - expected.phi ) <= eps, "Normal vector: check phi" );
  37776. assert.ok( Math.abs( a.theta - expected.theta ) <= eps, "Normal vector: check theta" );
  37777. } );
  37778. } );
  37779. } );
  37780. /**
  37781. * @author bhouston / http://exocortex.com
  37782. * @author TristanVALCKE / https://github.com/Itee
  37783. */
  37784. /* global QUnit */
  37785. QUnit.module( 'Maths', () => {
  37786. QUnit.module.todo( 'Triangle', () => {
  37787. // INSTANCING
  37788. QUnit.test( "Instancing", ( assert ) => {
  37789. var a = new Triangle();
  37790. assert.ok( a.a.equals( zero3 ), "Passed!" );
  37791. assert.ok( a.b.equals( zero3 ), "Passed!" );
  37792. assert.ok( a.c.equals( zero3 ), "Passed!" );
  37793. var a = new Triangle( one3.clone().negate(), one3.clone(), two3.clone() );
  37794. assert.ok( a.a.equals( one3.clone().negate() ), "Passed!" );
  37795. assert.ok( a.b.equals( one3 ), "Passed!" );
  37796. assert.ok( a.c.equals( two3 ), "Passed!" );
  37797. } );
  37798. // STATIC STUFF
  37799. QUnit.test( "normal", ( assert ) => {
  37800. assert.ok( false, "everything's gonna be alright" );
  37801. } );
  37802. QUnit.test( "barycoordFromPoint", ( assert ) => {
  37803. assert.ok( false, "everything's gonna be alright" );
  37804. } );
  37805. QUnit.test( "containsPoint", ( assert ) => {
  37806. assert.ok( false, "everything's gonna be alright" );
  37807. } );
  37808. // PUBLIC STUFF
  37809. QUnit.test( "set", ( assert ) => {
  37810. var a = new Triangle();
  37811. a.set( one3.clone().negate(), one3, two3 );
  37812. assert.ok( a.a.equals( one3.clone().negate() ), "Passed!" );
  37813. assert.ok( a.b.equals( one3 ), "Passed!" );
  37814. assert.ok( a.c.equals( two3 ), "Passed!" );
  37815. } );
  37816. QUnit.test( "setFromPointsAndIndices", ( assert ) => {
  37817. var a = new Triangle();
  37818. var points = [ one3, one3.clone().negate(), two3 ];
  37819. a.setFromPointsAndIndices( points, 1, 0, 2 );
  37820. assert.ok( a.a.equals( one3.clone().negate() ), "Passed!" );
  37821. assert.ok( a.b.equals( one3 ), "Passed!" );
  37822. assert.ok( a.c.equals( two3 ), "Passed!" );
  37823. } );
  37824. QUnit.test( "clone", ( assert ) => {
  37825. assert.ok( false, "everything's gonna be alright" );
  37826. } );
  37827. QUnit.test( "copy", ( assert ) => {
  37828. var a = new Triangle( one3.clone().negate(), one3.clone(), two3.clone() );
  37829. var b = new Triangle().copy( a );
  37830. assert.ok( b.a.equals( one3.clone().negate() ), "Passed!" );
  37831. assert.ok( b.b.equals( one3 ), "Passed!" );
  37832. assert.ok( b.c.equals( two3 ), "Passed!" );
  37833. // ensure that it is a true copy
  37834. a.a = one3;
  37835. a.b = zero3;
  37836. a.c = zero3;
  37837. assert.ok( b.a.equals( one3.clone().negate() ), "Passed!" );
  37838. assert.ok( b.b.equals( one3 ), "Passed!" );
  37839. assert.ok( b.c.equals( two3 ), "Passed!" );
  37840. } );
  37841. QUnit.test( "area", ( assert ) => {
  37842. var a = new Triangle();
  37843. assert.ok( a.area() == 0, "Passed!" );
  37844. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37845. assert.ok( a.area() == 0.5, "Passed!" );
  37846. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37847. assert.ok( a.area() == 2, "Passed!" );
  37848. // colinear triangle.
  37849. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 3, 0, 0 ) );
  37850. assert.ok( a.area() == 0, "Passed!" );
  37851. } );
  37852. QUnit.test( "midpoint", ( assert ) => {
  37853. var a = new Triangle();
  37854. assert.ok( a.midpoint().equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  37855. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37856. assert.ok( a.midpoint().equals( new Vector3( 1 / 3, 1 / 3, 0 ) ), "Passed!" );
  37857. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37858. assert.ok( a.midpoint().equals( new Vector3( 2 / 3, 0, 2 / 3 ) ), "Passed!" );
  37859. } );
  37860. QUnit.test( "normal", ( assert ) => {
  37861. var a = new Triangle();
  37862. assert.ok( a.normal().equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  37863. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37864. assert.ok( a.normal().equals( new Vector3( 0, 0, 1 ) ), "Passed!" );
  37865. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37866. assert.ok( a.normal().equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37867. } );
  37868. QUnit.test( "plane", ( assert ) => {
  37869. var a = new Triangle();
  37870. assert.notOk( isNaN( a.plane().distanceToPoint( a.a ) ), "Passed!" );
  37871. assert.notOk( isNaN( a.plane().distanceToPoint( a.b ) ), "Passed!" );
  37872. assert.notOk( isNaN( a.plane().distanceToPoint( a.c ) ), "Passed!" );
  37873. assert.notPropEqual( a.plane().normal, {
  37874. x: NaN,
  37875. y: NaN,
  37876. z: NaN
  37877. }, "Passed!" );
  37878. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37879. assert.ok( a.plane().distanceToPoint( a.a ) == 0, "Passed!" );
  37880. assert.ok( a.plane().distanceToPoint( a.b ) == 0, "Passed!" );
  37881. assert.ok( a.plane().distanceToPoint( a.c ) == 0, "Passed!" );
  37882. assert.ok( a.plane().normal.equals( a.normal() ), "Passed!" );
  37883. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37884. assert.ok( a.plane().distanceToPoint( a.a ) == 0, "Passed!" );
  37885. assert.ok( a.plane().distanceToPoint( a.b ) == 0, "Passed!" );
  37886. assert.ok( a.plane().distanceToPoint( a.c ) == 0, "Passed!" );
  37887. assert.ok( a.plane().normal.clone().normalize().equals( a.normal() ), "Passed!" );
  37888. } );
  37889. QUnit.test( "barycoordFromPoint", ( assert ) => {
  37890. var a = new Triangle();
  37891. var bad = new Vector3( - 2, - 1, - 1 );
  37892. assert.ok( a.barycoordFromPoint( a.a ).equals( bad ), "Passed!" );
  37893. assert.ok( a.barycoordFromPoint( a.b ).equals( bad ), "Passed!" );
  37894. assert.ok( a.barycoordFromPoint( a.c ).equals( bad ), "Passed!" );
  37895. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37896. assert.ok( a.barycoordFromPoint( a.a ).equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  37897. assert.ok( a.barycoordFromPoint( a.b ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37898. assert.ok( a.barycoordFromPoint( a.c ).equals( new Vector3( 0, 0, 1 ) ), "Passed!" );
  37899. assert.ok( a.barycoordFromPoint( a.midpoint() ).distanceTo( new Vector3( 1 / 3, 1 / 3, 1 / 3 ) ) < 0.0001, "Passed!" );
  37900. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37901. assert.ok( a.barycoordFromPoint( a.a ).equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  37902. assert.ok( a.barycoordFromPoint( a.b ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37903. assert.ok( a.barycoordFromPoint( a.c ).equals( new Vector3( 0, 0, 1 ) ), "Passed!" );
  37904. assert.ok( a.barycoordFromPoint( a.midpoint() ).distanceTo( new Vector3( 1 / 3, 1 / 3, 1 / 3 ) ) < 0.0001, "Passed!" );
  37905. } );
  37906. QUnit.test( "containsPoint", ( assert ) => {
  37907. var a = new Triangle();
  37908. assert.ok( ! a.containsPoint( a.a ), "Passed!" );
  37909. assert.ok( ! a.containsPoint( a.b ), "Passed!" );
  37910. assert.ok( ! a.containsPoint( a.c ), "Passed!" );
  37911. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37912. assert.ok( a.containsPoint( a.a ), "Passed!" );
  37913. assert.ok( a.containsPoint( a.b ), "Passed!" );
  37914. assert.ok( a.containsPoint( a.c ), "Passed!" );
  37915. assert.ok( a.containsPoint( a.midpoint() ), "Passed!" );
  37916. assert.ok( ! a.containsPoint( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
  37917. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37918. assert.ok( a.containsPoint( a.a ), "Passed!" );
  37919. assert.ok( a.containsPoint( a.b ), "Passed!" );
  37920. assert.ok( a.containsPoint( a.c ), "Passed!" );
  37921. assert.ok( a.containsPoint( a.midpoint() ), "Passed!" );
  37922. assert.ok( ! a.containsPoint( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
  37923. } );
  37924. QUnit.test( "closestPointToPoint", ( assert ) => {
  37925. var a = new Triangle( new Vector3( - 1, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37926. // point lies inside the triangle
  37927. var b0 = a.closestPointToPoint( new Vector3( 0, 0.5, 0 ) );
  37928. assert.ok( b0.equals( new Vector3( 0, 0.5, 0 ) ), "Passed!" );
  37929. // point lies on a vertex
  37930. var b0 = a.closestPointToPoint( a.a );
  37931. assert.ok( b0.equals( a.a ), "Passed!" );
  37932. var b0 = a.closestPointToPoint( a.b );
  37933. assert.ok( b0.equals( a.b ), "Passed!" );
  37934. var b0 = a.closestPointToPoint( a.c );
  37935. assert.ok( b0.equals( a.c ), "Passed!" );
  37936. // point lies on an edge
  37937. var b0 = a.closestPointToPoint( zero3.clone() );
  37938. assert.ok( b0.equals( zero3.clone() ), "Passed!" );
  37939. // point lies outside the triangle
  37940. var b0 = a.closestPointToPoint( new Vector3( - 2, 0, 0 ) );
  37941. assert.ok( b0.equals( new Vector3( - 1, 0, 0 ) ), "Passed!" );
  37942. var b0 = a.closestPointToPoint( new Vector3( 2, 0, 0 ) );
  37943. assert.ok( b0.equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  37944. var b0 = a.closestPointToPoint( new Vector3( 0, 2, 0 ) );
  37945. assert.ok( b0.equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37946. var b0 = a.closestPointToPoint( new Vector3( 0, - 2, 0 ) );
  37947. assert.ok( b0.equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  37948. } );
  37949. QUnit.test( "equals", ( assert ) => {
  37950. var a = new Triangle(
  37951. new Vector3( 1, 0, 0 ),
  37952. new Vector3( 0, 1, 0 ),
  37953. new Vector3( 0, 0, 1 )
  37954. );
  37955. var b = new Triangle(
  37956. new Vector3( 0, 0, 1 ),
  37957. new Vector3( 0, 1, 0 ),
  37958. new Vector3( 1, 0, 0 )
  37959. );
  37960. var c = new Triangle(
  37961. new Vector3( - 1, 0, 0 ),
  37962. new Vector3( 0, 1, 0 ),
  37963. new Vector3( 0, 0, 1 )
  37964. );
  37965. assert.ok( a.equals( a ), "a equals a" );
  37966. assert.notOk( a.equals( b ), "a does not equal b" );
  37967. assert.notOk( a.equals( c ), "a does not equal c" );
  37968. assert.notOk( b.equals( c ), "b does not equal c" );
  37969. a.copy( b );
  37970. assert.ok( a.equals( a ), "a equals b after copy()" );
  37971. } );
  37972. } );
  37973. } );
  37974. /**
  37975. * @author bhouston / http://exocortex.com
  37976. * @author TristanVALCKE / https://github.com/Itee
  37977. */
  37978. /* global QUnit */
  37979. QUnit.module( 'Maths', () => {
  37980. QUnit.module.todo( 'Vector2', () => {
  37981. // INSTANCING
  37982. QUnit.test( "Instancing", ( assert ) => {
  37983. var a = new Vector2();
  37984. assert.ok( a.x == 0, "Passed!" );
  37985. assert.ok( a.y == 0, "Passed!" );
  37986. var a = new Vector2( x, y );
  37987. assert.ok( a.x === x, "Passed!" );
  37988. assert.ok( a.y === y, "Passed!" );
  37989. } );
  37990. // PROPERTIES // ( [Itee] WHAT ??? o_O )
  37991. QUnit.test( "properties", ( assert ) => {
  37992. var a = new Vector2( 0, 0 );
  37993. var width = 100;
  37994. var height = 200;
  37995. assert.ok( a.width = width, "Set width" );
  37996. assert.ok( a.height = height, "Set height" );
  37997. a.set( width, height );
  37998. assert.strictEqual( a.width, width, "Get width" );
  37999. assert.strictEqual( a.height, height, "Get height" );
  38000. } );
  38001. QUnit.test( "width", ( assert ) => {
  38002. assert.ok( false, "everything's gonna be alright" );
  38003. } );
  38004. QUnit.test( "height", ( assert ) => {
  38005. assert.ok( false, "everything's gonna be alright" );
  38006. } );
  38007. // PUBLIC STUFF
  38008. QUnit.test( "isVector2", ( assert ) => {
  38009. assert.ok( false, "everything's gonna be alright" );
  38010. } );
  38011. QUnit.test( "set", ( assert ) => {
  38012. var a = new Vector2();
  38013. assert.ok( a.x == 0, "Passed!" );
  38014. assert.ok( a.y == 0, "Passed!" );
  38015. a.set( x, y );
  38016. assert.ok( a.x == x, "Passed!" );
  38017. assert.ok( a.y == y, "Passed!" );
  38018. } );
  38019. QUnit.test( "setScalar", ( assert ) => {
  38020. assert.ok( false, "everything's gonna be alright" );
  38021. } );
  38022. QUnit.test( "setX", ( assert ) => {
  38023. assert.ok( false, "everything's gonna be alright" );
  38024. } );
  38025. QUnit.test( "setY", ( assert ) => {
  38026. assert.ok( false, "everything's gonna be alright" );
  38027. } );
  38028. QUnit.test( "setComponent", ( assert ) => {
  38029. assert.ok( false, "everything's gonna be alright" );
  38030. } );
  38031. QUnit.test( "getComponent", ( assert ) => {
  38032. assert.ok( false, "everything's gonna be alright" );
  38033. } );
  38034. QUnit.test( "clone", ( assert ) => {
  38035. assert.ok( false, "everything's gonna be alright" );
  38036. } );
  38037. QUnit.test( "copy", ( assert ) => {
  38038. var a = new Vector2( x, y );
  38039. var b = new Vector2().copy( a );
  38040. assert.ok( b.x == x, "Passed!" );
  38041. assert.ok( b.y == y, "Passed!" );
  38042. // ensure that it is a true copy
  38043. a.x = 0;
  38044. a.y = - 1;
  38045. assert.ok( b.x == x, "Passed!" );
  38046. assert.ok( b.y == y, "Passed!" );
  38047. } );
  38048. QUnit.test( "add", ( assert ) => {
  38049. var a = new Vector2( x, y );
  38050. var b = new Vector2( - x, - y );
  38051. a.add( b );
  38052. assert.ok( a.x == 0, "Passed!" );
  38053. assert.ok( a.y == 0, "Passed!" );
  38054. var c = new Vector2().addVectors( b, b );
  38055. assert.ok( c.x == - 2 * x, "Passed!" );
  38056. assert.ok( c.y == - 2 * y, "Passed!" );
  38057. } );
  38058. QUnit.test( "addScalar", ( assert ) => {
  38059. assert.ok( false, "everything's gonna be alright" );
  38060. } );
  38061. QUnit.test( "addVectors", ( assert ) => {
  38062. assert.ok( false, "everything's gonna be alright" );
  38063. } );
  38064. QUnit.test( "addScaledVector", ( assert ) => {
  38065. var a = new Vector2( x, y );
  38066. var b = new Vector2( 2, 3 );
  38067. var s = 3;
  38068. a.addScaledVector( b, s );
  38069. assert.strictEqual( a.x, x + b.x * s, "Check x" );
  38070. assert.strictEqual( a.y, y + b.y * s, "Check y" );
  38071. } );
  38072. QUnit.test( "sub", ( assert ) => {
  38073. var a = new Vector2( x, y );
  38074. var b = new Vector2( - x, - y );
  38075. a.sub( b );
  38076. assert.ok( a.x == 2 * x, "Passed!" );
  38077. assert.ok( a.y == 2 * y, "Passed!" );
  38078. var c = new Vector2().subVectors( a, a );
  38079. assert.ok( c.x == 0, "Passed!" );
  38080. assert.ok( c.y == 0, "Passed!" );
  38081. } );
  38082. QUnit.test( "subScalar", ( assert ) => {
  38083. assert.ok( false, "everything's gonna be alright" );
  38084. } );
  38085. QUnit.test( "subVectors", ( assert ) => {
  38086. assert.ok( false, "everything's gonna be alright" );
  38087. } );
  38088. QUnit.test( "multiply", ( assert ) => {
  38089. assert.ok( false, "everything's gonna be alright" );
  38090. } );
  38091. QUnit.test( "multiplyScalar", ( assert ) => {
  38092. assert.ok( false, "everything's gonna be alright" );
  38093. } );
  38094. QUnit.test( "divide", ( assert ) => {
  38095. assert.ok( false, "everything's gonna be alright" );
  38096. } );
  38097. QUnit.test( "divideScalar", ( assert ) => {
  38098. assert.ok( false, "everything's gonna be alright" );
  38099. } );
  38100. QUnit.test( "applyMatrix3", ( assert ) => {
  38101. var a = new Vector2( x, y );
  38102. var m = new Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  38103. a.applyMatrix3( m );
  38104. assert.strictEqual( a.x, 18, "Check x" );
  38105. assert.strictEqual( a.y, 60, "Check y" );
  38106. } );
  38107. QUnit.test( "min", ( assert ) => {
  38108. assert.ok( false, "everything's gonna be alright" );
  38109. } );
  38110. QUnit.test( "max", ( assert ) => {
  38111. assert.ok( false, "everything's gonna be alright" );
  38112. } );
  38113. QUnit.test( "clamp", ( assert ) => {
  38114. assert.ok( false, "everything's gonna be alright" );
  38115. } );
  38116. QUnit.test( "clampScalar", ( assert ) => {
  38117. assert.ok( false, "everything's gonna be alright" );
  38118. } );
  38119. QUnit.test( "clampLength", ( assert ) => {
  38120. assert.ok( false, "everything's gonna be alright" );
  38121. } );
  38122. QUnit.test( "floor", ( assert ) => {
  38123. assert.ok( false, "everything's gonna be alright" );
  38124. } );
  38125. QUnit.test( "ceil", ( assert ) => {
  38126. assert.ok( false, "everything's gonna be alright" );
  38127. } );
  38128. QUnit.test( "round", ( assert ) => {
  38129. assert.ok( false, "everything's gonna be alright" );
  38130. } );
  38131. QUnit.test( "roundToZero", ( assert ) => {
  38132. assert.ok( false, "everything's gonna be alright" );
  38133. } );
  38134. QUnit.test( "negate", ( assert ) => {
  38135. var a = new Vector2( x, y );
  38136. a.negate();
  38137. assert.ok( a.x == - x, "Passed!" );
  38138. assert.ok( a.y == - y, "Passed!" );
  38139. } );
  38140. QUnit.test( "dot", ( assert ) => {
  38141. var a = new Vector2( x, y );
  38142. var b = new Vector2( - x, - y );
  38143. var c = new Vector2();
  38144. var result = a.dot( b );
  38145. assert.ok( result == ( - x * x - y * y ), "Passed!" );
  38146. var result = a.dot( c );
  38147. assert.ok( result == 0, "Passed!" );
  38148. } );
  38149. QUnit.test( "lengthSq", ( assert ) => {
  38150. assert.ok( false, "everything's gonna be alright" );
  38151. } );
  38152. QUnit.test( "length", ( assert ) => {
  38153. assert.ok( false, "everything's gonna be alright" );
  38154. } );
  38155. QUnit.test( "manhattanLength", ( assert ) => {
  38156. var a = new Vector2( x, 0 );
  38157. var b = new Vector2( 0, - y );
  38158. var c = new Vector2();
  38159. assert.strictEqual( a.manhattanLength(), x, "Positive component" );
  38160. assert.strictEqual( b.manhattanLength(), y, "Negative component" );
  38161. assert.strictEqual( c.manhattanLength(), 0, "Empty component" );
  38162. a.set( x, y );
  38163. assert.strictEqual( a.manhattanLength(), Math.abs( x ) + Math.abs( y ), "Two components" );
  38164. } );
  38165. QUnit.test( "normalize", ( assert ) => {
  38166. var a = new Vector2( x, 0 );
  38167. var b = new Vector2( 0, - y );
  38168. var c = new Vector2();
  38169. a.normalize();
  38170. assert.ok( a.length() == 1, "Passed!" );
  38171. assert.ok( a.x == 1, "Passed!" );
  38172. b.normalize();
  38173. assert.ok( b.length() == 1, "Passed!" );
  38174. assert.ok( b.y == - 1, "Passed!" );
  38175. } );
  38176. QUnit.test( "angle", ( assert ) => {
  38177. assert.ok( false, "everything's gonna be alright" );
  38178. } );
  38179. QUnit.test( "distanceTo", ( assert ) => {
  38180. assert.ok( false, "everything's gonna be alright" );
  38181. } );
  38182. QUnit.test( "distanceToSquared", ( assert ) => {
  38183. assert.ok( false, "everything's gonna be alright" );
  38184. } );
  38185. QUnit.test( "manhattanDistanceTo", ( assert ) => {
  38186. assert.ok( false, "everything's gonna be alright" );
  38187. } );
  38188. QUnit.test( "setLength", ( assert ) => {
  38189. var a = new Vector2( x, 0 );
  38190. assert.ok( a.length() == x, "Passed!" );
  38191. a.setLength( y );
  38192. assert.ok( a.length() == y, "Passed!" );
  38193. var a = new Vector2( 0, 0 );
  38194. assert.ok( a.length() == 0, "Passed!" );
  38195. a.setLength( y );
  38196. assert.ok( a.length() == 0, "Passed!" );
  38197. a.setLength();
  38198. assert.ok( isNaN( a.length() ), "Passed!" );
  38199. } );
  38200. QUnit.test( "lerp", ( assert ) => {
  38201. assert.ok( false, "everything's gonna be alright" );
  38202. } );
  38203. QUnit.test( "lerpVectors", ( assert ) => {
  38204. assert.ok( false, "everything's gonna be alright" );
  38205. } );
  38206. QUnit.test( "equals", ( assert ) => {
  38207. var a = new Vector2( x, 0 );
  38208. var b = new Vector2( 0, - y );
  38209. assert.ok( a.x != b.x, "Passed!" );
  38210. assert.ok( a.y != b.y, "Passed!" );
  38211. assert.ok( ! a.equals( b ), "Passed!" );
  38212. assert.ok( ! b.equals( a ), "Passed!" );
  38213. a.copy( b );
  38214. assert.ok( a.x == b.x, "Passed!" );
  38215. assert.ok( a.y == b.y, "Passed!" );
  38216. assert.ok( a.equals( b ), "Passed!" );
  38217. assert.ok( b.equals( a ), "Passed!" );
  38218. } );
  38219. QUnit.test( "fromArray", ( assert ) => {
  38220. var a = new Vector2();
  38221. var array = [ 1, 2, 3, 4 ];
  38222. a.fromArray( array );
  38223. assert.strictEqual( a.x, 1, "No offset: check x" );
  38224. assert.strictEqual( a.y, 2, "No offset: check y" );
  38225. a.fromArray( array, 2 );
  38226. assert.strictEqual( a.x, 3, "With offset: check x" );
  38227. assert.strictEqual( a.y, 4, "With offset: check y" );
  38228. } );
  38229. QUnit.test( "toArray", ( assert ) => {
  38230. var a = new Vector2( x, y );
  38231. var array = a.toArray();
  38232. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  38233. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  38234. var array = [];
  38235. a.toArray( array );
  38236. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  38237. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  38238. var array = [];
  38239. a.toArray( array, 1 );
  38240. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  38241. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  38242. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  38243. } );
  38244. QUnit.test( "fromBufferAttribute", ( assert ) => {
  38245. var a = new Vector2();
  38246. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4 ] ), 2 );
  38247. a.fromBufferAttribute( attr, 0 );
  38248. assert.strictEqual( a.x, 1, "Offset 0: check x" );
  38249. assert.strictEqual( a.y, 2, "Offset 0: check y" );
  38250. a.fromBufferAttribute( attr, 1 );
  38251. assert.strictEqual( a.x, 3, "Offset 1: check x" );
  38252. assert.strictEqual( a.y, 4, "Offset 1: check y" );
  38253. } );
  38254. QUnit.test( "rotateAround", ( assert ) => {
  38255. assert.ok( false, "everything's gonna be alright" );
  38256. } );
  38257. // TODO (Itee) refactor/split
  38258. QUnit.test( "setX,setY", ( assert ) => {
  38259. var a = new Vector2();
  38260. assert.ok( a.x == 0, "Passed!" );
  38261. assert.ok( a.y == 0, "Passed!" );
  38262. a.setX( x );
  38263. a.setY( y );
  38264. assert.ok( a.x == x, "Passed!" );
  38265. assert.ok( a.y == y, "Passed!" );
  38266. } );
  38267. QUnit.test( "setComponent,getComponent", ( assert ) => {
  38268. var a = new Vector2();
  38269. assert.ok( a.x == 0, "Passed!" );
  38270. assert.ok( a.y == 0, "Passed!" );
  38271. a.setComponent( 0, 1 );
  38272. a.setComponent( 1, 2 );
  38273. assert.ok( a.getComponent( 0 ) == 1, "Passed!" );
  38274. assert.ok( a.getComponent( 1 ) == 2, "Passed!" );
  38275. } );
  38276. QUnit.test( "multiply/divide", ( assert ) => {
  38277. var a = new Vector2( x, y );
  38278. var b = new Vector2( - x, - y );
  38279. a.multiplyScalar( - 2 );
  38280. assert.ok( a.x == x * - 2, "Passed!" );
  38281. assert.ok( a.y == y * - 2, "Passed!" );
  38282. b.multiplyScalar( - 2 );
  38283. assert.ok( b.x == 2 * x, "Passed!" );
  38284. assert.ok( b.y == 2 * y, "Passed!" );
  38285. a.divideScalar( - 2 );
  38286. assert.ok( a.x == x, "Passed!" );
  38287. assert.ok( a.y == y, "Passed!" );
  38288. b.divideScalar( - 2 );
  38289. assert.ok( b.x == - x, "Passed!" );
  38290. assert.ok( b.y == - y, "Passed!" );
  38291. } );
  38292. QUnit.test( "min/max/clamp", ( assert ) => {
  38293. var a = new Vector2( x, y );
  38294. var b = new Vector2( - x, - y );
  38295. var c = new Vector2();
  38296. c.copy( a ).min( b );
  38297. assert.ok( c.x == - x, "Passed!" );
  38298. assert.ok( c.y == - y, "Passed!" );
  38299. c.copy( a ).max( b );
  38300. assert.ok( c.x == x, "Passed!" );
  38301. assert.ok( c.y == y, "Passed!" );
  38302. c.set( - 2 * x, 2 * y );
  38303. c.clamp( b, a );
  38304. assert.ok( c.x == - x, "Passed!" );
  38305. assert.ok( c.y == y, "Passed!" );
  38306. c.set( - 2 * x, 2 * x );
  38307. c.clampScalar( - x, x );
  38308. assert.equal( c.x, - x, "scalar clamp x" );
  38309. assert.equal( c.y, x, "scalar clamp y" );
  38310. } );
  38311. QUnit.test( "rounding", ( assert ) => {
  38312. assert.deepEqual( new Vector2( - 0.1, 0.1 ).floor(), new Vector2( - 1, 0 ), "floor .1" );
  38313. assert.deepEqual( new Vector2( - 0.5, 0.5 ).floor(), new Vector2( - 1, 0 ), "floor .5" );
  38314. assert.deepEqual( new Vector2( - 0.9, 0.9 ).floor(), new Vector2( - 1, 0 ), "floor .9" );
  38315. assert.deepEqual( new Vector2( - 0.1, 0.1 ).ceil(), new Vector2( 0, 1 ), "ceil .1" );
  38316. assert.deepEqual( new Vector2( - 0.5, 0.5 ).ceil(), new Vector2( 0, 1 ), "ceil .5" );
  38317. assert.deepEqual( new Vector2( - 0.9, 0.9 ).ceil(), new Vector2( 0, 1 ), "ceil .9" );
  38318. assert.deepEqual( new Vector2( - 0.1, 0.1 ).round(), new Vector2( 0, 0 ), "round .1" );
  38319. assert.deepEqual( new Vector2( - 0.5, 0.5 ).round(), new Vector2( 0, 1 ), "round .5" );
  38320. assert.deepEqual( new Vector2( - 0.9, 0.9 ).round(), new Vector2( - 1, 1 ), "round .9" );
  38321. assert.deepEqual( new Vector2( - 0.1, 0.1 ).roundToZero(), new Vector2( 0, 0 ), "roundToZero .1" );
  38322. assert.deepEqual( new Vector2( - 0.5, 0.5 ).roundToZero(), new Vector2( 0, 0 ), "roundToZero .5" );
  38323. assert.deepEqual( new Vector2( - 0.9, 0.9 ).roundToZero(), new Vector2( 0, 0 ), "roundToZero .9" );
  38324. assert.deepEqual( new Vector2( - 1.1, 1.1 ).roundToZero(), new Vector2( - 1, 1 ), "roundToZero 1.1" );
  38325. assert.deepEqual( new Vector2( - 1.5, 1.5 ).roundToZero(), new Vector2( - 1, 1 ), "roundToZero 1.5" );
  38326. assert.deepEqual( new Vector2( - 1.9, 1.9 ).roundToZero(), new Vector2( - 1, 1 ), "roundToZero 1.9" );
  38327. } );
  38328. QUnit.test( "length/lengthSq", ( assert ) => {
  38329. var a = new Vector2( x, 0 );
  38330. var b = new Vector2( 0, - y );
  38331. var c = new Vector2();
  38332. assert.ok( a.length() == x, "Passed!" );
  38333. assert.ok( a.lengthSq() == x * x, "Passed!" );
  38334. assert.ok( b.length() == y, "Passed!" );
  38335. assert.ok( b.lengthSq() == y * y, "Passed!" );
  38336. assert.ok( c.length() == 0, "Passed!" );
  38337. assert.ok( c.lengthSq() == 0, "Passed!" );
  38338. a.set( x, y );
  38339. assert.ok( a.length() == Math.sqrt( x * x + y * y ), "Passed!" );
  38340. assert.ok( a.lengthSq() == ( x * x + y * y ), "Passed!" );
  38341. } );
  38342. QUnit.test( "distanceTo/distanceToSquared", ( assert ) => {
  38343. var a = new Vector2( x, 0 );
  38344. var b = new Vector2( 0, - y );
  38345. var c = new Vector2();
  38346. assert.ok( a.distanceTo( c ) == x, "Passed!" );
  38347. assert.ok( a.distanceToSquared( c ) == x * x, "Passed!" );
  38348. assert.ok( b.distanceTo( c ) == y, "Passed!" );
  38349. assert.ok( b.distanceToSquared( c ) == y * y, "Passed!" );
  38350. } );
  38351. QUnit.test( "lerp/clone", ( assert ) => {
  38352. var a = new Vector2( x, 0 );
  38353. var b = new Vector2( 0, - y );
  38354. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 0.5 ) ), "Passed!" );
  38355. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 1 ) ), "Passed!" );
  38356. assert.ok( a.clone().lerp( b, 0 ).equals( a ), "Passed!" );
  38357. assert.ok( a.clone().lerp( b, 0.5 ).x == x * 0.5, "Passed!" );
  38358. assert.ok( a.clone().lerp( b, 0.5 ).y == - y * 0.5, "Passed!" );
  38359. assert.ok( a.clone().lerp( b, 1 ).equals( b ), "Passed!" );
  38360. } );
  38361. QUnit.test( "setComponent/getComponent exceptions", ( assert ) => {
  38362. var a = new Vector2( 0, 0 );
  38363. assert.throws(
  38364. function () {
  38365. a.setComponent( 2, 0 );
  38366. },
  38367. /index is out of range/,
  38368. "setComponent with an out of range index throws Error"
  38369. );
  38370. assert.throws(
  38371. function () {
  38372. a.getComponent( 2 );
  38373. },
  38374. /index is out of range/,
  38375. "getComponent with an out of range index throws Error"
  38376. );
  38377. } );
  38378. QUnit.test( "setScalar/addScalar/subScalar", ( assert ) => {
  38379. var a = new Vector2( 1, 1 );
  38380. var s = 3;
  38381. a.setScalar( s );
  38382. assert.strictEqual( a.x, s, "setScalar: check x" );
  38383. assert.strictEqual( a.y, s, "setScalar: check y" );
  38384. a.addScalar( s );
  38385. assert.strictEqual( a.x, 2 * s, "addScalar: check x" );
  38386. assert.strictEqual( a.y, 2 * s, "addScalar: check y" );
  38387. a.subScalar( 2 * s );
  38388. assert.strictEqual( a.x, 0, "subScalar: check x" );
  38389. assert.strictEqual( a.y, 0, "subScalar: check y" );
  38390. } );
  38391. QUnit.test( "multiply/divide", ( assert ) => {
  38392. var a = new Vector2( x, y );
  38393. var b = new Vector2( 2 * x, 2 * y );
  38394. var c = new Vector2( 4 * x, 4 * y );
  38395. a.multiply( b );
  38396. assert.strictEqual( a.x, x * b.x, "multiply: check x" );
  38397. assert.strictEqual( a.y, y * b.y, "multiply: check y" );
  38398. b.divide( c );
  38399. assert.strictEqual( b.x, 0.5, "divide: check x" );
  38400. assert.strictEqual( b.y, 0.5, "divide: check y" );
  38401. } );
  38402. } );
  38403. } );
  38404. /**
  38405. * @author bhouston / http://exocortex.com
  38406. * @author TristanVALCKE / https://github.com/Itee
  38407. */
  38408. /* global QUnit */
  38409. QUnit.module( 'Maths', () => {
  38410. QUnit.module.todo( 'Vector3', () => {
  38411. // INSTANCING
  38412. QUnit.test( "Instancing", ( assert ) => {
  38413. var a = new Vector3();
  38414. assert.ok( a.x == 0, "Passed!" );
  38415. assert.ok( a.y == 0, "Passed!" );
  38416. assert.ok( a.z == 0, "Passed!" );
  38417. var a = new Vector3( x, y, z );
  38418. assert.ok( a.x === x, "Passed!" );
  38419. assert.ok( a.y === y, "Passed!" );
  38420. assert.ok( a.z === z, "Passed!" );
  38421. } );
  38422. // PUBLIC STUFF
  38423. QUnit.test( "isVector3", ( assert ) => {
  38424. assert.ok( false, "everything's gonna be alright" );
  38425. } );
  38426. QUnit.test( "set", ( assert ) => {
  38427. var a = new Vector3();
  38428. assert.ok( a.x == 0, "Passed!" );
  38429. assert.ok( a.y == 0, "Passed!" );
  38430. assert.ok( a.z == 0, "Passed!" );
  38431. a.set( x, y, z );
  38432. assert.ok( a.x == x, "Passed!" );
  38433. assert.ok( a.y == y, "Passed!" );
  38434. assert.ok( a.z == z, "Passed!" );
  38435. } );
  38436. QUnit.test( "setScalar", ( assert ) => {
  38437. assert.ok( false, "everything's gonna be alright" );
  38438. } );
  38439. QUnit.test( "setX", ( assert ) => {
  38440. assert.ok( false, "everything's gonna be alright" );
  38441. } );
  38442. QUnit.test( "setY", ( assert ) => {
  38443. assert.ok( false, "everything's gonna be alright" );
  38444. } );
  38445. QUnit.test( "setZ", ( assert ) => {
  38446. assert.ok( false, "everything's gonna be alright" );
  38447. } );
  38448. QUnit.test( "setComponent", ( assert ) => {
  38449. assert.ok( false, "everything's gonna be alright" );
  38450. } );
  38451. QUnit.test( "getComponent", ( assert ) => {
  38452. assert.ok( false, "everything's gonna be alright" );
  38453. } );
  38454. QUnit.test( "clone", ( assert ) => {
  38455. assert.ok( false, "everything's gonna be alright" );
  38456. } );
  38457. QUnit.test( "copy", ( assert ) => {
  38458. var a = new Vector3( x, y, z );
  38459. var b = new Vector3().copy( a );
  38460. assert.ok( b.x == x, "Passed!" );
  38461. assert.ok( b.y == y, "Passed!" );
  38462. assert.ok( b.z == z, "Passed!" );
  38463. // ensure that it is a true copy
  38464. a.x = 0;
  38465. a.y = - 1;
  38466. a.z = - 2;
  38467. assert.ok( b.x == x, "Passed!" );
  38468. assert.ok( b.y == y, "Passed!" );
  38469. assert.ok( b.z == z, "Passed!" );
  38470. } );
  38471. QUnit.test( "add", ( assert ) => {
  38472. var a = new Vector3( x, y, z );
  38473. var b = new Vector3( - x, - y, - z );
  38474. a.add( b );
  38475. assert.ok( a.x == 0, "Passed!" );
  38476. assert.ok( a.y == 0, "Passed!" );
  38477. assert.ok( a.z == 0, "Passed!" );
  38478. var c = new Vector3().addVectors( b, b );
  38479. assert.ok( c.x == - 2 * x, "Passed!" );
  38480. assert.ok( c.y == - 2 * y, "Passed!" );
  38481. assert.ok( c.z == - 2 * z, "Passed!" );
  38482. } );
  38483. QUnit.test( "addScalar", ( assert ) => {
  38484. assert.ok( false, "everything's gonna be alright" );
  38485. } );
  38486. QUnit.test( "addVectors", ( assert ) => {
  38487. assert.ok( false, "everything's gonna be alright" );
  38488. } );
  38489. QUnit.test( "addScaledVector", ( assert ) => {
  38490. var a = new Vector3( x, y, z );
  38491. var b = new Vector3( 2, 3, 4 );
  38492. var s = 3;
  38493. a.addScaledVector( b, s );
  38494. assert.strictEqual( a.x, x + b.x * s, "Check x" );
  38495. assert.strictEqual( a.y, y + b.y * s, "Check y" );
  38496. assert.strictEqual( a.z, z + b.z * s, "Check z" );
  38497. } );
  38498. QUnit.test( "sub", ( assert ) => {
  38499. var a = new Vector3( x, y, z );
  38500. var b = new Vector3( - x, - y, - z );
  38501. a.sub( b );
  38502. assert.ok( a.x == 2 * x, "Passed!" );
  38503. assert.ok( a.y == 2 * y, "Passed!" );
  38504. assert.ok( a.z == 2 * z, "Passed!" );
  38505. var c = new Vector3().subVectors( a, a );
  38506. assert.ok( c.x == 0, "Passed!" );
  38507. assert.ok( c.y == 0, "Passed!" );
  38508. assert.ok( c.z == 0, "Passed!" );
  38509. } );
  38510. QUnit.test( "subScalar", ( assert ) => {
  38511. assert.ok( false, "everything's gonna be alright" );
  38512. } );
  38513. QUnit.test( "subVectors", ( assert ) => {
  38514. assert.ok( false, "everything's gonna be alright" );
  38515. } );
  38516. QUnit.test( "multiply", ( assert ) => {
  38517. assert.ok( false, "everything's gonna be alright" );
  38518. } );
  38519. QUnit.test( "multiplyScalar", ( assert ) => {
  38520. assert.ok( false, "everything's gonna be alright" );
  38521. } );
  38522. QUnit.test( "multiplyVectors", ( assert ) => {
  38523. var a = new Vector3( x, y, z );
  38524. var b = new Vector3( 2, 3, - 5 );
  38525. var c = new Vector3().multiplyVectors( a, b );
  38526. assert.strictEqual( c.x, x * 2, "Check x" );
  38527. assert.strictEqual( c.y, y * 3, "Check y" );
  38528. assert.strictEqual( c.z, z * - 5, "Check z" );
  38529. } );
  38530. QUnit.test( "applyEuler", ( assert ) => {
  38531. var a = new Vector3( x, y, z );
  38532. var euler = new Euler( 90, - 45, 0 );
  38533. var expected = new Vector3( - 2.352970120501014, - 4.7441750936226645, 0.9779234597246458 );
  38534. a.applyEuler( euler );
  38535. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  38536. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  38537. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  38538. } );
  38539. QUnit.test( "applyAxisAngle", ( assert ) => {
  38540. var a = new Vector3( x, y, z );
  38541. var axis = new Vector3( 0, 1, 0 );
  38542. var angle = Math.PI / 4.0;
  38543. var expected = new Vector3( 3 * Math.sqrt( 2 ), 3, Math.sqrt( 2 ) );
  38544. a.applyAxisAngle( axis, angle );
  38545. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  38546. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  38547. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  38548. } );
  38549. QUnit.test( "applyMatrix3", ( assert ) => {
  38550. var a = new Vector3( x, y, z );
  38551. var m = new Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  38552. a.applyMatrix3( m );
  38553. assert.strictEqual( a.x, 33, "Check x" );
  38554. assert.strictEqual( a.y, 99, "Check y" );
  38555. assert.strictEqual( a.z, 183, "Check z" );
  38556. } );
  38557. QUnit.test( "applyMatrix4", ( assert ) => {
  38558. var a = new Vector3( x, y, z );
  38559. var b = new Vector4( x, y, z, 1 );
  38560. var m = new Matrix4().makeRotationX( Math.PI );
  38561. a.applyMatrix4( m );
  38562. b.applyMatrix4( m );
  38563. assert.ok( a.x == b.x / b.w, "Passed!" );
  38564. assert.ok( a.y == b.y / b.w, "Passed!" );
  38565. assert.ok( a.z == b.z / b.w, "Passed!" );
  38566. var m = new Matrix4().makeTranslation( 3, 2, 1 );
  38567. a.applyMatrix4( m );
  38568. b.applyMatrix4( m );
  38569. assert.ok( a.x == b.x / b.w, "Passed!" );
  38570. assert.ok( a.y == b.y / b.w, "Passed!" );
  38571. assert.ok( a.z == b.z / b.w, "Passed!" );
  38572. var m = new Matrix4().set(
  38573. 1, 0, 0, 0,
  38574. 0, 1, 0, 0,
  38575. 0, 0, 1, 0,
  38576. 0, 0, 1, 0
  38577. );
  38578. a.applyMatrix4( m );
  38579. b.applyMatrix4( m );
  38580. assert.ok( a.x == b.x / b.w, "Passed!" );
  38581. assert.ok( a.y == b.y / b.w, "Passed!" );
  38582. assert.ok( a.z == b.z / b.w, "Passed!" );
  38583. } );
  38584. QUnit.test( "applyQuaternion", ( assert ) => {
  38585. var a = new Vector3( x, y, z );
  38586. a.applyQuaternion( new Quaternion() );
  38587. assert.strictEqual( a.x, x, "Identity rotation: check x" );
  38588. assert.strictEqual( a.y, y, "Identity rotation: check y" );
  38589. assert.strictEqual( a.z, z, "Identity rotation: check z" );
  38590. a.applyQuaternion( new Quaternion( x, y, z, w ) );
  38591. assert.strictEqual( a.x, 108, "Normal rotation: check x" );
  38592. assert.strictEqual( a.y, 162, "Normal rotation: check y" );
  38593. assert.strictEqual( a.z, 216, "Normal rotation: check z" );
  38594. } );
  38595. QUnit.test( "project", ( assert ) => {
  38596. assert.ok( false, "everything's gonna be alright" );
  38597. } );
  38598. QUnit.test( "unproject", ( assert ) => {
  38599. assert.ok( false, "everything's gonna be alright" );
  38600. } );
  38601. QUnit.test( "transformDirection", ( assert ) => {
  38602. var a = new Vector3( x, y, z );
  38603. var m = new Matrix4();
  38604. var transformed = new Vector3( 0.3713906763541037, 0.5570860145311556, 0.7427813527082074 );
  38605. a.transformDirection( m );
  38606. assert.ok( Math.abs( a.x - transformed.x ) <= eps, "Check x" );
  38607. assert.ok( Math.abs( a.y - transformed.y ) <= eps, "Check y" );
  38608. assert.ok( Math.abs( a.z - transformed.z ) <= eps, "Check z" );
  38609. } );
  38610. QUnit.test( "divide", ( assert ) => {
  38611. assert.ok( false, "everything's gonna be alright" );
  38612. } );
  38613. QUnit.test( "divideScalar", ( assert ) => {
  38614. assert.ok( false, "everything's gonna be alright" );
  38615. } );
  38616. QUnit.test( "min", ( assert ) => {
  38617. assert.ok( false, "everything's gonna be alright" );
  38618. } );
  38619. QUnit.test( "max", ( assert ) => {
  38620. assert.ok( false, "everything's gonna be alright" );
  38621. } );
  38622. QUnit.test( "clamp", ( assert ) => {
  38623. assert.ok( false, "everything's gonna be alright" );
  38624. } );
  38625. QUnit.test( "clampScalar", ( assert ) => {
  38626. var a = new Vector3( - 0.01, 0.5, 1.5 );
  38627. var clamped = new Vector3( 0.1, 0.5, 1.0 );
  38628. a.clampScalar( 0.1, 1.0 );
  38629. assert.ok( Math.abs( a.x - clamped.x ) <= 0.001, "Check x" );
  38630. assert.ok( Math.abs( a.y - clamped.y ) <= 0.001, "Check y" );
  38631. assert.ok( Math.abs( a.z - clamped.z ) <= 0.001, "Check z" );
  38632. } );
  38633. QUnit.test( "clampLength", ( assert ) => {
  38634. assert.ok( false, "everything's gonna be alright" );
  38635. } );
  38636. QUnit.test( "floor", ( assert ) => {
  38637. assert.ok( false, "everything's gonna be alright" );
  38638. } );
  38639. QUnit.test( "ceil", ( assert ) => {
  38640. assert.ok( false, "everything's gonna be alright" );
  38641. } );
  38642. QUnit.test( "round", ( assert ) => {
  38643. assert.ok( false, "everything's gonna be alright" );
  38644. } );
  38645. QUnit.test( "roundToZero", ( assert ) => {
  38646. assert.ok( false, "everything's gonna be alright" );
  38647. } );
  38648. QUnit.test( "negate", ( assert ) => {
  38649. var a = new Vector3( x, y, z );
  38650. a.negate();
  38651. assert.ok( a.x == - x, "Passed!" );
  38652. assert.ok( a.y == - y, "Passed!" );
  38653. assert.ok( a.z == - z, "Passed!" );
  38654. } );
  38655. QUnit.test( "dot", ( assert ) => {
  38656. var a = new Vector3( x, y, z );
  38657. var b = new Vector3( - x, - y, - z );
  38658. var c = new Vector3();
  38659. var result = a.dot( b );
  38660. assert.ok( result == ( - x * x - y * y - z * z ), "Passed!" );
  38661. var result = a.dot( c );
  38662. assert.ok( result == 0, "Passed!" );
  38663. } );
  38664. QUnit.test( "lengthSq", ( assert ) => {
  38665. assert.ok( false, "everything's gonna be alright" );
  38666. } );
  38667. QUnit.test( "length", ( assert ) => {
  38668. assert.ok( false, "everything's gonna be alright" );
  38669. } );
  38670. QUnit.test( "manhattanLength", ( assert ) => {
  38671. var a = new Vector3( x, 0, 0 );
  38672. var b = new Vector3( 0, - y, 0 );
  38673. var c = new Vector3( 0, 0, z );
  38674. var d = new Vector3();
  38675. assert.ok( a.manhattanLength() == x, "Positive x" );
  38676. assert.ok( b.manhattanLength() == y, "Negative y" );
  38677. assert.ok( c.manhattanLength() == z, "Positive z" );
  38678. assert.ok( d.manhattanLength() == 0, "Empty initialization" );
  38679. a.set( x, y, z );
  38680. assert.ok( a.manhattanLength() == Math.abs( x ) + Math.abs( y ) + Math.abs( z ), "All components" );
  38681. } );
  38682. QUnit.test( "normalize", ( assert ) => {
  38683. var a = new Vector3( x, 0, 0 );
  38684. var b = new Vector3( 0, - y, 0 );
  38685. var c = new Vector3( 0, 0, z );
  38686. a.normalize();
  38687. assert.ok( a.length() == 1, "Passed!" );
  38688. assert.ok( a.x == 1, "Passed!" );
  38689. b.normalize();
  38690. assert.ok( b.length() == 1, "Passed!" );
  38691. assert.ok( b.y == - 1, "Passed!" );
  38692. c.normalize();
  38693. assert.ok( c.length() == 1, "Passed!" );
  38694. assert.ok( c.z == 1, "Passed!" );
  38695. } );
  38696. QUnit.test( "setLength", ( assert ) => {
  38697. var a = new Vector3( x, 0, 0 );
  38698. assert.ok( a.length() == x, "Passed!" );
  38699. a.setLength( y );
  38700. assert.ok( a.length() == y, "Passed!" );
  38701. var a = new Vector3( 0, 0, 0 );
  38702. assert.ok( a.length() == 0, "Passed!" );
  38703. a.setLength( y );
  38704. assert.ok( a.length() == 0, "Passed!" );
  38705. a.setLength();
  38706. assert.ok( isNaN( a.length() ), "Passed!" );
  38707. } );
  38708. QUnit.test( "lerp", ( assert ) => {
  38709. assert.ok( false, "everything's gonna be alright" );
  38710. } );
  38711. QUnit.test( "lerpVectors", ( assert ) => {
  38712. assert.ok( false, "everything's gonna be alright" );
  38713. } );
  38714. QUnit.test( "cross", ( assert ) => {
  38715. var a = new Vector3( x, y, z );
  38716. var b = new Vector3( 2 * x, - y, 0.5 * z );
  38717. var crossed = new Vector3( 18, 12, - 18 );
  38718. a.cross( b );
  38719. assert.ok( Math.abs( a.x - crossed.x ) <= eps, "Check x" );
  38720. assert.ok( Math.abs( a.y - crossed.y ) <= eps, "Check y" );
  38721. assert.ok( Math.abs( a.z - crossed.z ) <= eps, "Check z" );
  38722. } );
  38723. QUnit.test( "crossVectors", ( assert ) => {
  38724. var a = new Vector3( x, y, z );
  38725. var b = new Vector3( x, - y, z );
  38726. var c = new Vector3();
  38727. var crossed = new Vector3( 24, 0, - 12 );
  38728. c.crossVectors( a, b );
  38729. assert.ok( Math.abs( c.x - crossed.x ) <= eps, "Check x" );
  38730. assert.ok( Math.abs( c.y - crossed.y ) <= eps, "Check y" );
  38731. assert.ok( Math.abs( c.z - crossed.z ) <= eps, "Check z" );
  38732. } );
  38733. QUnit.test( "projectOnVector", ( assert ) => {
  38734. var a = new Vector3( 1, 0, 0 );
  38735. var b = new Vector3();
  38736. var normal = new Vector3( 10, 0, 0 );
  38737. assert.ok( b.copy( a ).projectOnVector( normal ).equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  38738. a.set( 0, 1, 0 );
  38739. assert.ok( b.copy( a ).projectOnVector( normal ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  38740. a.set( 0, 0, - 1 );
  38741. assert.ok( b.copy( a ).projectOnVector( normal ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  38742. a.set( - 1, 0, 0 );
  38743. assert.ok( b.copy( a ).projectOnVector( normal ).equals( new Vector3( - 1, 0, 0 ) ), "Passed!" );
  38744. } );
  38745. QUnit.test( "projectOnPlane", ( assert ) => {
  38746. var a = new Vector3( 1, 0, 0 );
  38747. var b = new Vector3();
  38748. var normal = new Vector3( 1, 0, 0 );
  38749. assert.ok( b.copy( a ).projectOnPlane( normal ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  38750. a.set( 0, 1, 0 );
  38751. assert.ok( b.copy( a ).projectOnPlane( normal ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  38752. a.set( 0, 0, - 1 );
  38753. assert.ok( b.copy( a ).projectOnPlane( normal ).equals( new Vector3( 0, 0, - 1 ) ), "Passed!" );
  38754. a.set( - 1, 0, 0 );
  38755. assert.ok( b.copy( a ).projectOnPlane( normal ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  38756. } );
  38757. QUnit.test( "reflect", ( assert ) => {
  38758. var a = new Vector3();
  38759. var normal = new Vector3( 0, 1, 0 );
  38760. var b = new Vector3();
  38761. a.set( 0, - 1, 0 );
  38762. assert.ok( b.copy( a ).reflect( normal ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  38763. a.set( 1, - 1, 0 );
  38764. assert.ok( b.copy( a ).reflect( normal ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
  38765. a.set( 1, - 1, 0 );
  38766. normal.set( 0, - 1, 0 );
  38767. assert.ok( b.copy( a ).reflect( normal ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
  38768. } );
  38769. QUnit.test( "angleTo", ( assert ) => {
  38770. var a = new Vector3( 0, - 0.18851655680720186, 0.9820700116639124 );
  38771. var b = new Vector3( 0, 0.18851655680720186, - 0.9820700116639124 );
  38772. assert.equal( a.angleTo( a ), 0 );
  38773. assert.equal( a.angleTo( b ), Math.PI );
  38774. var x$$1 = new Vector3( 1, 0, 0 );
  38775. var y$$1 = new Vector3( 0, 1, 0 );
  38776. var z$$1 = new Vector3( 0, 0, 1 );
  38777. assert.equal( x$$1.angleTo( y$$1 ), Math.PI / 2 );
  38778. assert.equal( x$$1.angleTo( z$$1 ), Math.PI / 2 );
  38779. assert.equal( z$$1.angleTo( x$$1 ), Math.PI / 2 );
  38780. assert.ok( Math.abs( x$$1.angleTo( new Vector3( 1, 1, 0 ) ) - ( Math.PI / 4 ) ) < 0.0000001 );
  38781. } );
  38782. QUnit.test( "distanceTo", ( assert ) => {
  38783. assert.ok( false, "everything's gonna be alright" );
  38784. } );
  38785. QUnit.test( "distanceToSquared", ( assert ) => {
  38786. assert.ok( false, "everything's gonna be alright" );
  38787. } );
  38788. QUnit.test( "manhattanDistanceTo", ( assert ) => {
  38789. assert.ok( false, "everything's gonna be alright" );
  38790. } );
  38791. QUnit.test( "setFromSpherical", ( assert ) => {
  38792. var a = new Vector3();
  38793. var phi = Math.acos( - 0.5 );
  38794. var theta = Math.sqrt( Math.PI ) * phi;
  38795. var sph = new Spherical( 10, phi, theta );
  38796. var expected = new Vector3( - 4.677914006701843, - 5, - 7.288149322420796 );
  38797. a.setFromSpherical( sph );
  38798. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  38799. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  38800. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  38801. } );
  38802. QUnit.test( "setFromCylindrical", ( assert ) => {
  38803. var a = new Vector3();
  38804. var cyl = new Cylindrical( 10, Math.PI * 0.125, 20 );
  38805. var expected = new Vector3( 3.826834323650898, 20, 9.238795325112868 );
  38806. a.setFromCylindrical( cyl );
  38807. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  38808. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  38809. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  38810. } );
  38811. QUnit.test( "setFromMatrixPosition", ( assert ) => {
  38812. var a = new Vector3();
  38813. var m = new Matrix4().set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  38814. a.setFromMatrixPosition( m );
  38815. assert.strictEqual( a.x, 7, "Check x" );
  38816. assert.strictEqual( a.y, 19, "Check y" );
  38817. assert.strictEqual( a.z, 37, "Check z" );
  38818. } );
  38819. QUnit.test( "setFromMatrixScale", ( assert ) => {
  38820. var a = new Vector3();
  38821. var m = new Matrix4().set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  38822. var expected = new Vector3( 25.573423705088842, 31.921779399024736, 35.70714214271425 );
  38823. a.setFromMatrixScale( m );
  38824. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  38825. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  38826. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  38827. } );
  38828. QUnit.test( "setFromMatrixColumn", ( assert ) => {
  38829. var a = new Vector3();
  38830. var m = new Matrix4().set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  38831. a.setFromMatrixColumn( m, 0 );
  38832. assert.strictEqual( a.x, 2, "Index 0: check x" );
  38833. assert.strictEqual( a.y, 11, "Index 0: check y" );
  38834. assert.strictEqual( a.z, 23, "Index 0: check z" );
  38835. a.setFromMatrixColumn( m, 2 );
  38836. assert.strictEqual( a.x, 5, "Index 2: check x" );
  38837. assert.strictEqual( a.y, 17, "Index 2: check y" );
  38838. assert.strictEqual( a.z, 31, "Index 2: check z" );
  38839. } );
  38840. QUnit.test( "equals", ( assert ) => {
  38841. var a = new Vector3( x, 0, z );
  38842. var b = new Vector3( 0, - y, 0 );
  38843. assert.ok( a.x != b.x, "Passed!" );
  38844. assert.ok( a.y != b.y, "Passed!" );
  38845. assert.ok( a.z != b.z, "Passed!" );
  38846. assert.ok( ! a.equals( b ), "Passed!" );
  38847. assert.ok( ! b.equals( a ), "Passed!" );
  38848. a.copy( b );
  38849. assert.ok( a.x == b.x, "Passed!" );
  38850. assert.ok( a.y == b.y, "Passed!" );
  38851. assert.ok( a.z == b.z, "Passed!" );
  38852. assert.ok( a.equals( b ), "Passed!" );
  38853. assert.ok( b.equals( a ), "Passed!" );
  38854. } );
  38855. QUnit.test( "fromArray", ( assert ) => {
  38856. var a = new Vector3();
  38857. var array = [ 1, 2, 3, 4, 5, 6 ];
  38858. a.fromArray( array );
  38859. assert.strictEqual( a.x, 1, "No offset: check x" );
  38860. assert.strictEqual( a.y, 2, "No offset: check y" );
  38861. assert.strictEqual( a.z, 3, "No offset: check z" );
  38862. a.fromArray( array, 3 );
  38863. assert.strictEqual( a.x, 4, "With offset: check x" );
  38864. assert.strictEqual( a.y, 5, "With offset: check y" );
  38865. assert.strictEqual( a.z, 6, "With offset: check z" );
  38866. } );
  38867. QUnit.test( "toArray", ( assert ) => {
  38868. var a = new Vector3( x, y, z );
  38869. var array = a.toArray();
  38870. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  38871. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  38872. assert.strictEqual( array[ 2 ], z, "No array, no offset: check z" );
  38873. var array = [];
  38874. a.toArray( array );
  38875. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  38876. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  38877. assert.strictEqual( array[ 2 ], z, "With array, no offset: check z" );
  38878. var array = [];
  38879. a.toArray( array, 1 );
  38880. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  38881. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  38882. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  38883. assert.strictEqual( array[ 3 ], z, "With array and offset: check z" );
  38884. } );
  38885. QUnit.test( "fromBufferAttribute", ( assert ) => {
  38886. var a = new Vector3();
  38887. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 );
  38888. a.fromBufferAttribute( attr, 0 );
  38889. assert.strictEqual( a.x, 1, "Offset 0: check x" );
  38890. assert.strictEqual( a.y, 2, "Offset 0: check y" );
  38891. assert.strictEqual( a.z, 3, "Offset 0: check z" );
  38892. a.fromBufferAttribute( attr, 1 );
  38893. assert.strictEqual( a.x, 4, "Offset 1: check x" );
  38894. assert.strictEqual( a.y, 5, "Offset 1: check y" );
  38895. assert.strictEqual( a.z, 6, "Offset 1: check z" );
  38896. } );
  38897. // TODO (Itee) refactor/split
  38898. QUnit.test( "setX,setY,setZ", ( assert ) => {
  38899. var a = new Vector3();
  38900. assert.ok( a.x == 0, "Passed!" );
  38901. assert.ok( a.y == 0, "Passed!" );
  38902. assert.ok( a.z == 0, "Passed!" );
  38903. a.setX( x );
  38904. a.setY( y );
  38905. a.setZ( z );
  38906. assert.ok( a.x == x, "Passed!" );
  38907. assert.ok( a.y == y, "Passed!" );
  38908. assert.ok( a.z == z, "Passed!" );
  38909. } );
  38910. QUnit.test( "setComponent,getComponent", ( assert ) => {
  38911. var a = new Vector3();
  38912. assert.ok( a.x == 0, "Passed!" );
  38913. assert.ok( a.y == 0, "Passed!" );
  38914. assert.ok( a.z == 0, "Passed!" );
  38915. a.setComponent( 0, 1 );
  38916. a.setComponent( 1, 2 );
  38917. a.setComponent( 2, 3 );
  38918. assert.ok( a.getComponent( 0 ) == 1, "Passed!" );
  38919. assert.ok( a.getComponent( 1 ) == 2, "Passed!" );
  38920. assert.ok( a.getComponent( 2 ) == 3, "Passed!" );
  38921. } );
  38922. QUnit.test( "setComponent/getComponent exceptions", ( assert ) => {
  38923. var a = new Vector3();
  38924. assert.throws(
  38925. function () {
  38926. a.setComponent( 3, 0 );
  38927. },
  38928. /index is out of range/,
  38929. "setComponent with an out of range index throws Error"
  38930. );
  38931. assert.throws(
  38932. function () {
  38933. a.getComponent( 3 );
  38934. },
  38935. /index is out of range/,
  38936. "getComponent with an out of range index throws Error"
  38937. );
  38938. } );
  38939. QUnit.test( "min/max/clamp", ( assert ) => {
  38940. var a = new Vector3( x, y, z );
  38941. var b = new Vector3( - x, - y, - z );
  38942. var c = new Vector3();
  38943. c.copy( a ).min( b );
  38944. assert.ok( c.x == - x, "Passed!" );
  38945. assert.ok( c.y == - y, "Passed!" );
  38946. assert.ok( c.z == - z, "Passed!" );
  38947. c.copy( a ).max( b );
  38948. assert.ok( c.x == x, "Passed!" );
  38949. assert.ok( c.y == y, "Passed!" );
  38950. assert.ok( c.z == z, "Passed!" );
  38951. c.set( - 2 * x, 2 * y, - 2 * z );
  38952. c.clamp( b, a );
  38953. assert.ok( c.x == - x, "Passed!" );
  38954. assert.ok( c.y == y, "Passed!" );
  38955. assert.ok( c.z == - z, "Passed!" );
  38956. } );
  38957. QUnit.test( "distanceTo/distanceToSquared", ( assert ) => {
  38958. var a = new Vector3( x, 0, 0 );
  38959. var b = new Vector3( 0, - y, 0 );
  38960. var c = new Vector3( 0, 0, z );
  38961. var d = new Vector3();
  38962. assert.ok( a.distanceTo( d ) == x, "Passed!" );
  38963. assert.ok( a.distanceToSquared( d ) == x * x, "Passed!" );
  38964. assert.ok( b.distanceTo( d ) == y, "Passed!" );
  38965. assert.ok( b.distanceToSquared( d ) == y * y, "Passed!" );
  38966. assert.ok( c.distanceTo( d ) == z, "Passed!" );
  38967. assert.ok( c.distanceToSquared( d ) == z * z, "Passed!" );
  38968. } );
  38969. QUnit.test( "setScalar/addScalar/subScalar", ( assert ) => {
  38970. var a = new Vector3();
  38971. var s = 3;
  38972. a.setScalar( s );
  38973. assert.strictEqual( a.x, s, "setScalar: check x" );
  38974. assert.strictEqual( a.y, s, "setScalar: check y" );
  38975. assert.strictEqual( a.z, s, "setScalar: check z" );
  38976. a.addScalar( s );
  38977. assert.strictEqual( a.x, 2 * s, "addScalar: check x" );
  38978. assert.strictEqual( a.y, 2 * s, "addScalar: check y" );
  38979. assert.strictEqual( a.z, 2 * s, "addScalar: check z" );
  38980. a.subScalar( 2 * s );
  38981. assert.strictEqual( a.x, 0, "subScalar: check x" );
  38982. assert.strictEqual( a.y, 0, "subScalar: check y" );
  38983. assert.strictEqual( a.z, 0, "subScalar: check z" );
  38984. } );
  38985. QUnit.test( "multiply/divide", ( assert ) => {
  38986. var a = new Vector3( x, y, z );
  38987. var b = new Vector3( 2 * x, 2 * y, 2 * z );
  38988. var c = new Vector3( 4 * x, 4 * y, 4 * z );
  38989. a.multiply( b );
  38990. assert.strictEqual( a.x, x * b.x, "multiply: check x" );
  38991. assert.strictEqual( a.y, y * b.y, "multiply: check y" );
  38992. assert.strictEqual( a.z, z * b.z, "multiply: check z" );
  38993. b.divide( c );
  38994. assert.ok( Math.abs( b.x - 0.5 ) <= eps, "divide: check z" );
  38995. assert.ok( Math.abs( b.y - 0.5 ) <= eps, "divide: check z" );
  38996. assert.ok( Math.abs( b.z - 0.5 ) <= eps, "divide: check z" );
  38997. } );
  38998. QUnit.test( "multiply/divide", ( assert ) => {
  38999. var a = new Vector3( x, y, z );
  39000. var b = new Vector3( - x, - y, - z );
  39001. a.multiplyScalar( - 2 );
  39002. assert.ok( a.x == x * - 2, "Passed!" );
  39003. assert.ok( a.y == y * - 2, "Passed!" );
  39004. assert.ok( a.z == z * - 2, "Passed!" );
  39005. b.multiplyScalar( - 2 );
  39006. assert.ok( b.x == 2 * x, "Passed!" );
  39007. assert.ok( b.y == 2 * y, "Passed!" );
  39008. assert.ok( b.z == 2 * z, "Passed!" );
  39009. a.divideScalar( - 2 );
  39010. assert.ok( a.x == x, "Passed!" );
  39011. assert.ok( a.y == y, "Passed!" );
  39012. assert.ok( a.z == z, "Passed!" );
  39013. b.divideScalar( - 2 );
  39014. assert.ok( b.x == - x, "Passed!" );
  39015. assert.ok( b.y == - y, "Passed!" );
  39016. assert.ok( b.z == - z, "Passed!" );
  39017. } );
  39018. QUnit.test( "project/unproject", ( assert ) => {
  39019. var a = new Vector3( x, y, z );
  39020. var camera = new PerspectiveCamera( 75, 16 / 9, 0.1, 300.0 );
  39021. var projected = new Vector3( - 0.36653213611158914, - 0.9774190296309043, 1.0506835611870624 );
  39022. a.project( camera );
  39023. assert.ok( Math.abs( a.x - projected.x ) <= eps, "project: check x" );
  39024. assert.ok( Math.abs( a.y - projected.y ) <= eps, "project: check y" );
  39025. assert.ok( Math.abs( a.z - projected.z ) <= eps, "project: check z" );
  39026. a.unproject( camera );
  39027. assert.ok( Math.abs( a.x - x ) <= eps, "unproject: check x" );
  39028. assert.ok( Math.abs( a.y - y ) <= eps, "unproject: check y" );
  39029. assert.ok( Math.abs( a.z - z ) <= eps, "unproject: check z" );
  39030. } );
  39031. QUnit.test( "length/lengthSq", ( assert ) => {
  39032. var a = new Vector3( x, 0, 0 );
  39033. var b = new Vector3( 0, - y, 0 );
  39034. var c = new Vector3( 0, 0, z );
  39035. var d = new Vector3();
  39036. assert.ok( a.length() == x, "Passed!" );
  39037. assert.ok( a.lengthSq() == x * x, "Passed!" );
  39038. assert.ok( b.length() == y, "Passed!" );
  39039. assert.ok( b.lengthSq() == y * y, "Passed!" );
  39040. assert.ok( c.length() == z, "Passed!" );
  39041. assert.ok( c.lengthSq() == z * z, "Passed!" );
  39042. assert.ok( d.length() == 0, "Passed!" );
  39043. assert.ok( d.lengthSq() == 0, "Passed!" );
  39044. a.set( x, y, z );
  39045. assert.ok( a.length() == Math.sqrt( x * x + y * y + z * z ), "Passed!" );
  39046. assert.ok( a.lengthSq() == ( x * x + y * y + z * z ), "Passed!" );
  39047. } );
  39048. QUnit.test( "lerp/clone", ( assert ) => {
  39049. var a = new Vector3( x, 0, z );
  39050. var b = new Vector3( 0, - y, 0 );
  39051. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 0.5 ) ), "Passed!" );
  39052. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 1 ) ), "Passed!" );
  39053. assert.ok( a.clone().lerp( b, 0 ).equals( a ), "Passed!" );
  39054. assert.ok( a.clone().lerp( b, 0.5 ).x == x * 0.5, "Passed!" );
  39055. assert.ok( a.clone().lerp( b, 0.5 ).y == - y * 0.5, "Passed!" );
  39056. assert.ok( a.clone().lerp( b, 0.5 ).z == z * 0.5, "Passed!" );
  39057. assert.ok( a.clone().lerp( b, 1 ).equals( b ), "Passed!" );
  39058. } );
  39059. } );
  39060. } );
  39061. /**
  39062. * @author bhouston / http://exocortex.com
  39063. * @author TristanVALCKE / https://github.com/Itee
  39064. */
  39065. /* global QUnit */
  39066. QUnit.module( 'Maths', () => {
  39067. QUnit.module.todo( 'Vector4', () => {
  39068. // INSTANCING
  39069. QUnit.test( "Instancing", ( assert ) => {
  39070. var a = new Vector4();
  39071. assert.ok( a.x == 0, "Passed!" );
  39072. assert.ok( a.y == 0, "Passed!" );
  39073. assert.ok( a.z == 0, "Passed!" );
  39074. assert.ok( a.w == 1, "Passed!" );
  39075. var a = new Vector4( x, y, z, w );
  39076. assert.ok( a.x === x, "Passed!" );
  39077. assert.ok( a.y === y, "Passed!" );
  39078. assert.ok( a.z === z, "Passed!" );
  39079. assert.ok( a.w === w, "Passed!" );
  39080. } );
  39081. // PUBLIC STUFF
  39082. QUnit.test( "isVector4", ( assert ) => {
  39083. assert.ok( false, "everything's gonna be alright" );
  39084. } );
  39085. QUnit.test( "set", ( assert ) => {
  39086. var a = new Vector4();
  39087. assert.ok( a.x == 0, "Passed!" );
  39088. assert.ok( a.y == 0, "Passed!" );
  39089. assert.ok( a.z == 0, "Passed!" );
  39090. assert.ok( a.w == 1, "Passed!" );
  39091. a.set( x, y, z, w );
  39092. assert.ok( a.x == x, "Passed!" );
  39093. assert.ok( a.y == y, "Passed!" );
  39094. assert.ok( a.z == z, "Passed!" );
  39095. assert.ok( a.w == w, "Passed!" );
  39096. } );
  39097. QUnit.test( "setScalar", ( assert ) => {
  39098. assert.ok( false, "everything's gonna be alright" );
  39099. } );
  39100. QUnit.test( "setX", ( assert ) => {
  39101. assert.ok( false, "everything's gonna be alright" );
  39102. } );
  39103. QUnit.test( "setY", ( assert ) => {
  39104. assert.ok( false, "everything's gonna be alright" );
  39105. } );
  39106. QUnit.test( "setZ", ( assert ) => {
  39107. assert.ok( false, "everything's gonna be alright" );
  39108. } );
  39109. QUnit.test( "setW", ( assert ) => {
  39110. assert.ok( false, "everything's gonna be alright" );
  39111. } );
  39112. QUnit.test( "setComponent", ( assert ) => {
  39113. assert.ok( false, "everything's gonna be alright" );
  39114. } );
  39115. QUnit.test( "getComponent", ( assert ) => {
  39116. assert.ok( false, "everything's gonna be alright" );
  39117. } );
  39118. QUnit.test( "clone", ( assert ) => {
  39119. assert.ok( false, "everything's gonna be alright" );
  39120. } );
  39121. QUnit.test( "copy", ( assert ) => {
  39122. var a = new Vector4( x, y, z, w );
  39123. var b = new Vector4().copy( a );
  39124. assert.ok( b.x == x, "Passed!" );
  39125. assert.ok( b.y == y, "Passed!" );
  39126. assert.ok( b.z == z, "Passed!" );
  39127. assert.ok( b.w == w, "Passed!" );
  39128. // ensure that it is a true copy
  39129. a.x = 0;
  39130. a.y = - 1;
  39131. a.z = - 2;
  39132. a.w = - 3;
  39133. assert.ok( b.x == x, "Passed!" );
  39134. assert.ok( b.y == y, "Passed!" );
  39135. assert.ok( b.z == z, "Passed!" );
  39136. assert.ok( b.w == w, "Passed!" );
  39137. } );
  39138. QUnit.test( "add", ( assert ) => {
  39139. var a = new Vector4( x, y, z, w );
  39140. var b = new Vector4( - x, - y, - z, - w );
  39141. a.add( b );
  39142. assert.ok( a.x == 0, "Passed!" );
  39143. assert.ok( a.y == 0, "Passed!" );
  39144. assert.ok( a.z == 0, "Passed!" );
  39145. assert.ok( a.w == 0, "Passed!" );
  39146. var c = new Vector4().addVectors( b, b );
  39147. assert.ok( c.x == - 2 * x, "Passed!" );
  39148. assert.ok( c.y == - 2 * y, "Passed!" );
  39149. assert.ok( c.z == - 2 * z, "Passed!" );
  39150. assert.ok( c.w == - 2 * w, "Passed!" );
  39151. } );
  39152. QUnit.test( "addScalar", ( assert ) => {
  39153. assert.ok( false, "everything's gonna be alright" );
  39154. } );
  39155. QUnit.test( "addVectors", ( assert ) => {
  39156. assert.ok( false, "everything's gonna be alright" );
  39157. } );
  39158. QUnit.test( "addScaledVector", ( assert ) => {
  39159. var a = new Vector4( x, y, z, w );
  39160. var b = new Vector4( 6, 7, 8, 9 );
  39161. var s = 3;
  39162. a.addScaledVector( b, s );
  39163. assert.strictEqual( a.x, x + b.x * s, "Check x" );
  39164. assert.strictEqual( a.y, y + b.y * s, "Check y" );
  39165. assert.strictEqual( a.z, z + b.z * s, "Check z" );
  39166. assert.strictEqual( a.w, w + b.w * s, "Check w" );
  39167. } );
  39168. QUnit.test( "sub", ( assert ) => {
  39169. var a = new Vector4( x, y, z, w );
  39170. var b = new Vector4( - x, - y, - z, - w );
  39171. a.sub( b );
  39172. assert.ok( a.x == 2 * x, "Passed!" );
  39173. assert.ok( a.y == 2 * y, "Passed!" );
  39174. assert.ok( a.z == 2 * z, "Passed!" );
  39175. assert.ok( a.w == 2 * w, "Passed!" );
  39176. var c = new Vector4().subVectors( a, a );
  39177. assert.ok( c.x == 0, "Passed!" );
  39178. assert.ok( c.y == 0, "Passed!" );
  39179. assert.ok( c.z == 0, "Passed!" );
  39180. assert.ok( c.w == 0, "Passed!" );
  39181. } );
  39182. QUnit.test( "subScalar", ( assert ) => {
  39183. assert.ok( false, "everything's gonna be alright" );
  39184. } );
  39185. QUnit.test( "subVectors", ( assert ) => {
  39186. assert.ok( false, "everything's gonna be alright" );
  39187. } );
  39188. QUnit.test( "multiplyScalar", ( assert ) => {
  39189. assert.ok( false, "everything's gonna be alright" );
  39190. } );
  39191. QUnit.test( "applyMatrix4", ( assert ) => {
  39192. var a = new Vector4( x, y, z, w );
  39193. var m = new Matrix4().makeRotationX( Math.PI );
  39194. var expected = new Vector4( 2, - 3, - 4, 5 );
  39195. a.applyMatrix4( m );
  39196. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Rotation matrix: check x" );
  39197. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Rotation matrix: check y" );
  39198. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Rotation matrix: check z" );
  39199. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Rotation matrix: check w" );
  39200. a.set( x, y, z, w );
  39201. m.makeTranslation( 5, 7, 11 );
  39202. expected.set( 27, 38, 59, 5 );
  39203. a.applyMatrix4( m );
  39204. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Translation matrix: check x" );
  39205. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Translation matrix: check y" );
  39206. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Translation matrix: check z" );
  39207. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Translation matrix: check w" );
  39208. a.set( x, y, z, w );
  39209. m.set( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 );
  39210. expected.set( 2, 3, 4, 4 );
  39211. a.applyMatrix4( m );
  39212. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Custom matrix: check x" );
  39213. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Custom matrix: check y" );
  39214. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Custom matrix: check z" );
  39215. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Custom matrix: check w" );
  39216. a.set( x, y, z, w );
  39217. m.set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  39218. expected.set( 68, 224, 442, 664 );
  39219. a.applyMatrix4( m );
  39220. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Bogus matrix: check x" );
  39221. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Bogus matrix: check y" );
  39222. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Bogus matrix: check z" );
  39223. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Bogus matrix: check w" );
  39224. } );
  39225. QUnit.test( "divideScalar", ( assert ) => {
  39226. assert.ok( false, "everything's gonna be alright" );
  39227. } );
  39228. QUnit.test( "setAxisAngleFromQuaternion", ( assert ) => {
  39229. assert.ok( false, "everything's gonna be alright" );
  39230. } );
  39231. QUnit.test( "setAxisAngleFromRotationMatrix", ( assert ) => {
  39232. assert.ok( false, "everything's gonna be alright" );
  39233. } );
  39234. QUnit.test( "min", ( assert ) => {
  39235. assert.ok( false, "everything's gonna be alright" );
  39236. } );
  39237. QUnit.test( "max", ( assert ) => {
  39238. assert.ok( false, "everything's gonna be alright" );
  39239. } );
  39240. QUnit.test( "clamp", ( assert ) => {
  39241. assert.ok( false, "everything's gonna be alright" );
  39242. } );
  39243. QUnit.test( "clampScalar", ( assert ) => {
  39244. var a = new Vector4( - 0.1, 0.01, 0.5, 1.5 );
  39245. var clamped = new Vector4( 0.1, 0.1, 0.5, 1.0 );
  39246. a.clampScalar( 0.1, 1.0 );
  39247. assert.ok( Math.abs( a.x - clamped.x ) <= eps, "Check x" );
  39248. assert.ok( Math.abs( a.y - clamped.y ) <= eps, "Check y" );
  39249. assert.ok( Math.abs( a.z - clamped.z ) <= eps, "Check z" );
  39250. assert.ok( Math.abs( a.w - clamped.w ) <= eps, "Check w" );
  39251. } );
  39252. QUnit.test( "clampLength", ( assert ) => {
  39253. assert.ok( false, "everything's gonna be alright" );
  39254. } );
  39255. QUnit.test( "floor", ( assert ) => {
  39256. assert.ok( false, "everything's gonna be alright" );
  39257. } );
  39258. QUnit.test( "ceil", ( assert ) => {
  39259. assert.ok( false, "everything's gonna be alright" );
  39260. } );
  39261. QUnit.test( "round", ( assert ) => {
  39262. assert.ok( false, "everything's gonna be alright" );
  39263. } );
  39264. QUnit.test( "roundToZero", ( assert ) => {
  39265. assert.ok( false, "everything's gonna be alright" );
  39266. } );
  39267. QUnit.test( "negate", ( assert ) => {
  39268. var a = new Vector4( x, y, z, w );
  39269. a.negate();
  39270. assert.ok( a.x == - x, "Passed!" );
  39271. assert.ok( a.y == - y, "Passed!" );
  39272. assert.ok( a.z == - z, "Passed!" );
  39273. assert.ok( a.w == - w, "Passed!" );
  39274. } );
  39275. QUnit.test( "dot", ( assert ) => {
  39276. var a = new Vector4( x, y, z, w );
  39277. var b = new Vector4( - x, - y, - z, - w );
  39278. var c = new Vector4( 0, 0, 0, 0 );
  39279. var result = a.dot( b );
  39280. assert.ok( result == ( - x * x - y * y - z * z - w * w ), "Passed!" );
  39281. var result = a.dot( c );
  39282. assert.ok( result == 0, "Passed!" );
  39283. } );
  39284. QUnit.test( "lengthSq", ( assert ) => {
  39285. assert.ok( false, "everything's gonna be alright" );
  39286. } );
  39287. QUnit.test( "length", ( assert ) => {
  39288. assert.ok( false, "everything's gonna be alright" );
  39289. } );
  39290. QUnit.test( "manhattanLength", ( assert ) => {
  39291. var a = new Vector4( x, 0, 0, 0 );
  39292. var b = new Vector4( 0, - y, 0, 0 );
  39293. var c = new Vector4( 0, 0, z, 0 );
  39294. var d = new Vector4( 0, 0, 0, w );
  39295. var e = new Vector4( 0, 0, 0, 0 );
  39296. assert.ok( a.manhattanLength() == x, "Positive x" );
  39297. assert.ok( b.manhattanLength() == y, "Negative y" );
  39298. assert.ok( c.manhattanLength() == z, "Positive z" );
  39299. assert.ok( d.manhattanLength() == w, "Positive w" );
  39300. assert.ok( e.manhattanLength() == 0, "Empty initialization" );
  39301. a.set( x, y, z, w );
  39302. assert.ok(
  39303. a.manhattanLength() == Math.abs( x ) + Math.abs( y ) + Math.abs( z ) + Math.abs( w ),
  39304. "All components"
  39305. );
  39306. } );
  39307. QUnit.test( "normalize", ( assert ) => {
  39308. var a = new Vector4( x, 0, 0, 0 );
  39309. var b = new Vector4( 0, - y, 0, 0 );
  39310. var c = new Vector4( 0, 0, z, 0 );
  39311. var d = new Vector4( 0, 0, 0, - w );
  39312. a.normalize();
  39313. assert.ok( a.length() == 1, "Passed!" );
  39314. assert.ok( a.x == 1, "Passed!" );
  39315. b.normalize();
  39316. assert.ok( b.length() == 1, "Passed!" );
  39317. assert.ok( b.y == - 1, "Passed!" );
  39318. c.normalize();
  39319. assert.ok( c.length() == 1, "Passed!" );
  39320. assert.ok( c.z == 1, "Passed!" );
  39321. d.normalize();
  39322. assert.ok( d.length() == 1, "Passed!" );
  39323. assert.ok( d.w == - 1, "Passed!" );
  39324. } );
  39325. QUnit.test( "setLength", ( assert ) => {
  39326. var a = new Vector4( x, 0, 0, 0 );
  39327. assert.ok( a.length() == x, "Passed!" );
  39328. a.setLength( y );
  39329. assert.ok( a.length() == y, "Passed!" );
  39330. var a = new Vector4( 0, 0, 0, 0 );
  39331. assert.ok( a.length() == 0, "Passed!" );
  39332. a.setLength( y );
  39333. assert.ok( a.length() == 0, "Passed!" );
  39334. a.setLength();
  39335. assert.ok( isNaN( a.length() ), "Passed!" );
  39336. } );
  39337. QUnit.test( "lerp", ( assert ) => {
  39338. assert.ok( false, "everything's gonna be alright" );
  39339. } );
  39340. QUnit.test( "lerpVectors", ( assert ) => {
  39341. assert.ok( false, "everything's gonna be alright" );
  39342. } );
  39343. QUnit.test( "equals", ( assert ) => {
  39344. var a = new Vector4( x, 0, z, 0 );
  39345. var b = new Vector4( 0, - y, 0, - w );
  39346. assert.ok( a.x != b.x, "Passed!" );
  39347. assert.ok( a.y != b.y, "Passed!" );
  39348. assert.ok( a.z != b.z, "Passed!" );
  39349. assert.ok( a.w != b.w, "Passed!" );
  39350. assert.ok( ! a.equals( b ), "Passed!" );
  39351. assert.ok( ! b.equals( a ), "Passed!" );
  39352. a.copy( b );
  39353. assert.ok( a.x == b.x, "Passed!" );
  39354. assert.ok( a.y == b.y, "Passed!" );
  39355. assert.ok( a.z == b.z, "Passed!" );
  39356. assert.ok( a.w == b.w, "Passed!" );
  39357. assert.ok( a.equals( b ), "Passed!" );
  39358. assert.ok( b.equals( a ), "Passed!" );
  39359. } );
  39360. QUnit.test( "fromArray", ( assert ) => {
  39361. var a = new Vector4();
  39362. var array = [ 1, 2, 3, 4, 5, 6, 7, 8 ];
  39363. a.fromArray( array );
  39364. assert.strictEqual( a.x, 1, "No offset: check x" );
  39365. assert.strictEqual( a.y, 2, "No offset: check y" );
  39366. assert.strictEqual( a.z, 3, "No offset: check z" );
  39367. assert.strictEqual( a.w, 4, "No offset: check w" );
  39368. a.fromArray( array, 4 );
  39369. assert.strictEqual( a.x, 5, "With offset: check x" );
  39370. assert.strictEqual( a.y, 6, "With offset: check y" );
  39371. assert.strictEqual( a.z, 7, "With offset: check z" );
  39372. assert.strictEqual( a.w, 8, "With offset: check w" );
  39373. } );
  39374. QUnit.test( "toArray", ( assert ) => {
  39375. var a = new Vector4( x, y, z, w );
  39376. var array = a.toArray();
  39377. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  39378. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  39379. assert.strictEqual( array[ 2 ], z, "No array, no offset: check z" );
  39380. assert.strictEqual( array[ 3 ], w, "No array, no offset: check w" );
  39381. var array = [];
  39382. a.toArray( array );
  39383. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  39384. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  39385. assert.strictEqual( array[ 2 ], z, "With array, no offset: check z" );
  39386. assert.strictEqual( array[ 3 ], w, "With array, no offset: check w" );
  39387. var array = [];
  39388. a.toArray( array, 1 );
  39389. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  39390. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  39391. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  39392. assert.strictEqual( array[ 3 ], z, "With array and offset: check z" );
  39393. assert.strictEqual( array[ 4 ], w, "With array and offset: check w" );
  39394. } );
  39395. QUnit.test( "fromBufferAttribute", ( assert ) => {
  39396. var a = new Vector4();
  39397. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ), 4 );
  39398. a.fromBufferAttribute( attr, 0 );
  39399. assert.strictEqual( a.x, 1, "Offset 0: check x" );
  39400. assert.strictEqual( a.y, 2, "Offset 0: check y" );
  39401. assert.strictEqual( a.z, 3, "Offset 0: check z" );
  39402. assert.strictEqual( a.w, 4, "Offset 0: check w" );
  39403. a.fromBufferAttribute( attr, 1 );
  39404. assert.strictEqual( a.x, 5, "Offset 1: check x" );
  39405. assert.strictEqual( a.y, 6, "Offset 1: check y" );
  39406. assert.strictEqual( a.z, 7, "Offset 1: check z" );
  39407. assert.strictEqual( a.w, 8, "Offset 1: check w" );
  39408. } );
  39409. // TODO (Itee) refactor/split
  39410. QUnit.test( "setX,setY,setZ,setW", ( assert ) => {
  39411. var a = new Vector4();
  39412. assert.ok( a.x == 0, "Passed!" );
  39413. assert.ok( a.y == 0, "Passed!" );
  39414. assert.ok( a.z == 0, "Passed!" );
  39415. assert.ok( a.w == 1, "Passed!" );
  39416. a.setX( x );
  39417. a.setY( y );
  39418. a.setZ( z );
  39419. a.setW( w );
  39420. assert.ok( a.x == x, "Passed!" );
  39421. assert.ok( a.y == y, "Passed!" );
  39422. assert.ok( a.z == z, "Passed!" );
  39423. assert.ok( a.w == w, "Passed!" );
  39424. } );
  39425. QUnit.test( "setComponent,getComponent", ( assert ) => {
  39426. var a = new Vector4();
  39427. assert.ok( a.x == 0, "Passed!" );
  39428. assert.ok( a.y == 0, "Passed!" );
  39429. assert.ok( a.z == 0, "Passed!" );
  39430. assert.ok( a.w == 1, "Passed!" );
  39431. a.setComponent( 0, 1 );
  39432. a.setComponent( 1, 2 );
  39433. a.setComponent( 2, 3 );
  39434. a.setComponent( 3, 4 );
  39435. assert.ok( a.getComponent( 0 ) == 1, "Passed!" );
  39436. assert.ok( a.getComponent( 1 ) == 2, "Passed!" );
  39437. assert.ok( a.getComponent( 2 ) == 3, "Passed!" );
  39438. assert.ok( a.getComponent( 3 ) == 4, "Passed!" );
  39439. } );
  39440. QUnit.test( "setComponent/getComponent exceptions", ( assert ) => {
  39441. var a = new Vector4();
  39442. assert.throws(
  39443. function () {
  39444. a.setComponent( 4, 0 );
  39445. },
  39446. /index is out of range/,
  39447. "setComponent with an out of range index throws Error"
  39448. );
  39449. assert.throws(
  39450. function () {
  39451. a.getComponent( 4 );
  39452. },
  39453. /index is out of range/,
  39454. "getComponent with an out of range index throws Error"
  39455. );
  39456. } );
  39457. QUnit.test( "setScalar/addScalar/subScalar", ( assert ) => {
  39458. var a = new Vector4();
  39459. var s = 3;
  39460. a.setScalar( s );
  39461. assert.strictEqual( a.x, s, "setScalar: check x" );
  39462. assert.strictEqual( a.y, s, "setScalar: check y" );
  39463. assert.strictEqual( a.z, s, "setScalar: check z" );
  39464. assert.strictEqual( a.w, s, "setScalar: check w" );
  39465. a.addScalar( s );
  39466. assert.strictEqual( a.x, 2 * s, "addScalar: check x" );
  39467. assert.strictEqual( a.y, 2 * s, "addScalar: check y" );
  39468. assert.strictEqual( a.z, 2 * s, "addScalar: check z" );
  39469. assert.strictEqual( a.w, 2 * s, "addScalar: check w" );
  39470. a.subScalar( 2 * s );
  39471. assert.strictEqual( a.x, 0, "subScalar: check x" );
  39472. assert.strictEqual( a.y, 0, "subScalar: check y" );
  39473. assert.strictEqual( a.z, 0, "subScalar: check z" );
  39474. assert.strictEqual( a.w, 0, "subScalar: check w" );
  39475. } );
  39476. QUnit.test( "multiply/divide", ( assert ) => {
  39477. var a = new Vector4( x, y, z, w );
  39478. var b = new Vector4( - x, - y, - z, - w );
  39479. a.multiplyScalar( - 2 );
  39480. assert.ok( a.x == x * - 2, "Passed!" );
  39481. assert.ok( a.y == y * - 2, "Passed!" );
  39482. assert.ok( a.z == z * - 2, "Passed!" );
  39483. assert.ok( a.w == w * - 2, "Passed!" );
  39484. b.multiplyScalar( - 2 );
  39485. assert.ok( b.x == 2 * x, "Passed!" );
  39486. assert.ok( b.y == 2 * y, "Passed!" );
  39487. assert.ok( b.z == 2 * z, "Passed!" );
  39488. assert.ok( b.w == 2 * w, "Passed!" );
  39489. a.divideScalar( - 2 );
  39490. assert.ok( a.x == x, "Passed!" );
  39491. assert.ok( a.y == y, "Passed!" );
  39492. assert.ok( a.z == z, "Passed!" );
  39493. assert.ok( a.w == w, "Passed!" );
  39494. b.divideScalar( - 2 );
  39495. assert.ok( b.x == - x, "Passed!" );
  39496. assert.ok( b.y == - y, "Passed!" );
  39497. assert.ok( b.z == - z, "Passed!" );
  39498. assert.ok( b.w == - w, "Passed!" );
  39499. } );
  39500. QUnit.test( "min/max/clamp", ( assert ) => {
  39501. var a = new Vector4( x, y, z, w );
  39502. var b = new Vector4( - x, - y, - z, - w );
  39503. var c = new Vector4();
  39504. c.copy( a ).min( b );
  39505. assert.ok( c.x == - x, "Passed!" );
  39506. assert.ok( c.y == - y, "Passed!" );
  39507. assert.ok( c.z == - z, "Passed!" );
  39508. assert.ok( c.w == - w, "Passed!" );
  39509. c.copy( a ).max( b );
  39510. assert.ok( c.x == x, "Passed!" );
  39511. assert.ok( c.y == y, "Passed!" );
  39512. assert.ok( c.z == z, "Passed!" );
  39513. assert.ok( c.w == w, "Passed!" );
  39514. c.set( - 2 * x, 2 * y, - 2 * z, 2 * w );
  39515. c.clamp( b, a );
  39516. assert.ok( c.x == - x, "Passed!" );
  39517. assert.ok( c.y == y, "Passed!" );
  39518. assert.ok( c.z == - z, "Passed!" );
  39519. assert.ok( c.w == w, "Passed!" );
  39520. } );
  39521. QUnit.test( "length/lengthSq", ( assert ) => {
  39522. var a = new Vector4( x, 0, 0, 0 );
  39523. var b = new Vector4( 0, - y, 0, 0 );
  39524. var c = new Vector4( 0, 0, z, 0 );
  39525. var d = new Vector4( 0, 0, 0, w );
  39526. var e = new Vector4( 0, 0, 0, 0 );
  39527. assert.ok( a.length() == x, "Passed!" );
  39528. assert.ok( a.lengthSq() == x * x, "Passed!" );
  39529. assert.ok( b.length() == y, "Passed!" );
  39530. assert.ok( b.lengthSq() == y * y, "Passed!" );
  39531. assert.ok( c.length() == z, "Passed!" );
  39532. assert.ok( c.lengthSq() == z * z, "Passed!" );
  39533. assert.ok( d.length() == w, "Passed!" );
  39534. assert.ok( d.lengthSq() == w * w, "Passed!" );
  39535. assert.ok( e.length() == 0, "Passed!" );
  39536. assert.ok( e.lengthSq() == 0, "Passed!" );
  39537. a.set( x, y, z, w );
  39538. assert.ok( a.length() == Math.sqrt( x * x + y * y + z * z + w * w ), "Passed!" );
  39539. assert.ok( a.lengthSq() == ( x * x + y * y + z * z + w * w ), "Passed!" );
  39540. } );
  39541. QUnit.test( "lerp/clone", ( assert ) => {
  39542. var a = new Vector4( x, 0, z, 0 );
  39543. var b = new Vector4( 0, - y, 0, - w );
  39544. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 0.5 ) ), "Passed!" );
  39545. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 1 ) ), "Passed!" );
  39546. assert.ok( a.clone().lerp( b, 0 ).equals( a ), "Passed!" );
  39547. assert.ok( a.clone().lerp( b, 0.5 ).x == x * 0.5, "Passed!" );
  39548. assert.ok( a.clone().lerp( b, 0.5 ).y == - y * 0.5, "Passed!" );
  39549. assert.ok( a.clone().lerp( b, 0.5 ).z == z * 0.5, "Passed!" );
  39550. assert.ok( a.clone().lerp( b, 0.5 ).w == - w * 0.5, "Passed!" );
  39551. assert.ok( a.clone().lerp( b, 1 ).equals( b ), "Passed!" );
  39552. } );
  39553. } );
  39554. } );
  39555. /**
  39556. * @author TristanVALCKE / https://github.com/Itee
  39557. */
  39558. /* global QUnit */
  39559. QUnit.module( 'Maths', () => {
  39560. QUnit.module( 'Interpolants', () => {
  39561. QUnit.module.todo( 'CubicInterpolant', () => {
  39562. // INHERITANCE
  39563. QUnit.test( "Extending", ( assert ) => {
  39564. assert.ok( false, "everything's gonna be alright" );
  39565. } );
  39566. // INSTANCING
  39567. QUnit.test( "Instancing", ( assert ) => {
  39568. assert.ok( false, "everything's gonna be alright" );
  39569. } );
  39570. // PRIVATE STUFF
  39571. QUnit.test( "DefaultSettings_", ( assert ) => {
  39572. assert.ok( false, "everything's gonna be alright" );
  39573. } );
  39574. QUnit.test( "intervalChanged_", ( assert ) => {
  39575. assert.ok( false, "everything's gonna be alright" );
  39576. } );
  39577. QUnit.test( "interpolate_", ( assert ) => {
  39578. assert.ok( false, "everything's gonna be alright" );
  39579. } );
  39580. } );
  39581. } );
  39582. } );
  39583. /**
  39584. * @author TristanVALCKE / https://github.com/Itee
  39585. */
  39586. /* global QUnit */
  39587. QUnit.module( 'Maths', () => {
  39588. QUnit.module( 'Interpolants', () => {
  39589. QUnit.module.todo( 'DiscreteInterpolant', () => {
  39590. // INHERITANCE
  39591. QUnit.test( "Extending", ( assert ) => {
  39592. assert.ok( false, "everything's gonna be alright" );
  39593. } );
  39594. // INSTANCING
  39595. QUnit.test( "Instancing", ( assert ) => {
  39596. assert.ok( false, "everything's gonna be alright" );
  39597. } );
  39598. // PRIVATE STUFF
  39599. QUnit.test( "interpolate_", ( assert ) => {
  39600. assert.ok( false, "everything's gonna be alright" );
  39601. } );
  39602. } );
  39603. } );
  39604. } );
  39605. /**
  39606. * @author TristanVALCKE / https://github.com/Itee
  39607. */
  39608. /* global QUnit */
  39609. QUnit.module( 'Maths', () => {
  39610. QUnit.module( 'Interpolants', () => {
  39611. QUnit.module.todo( 'LinearInterpolant', () => {
  39612. // INHERITANCE
  39613. QUnit.test( "Extending", ( assert ) => {
  39614. assert.ok( false, "everything's gonna be alright" );
  39615. } );
  39616. // INSTANCING
  39617. QUnit.test( "Instancing", ( assert ) => {
  39618. assert.ok( false, "everything's gonna be alright" );
  39619. } );
  39620. // PRIVATE STUFF
  39621. QUnit.test( "interpolate_", ( assert ) => {
  39622. assert.ok( false, "everything's gonna be alright" );
  39623. } );
  39624. } );
  39625. } );
  39626. } );
  39627. /**
  39628. * @author TristanVALCKE / https://github.com/Itee
  39629. */
  39630. /* global QUnit */
  39631. QUnit.module( 'Maths', () => {
  39632. QUnit.module( 'Interpolants', () => {
  39633. QUnit.module.todo( 'QuaternionLinearInterpolant', () => {
  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. // PRIVATE STUFF
  39643. QUnit.test( "interpolate_", ( assert ) => {
  39644. assert.ok( false, "everything's gonna be alright" );
  39645. } );
  39646. } );
  39647. } );
  39648. } );
  39649. /**
  39650. * @author TristanVALCKE / https://github.com/Itee
  39651. */
  39652. /* global QUnit */
  39653. QUnit.module( 'Objects', () => {
  39654. QUnit.module.todo( 'Bone', () => {
  39655. // INHERITANCE
  39656. QUnit.test( "Extending", ( assert ) => {
  39657. assert.ok( false, "everything's gonna be alright" );
  39658. } );
  39659. // INSTANCING
  39660. QUnit.test( "Instancing", ( assert ) => {
  39661. assert.ok( false, "everything's gonna be alright" );
  39662. } );
  39663. // PUBLIC STUFF
  39664. QUnit.test( "isBone", ( assert ) => {
  39665. assert.ok( false, "everything's gonna be alright" );
  39666. } );
  39667. } );
  39668. } );
  39669. /**
  39670. * @author TristanVALCKE / https://github.com/Itee
  39671. */
  39672. /* global QUnit */
  39673. QUnit.module( 'Objects', () => {
  39674. QUnit.module.todo( 'Group', () => {
  39675. // INHERITANCE
  39676. QUnit.test( "Extending", ( assert ) => {
  39677. assert.ok( false, "everything's gonna be alright" );
  39678. } );
  39679. // INSTANCING
  39680. QUnit.test( "Instancing", ( assert ) => {
  39681. assert.ok( false, "everything's gonna be alright" );
  39682. } );
  39683. } );
  39684. } );
  39685. /**
  39686. * @author mikael emtinger / http://gomo.se/
  39687. * @author alteredq / http://alteredqualia.com/
  39688. */
  39689. function LensFlare( texture, size, distance, blending, color ) {
  39690. Object3D.call( this );
  39691. this.lensFlares = [];
  39692. this.positionScreen = new Vector3();
  39693. this.customUpdateCallback = undefined;
  39694. if ( texture !== undefined ) {
  39695. this.add( texture, size, distance, blending, color );
  39696. }
  39697. }
  39698. LensFlare.prototype = Object.assign( Object.create( Object3D.prototype ), {
  39699. constructor: LensFlare,
  39700. isLensFlare: true,
  39701. copy: function ( source ) {
  39702. Object3D.prototype.copy.call( this, source );
  39703. this.positionScreen.copy( source.positionScreen );
  39704. this.customUpdateCallback = source.customUpdateCallback;
  39705. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  39706. this.lensFlares.push( source.lensFlares[ i ] );
  39707. }
  39708. return this;
  39709. },
  39710. add: function ( texture, size, distance, blending, color, opacity ) {
  39711. if ( size === undefined ) size = - 1;
  39712. if ( distance === undefined ) distance = 0;
  39713. if ( opacity === undefined ) opacity = 1;
  39714. if ( color === undefined ) color = new Color( 0xffffff );
  39715. if ( blending === undefined ) blending = NormalBlending;
  39716. distance = Math.min( distance, Math.max( 0, distance ) );
  39717. this.lensFlares.push( {
  39718. texture: texture, // THREE.Texture
  39719. size: size, // size in pixels (-1 = use texture.width)
  39720. distance: distance, // distance (0-1) from light source (0=at light source)
  39721. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  39722. scale: 1, // scale
  39723. rotation: 0, // rotation
  39724. opacity: opacity, // opacity
  39725. color: color, // color
  39726. blending: blending // blending
  39727. } );
  39728. },
  39729. /*
  39730. * Update lens flares update positions on all flares based on the screen position
  39731. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  39732. */
  39733. updateLensFlares: function () {
  39734. var f, fl = this.lensFlares.length;
  39735. var flare;
  39736. var vecX = - this.positionScreen.x * 2;
  39737. var vecY = - this.positionScreen.y * 2;
  39738. for ( f = 0; f < fl; f ++ ) {
  39739. flare = this.lensFlares[ f ];
  39740. flare.x = this.positionScreen.x + vecX * flare.distance;
  39741. flare.y = this.positionScreen.y + vecY * flare.distance;
  39742. flare.wantedRotation = flare.x * Math.PI * 0.25;
  39743. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  39744. }
  39745. }
  39746. } );
  39747. /**
  39748. * @author TristanVALCKE / https://github.com/Itee
  39749. */
  39750. /* global QUnit */
  39751. QUnit.module( 'Objects', () => {
  39752. QUnit.module.todo( 'LensFlare', () => {
  39753. // INHERITANCE
  39754. QUnit.test( "Extending", ( assert ) => {
  39755. assert.ok( false, "everything's gonna be alright" );
  39756. } );
  39757. // INSTANCING
  39758. QUnit.test( "Instancing", ( assert ) => {
  39759. assert.ok( false, "everything's gonna be alright" );
  39760. } );
  39761. // PUBLIC STUFF
  39762. QUnit.test( "isLensFlare", ( assert ) => {
  39763. assert.ok( false, "everything's gonna be alright" );
  39764. } );
  39765. QUnit.test( "copy", ( assert ) => {
  39766. assert.ok( false, "everything's gonna be alright" );
  39767. } );
  39768. QUnit.test( "add", ( assert ) => {
  39769. assert.ok( false, "everything's gonna be alright" );
  39770. } );
  39771. QUnit.test( "updateLensFlares", ( assert ) => {
  39772. assert.ok( false, "everything's gonna be alright" );
  39773. } );
  39774. } );
  39775. } );
  39776. /**
  39777. * @author TristanVALCKE / https://github.com/Itee
  39778. */
  39779. /* global QUnit */
  39780. QUnit.module( 'Objects', () => {
  39781. QUnit.module.todo( 'Line', () => {
  39782. // INHERITANCE
  39783. QUnit.test( "Extending", ( assert ) => {
  39784. assert.ok( false, "everything's gonna be alright" );
  39785. } );
  39786. // INSTANCING
  39787. QUnit.test( "Instancing", ( assert ) => {
  39788. assert.ok( false, "everything's gonna be alright" );
  39789. } );
  39790. // PUBLIC STUFF
  39791. QUnit.test( "isLine", ( assert ) => {
  39792. assert.ok( false, "everything's gonna be alright" );
  39793. } );
  39794. QUnit.test( "raycast", ( assert ) => {
  39795. assert.ok( false, "everything's gonna be alright" );
  39796. } );
  39797. QUnit.test( "clone", ( assert ) => {
  39798. assert.ok( false, "everything's gonna be alright" );
  39799. } );
  39800. } );
  39801. } );
  39802. /**
  39803. * @author TristanVALCKE / https://github.com/Itee
  39804. */
  39805. /* global QUnit */
  39806. QUnit.module( 'Objects', () => {
  39807. QUnit.module.todo( 'LineLoop', () => {
  39808. // INHERITANCE
  39809. QUnit.test( "Extending", ( assert ) => {
  39810. assert.ok( false, "everything's gonna be alright" );
  39811. } );
  39812. // INSTANCING
  39813. QUnit.test( "Instancing", ( assert ) => {
  39814. assert.ok( false, "everything's gonna be alright" );
  39815. } );
  39816. // PUBLIC STUFF
  39817. QUnit.test( "isLineLoop", ( assert ) => {
  39818. assert.ok( false, "everything's gonna be alright" );
  39819. } );
  39820. } );
  39821. } );
  39822. /**
  39823. * @author TristanVALCKE / https://github.com/Itee
  39824. */
  39825. /* global QUnit */
  39826. QUnit.module( 'Objects', () => {
  39827. QUnit.module.todo( 'LineSegments', () => {
  39828. // INHERITANCE
  39829. QUnit.test( "Extending", ( assert ) => {
  39830. assert.ok( false, "everything's gonna be alright" );
  39831. } );
  39832. // INSTANCING
  39833. QUnit.test( "Instancing", ( assert ) => {
  39834. assert.ok( false, "everything's gonna be alright" );
  39835. } );
  39836. // PUBLIC STUFF
  39837. QUnit.test( "isLineSegments", ( assert ) => {
  39838. assert.ok( false, "everything's gonna be alright" );
  39839. } );
  39840. } );
  39841. } );
  39842. /**
  39843. * @author TristanVALCKE / https://github.com/Itee
  39844. */
  39845. /* global QUnit */
  39846. QUnit.module( 'Objects', () => {
  39847. QUnit.module.todo( 'LOD', () => {
  39848. // INHERITANCE
  39849. QUnit.test( "Extending", ( assert ) => {
  39850. assert.ok( false, "everything's gonna be alright" );
  39851. } );
  39852. // INSTANCING
  39853. QUnit.test( "Instancing", ( assert ) => {
  39854. assert.ok( false, "everything's gonna be alright" );
  39855. } );
  39856. // PROPERTIES
  39857. QUnit.test( "levels", ( assert ) => {
  39858. assert.ok( false, "everything's gonna be alright" );
  39859. } );
  39860. // PUBLIC STUFF
  39861. QUnit.test( "isLOD", ( assert ) => {
  39862. assert.ok( false, "everything's gonna be alright" );
  39863. } );
  39864. QUnit.test( "copy", ( assert ) => {
  39865. assert.ok( false, "everything's gonna be alright" );
  39866. } );
  39867. QUnit.test( "addLevel", ( assert ) => {
  39868. assert.ok( false, "everything's gonna be alright" );
  39869. } );
  39870. QUnit.test( "getObjectForDistance", ( assert ) => {
  39871. assert.ok( false, "everything's gonna be alright" );
  39872. } );
  39873. QUnit.test( "raycast", ( assert ) => {
  39874. assert.ok( false, "everything's gonna be alright" );
  39875. } );
  39876. QUnit.test( "update", ( assert ) => {
  39877. assert.ok( false, "everything's gonna be alright" );
  39878. } );
  39879. QUnit.test( "toJSON", ( assert ) => {
  39880. assert.ok( false, "everything's gonna be alright" );
  39881. } );
  39882. } );
  39883. } );
  39884. /**
  39885. * @author TristanVALCKE / https://github.com/Itee
  39886. */
  39887. /* global QUnit */
  39888. QUnit.module( 'Objects', () => {
  39889. QUnit.module.todo( 'Mesh', () => {
  39890. // INHERITANCE
  39891. QUnit.test( "Extending", ( assert ) => {
  39892. assert.ok( false, "everything's gonna be alright" );
  39893. } );
  39894. // INSTANCING
  39895. QUnit.test( "Instancing", ( assert ) => {
  39896. assert.ok( false, "everything's gonna be alright" );
  39897. } );
  39898. // PUBLIC STUFF
  39899. QUnit.test( "isMesh", ( assert ) => {
  39900. assert.ok( false, "everything's gonna be alright" );
  39901. } );
  39902. QUnit.test( "setDrawMode", ( assert ) => {
  39903. assert.ok( false, "everything's gonna be alright" );
  39904. } );
  39905. QUnit.test( "copy", ( assert ) => {
  39906. assert.ok( false, "everything's gonna be alright" );
  39907. } );
  39908. QUnit.test( "updateMorphTargets", ( assert ) => {
  39909. assert.ok( false, "everything's gonna be alright" );
  39910. } );
  39911. QUnit.test( "raycast", ( assert ) => {
  39912. assert.ok( false, "everything's gonna be alright" );
  39913. } );
  39914. QUnit.test( "clone", ( assert ) => {
  39915. assert.ok( false, "everything's gonna be alright" );
  39916. } );
  39917. } );
  39918. } );
  39919. /**
  39920. * @author TristanVALCKE / https://github.com/Itee
  39921. */
  39922. /* global QUnit */
  39923. QUnit.module( 'Objects', () => {
  39924. QUnit.module.todo( 'Points', () => {
  39925. // INHERITANCE
  39926. QUnit.test( "isPoints", ( assert ) => {
  39927. assert.ok( false, "everything's gonna be alright" );
  39928. } );
  39929. // INSTANCING
  39930. QUnit.test( "raycast", ( assert ) => {
  39931. assert.ok( false, "everything's gonna be alright" );
  39932. } );
  39933. // PUBLIC STUFF
  39934. QUnit.test( "clone", ( assert ) => {
  39935. assert.ok( false, "everything's gonna be alright" );
  39936. } );
  39937. } );
  39938. } );
  39939. /**
  39940. * @author TristanVALCKE / https://github.com/Itee
  39941. */
  39942. /* global QUnit */
  39943. QUnit.module( 'Objects', () => {
  39944. QUnit.module.todo( 'Skeleton', () => {
  39945. // INSTANCING
  39946. QUnit.test( "Instancing", ( assert ) => {
  39947. assert.ok( false, "everything's gonna be alright" );
  39948. } );
  39949. // PUBLIC STUFF
  39950. QUnit.test( "calculateInverses", ( assert ) => {
  39951. assert.ok( false, "everything's gonna be alright" );
  39952. } );
  39953. QUnit.test( "pose", ( assert ) => {
  39954. assert.ok( false, "everything's gonna be alright" );
  39955. } );
  39956. QUnit.test( "update", ( assert ) => {
  39957. assert.ok( false, "everything's gonna be alright" );
  39958. } );
  39959. QUnit.test( "clone", ( assert ) => {
  39960. assert.ok( false, "everything's gonna be alright" );
  39961. } );
  39962. } );
  39963. } );
  39964. /**
  39965. * @author TristanVALCKE / https://github.com/Itee
  39966. */
  39967. /* global QUnit */
  39968. QUnit.module( 'Objects', () => {
  39969. QUnit.module.todo( 'SkinnedMesh', () => {
  39970. // INHERITANCE
  39971. QUnit.test( "Extending", ( assert ) => {
  39972. assert.ok( false, "everything's gonna be alright" );
  39973. } );
  39974. // INSTANCING
  39975. QUnit.test( "Instancing", ( assert ) => {
  39976. assert.ok( false, "everything's gonna be alright" );
  39977. } );
  39978. // PUBLIC STUFF
  39979. QUnit.test( "isSkinnedMesh", ( assert ) => {
  39980. assert.ok( false, "everything's gonna be alright" );
  39981. } );
  39982. QUnit.test( "initBones", ( assert ) => {
  39983. assert.ok( false, "everything's gonna be alright" );
  39984. } );
  39985. QUnit.test( "bind", ( assert ) => {
  39986. assert.ok( false, "everything's gonna be alright" );
  39987. } );
  39988. QUnit.test( "pose", ( assert ) => {
  39989. assert.ok( false, "everything's gonna be alright" );
  39990. } );
  39991. QUnit.test( "normalizeSkinWeights", ( assert ) => {
  39992. assert.ok( false, "everything's gonna be alright" );
  39993. } );
  39994. QUnit.test( "updateMatrixWorld", ( assert ) => {
  39995. assert.ok( false, "everything's gonna be alright" );
  39996. } );
  39997. QUnit.test( "clone", ( assert ) => {
  39998. assert.ok( false, "everything's gonna be alright" );
  39999. } );
  40000. } );
  40001. } );
  40002. /**
  40003. * @author TristanVALCKE / https://github.com/Itee
  40004. */
  40005. /* global QUnit */
  40006. QUnit.module( 'Objects', () => {
  40007. QUnit.module.todo( 'Sprite', () => {
  40008. // INHERITANCE
  40009. QUnit.test( "Extending", ( assert ) => {
  40010. assert.ok( false, "everything's gonna be alright" );
  40011. } );
  40012. // INSTANCING
  40013. QUnit.test( "Instancing", ( assert ) => {
  40014. assert.ok( false, "everything's gonna be alright" );
  40015. } );
  40016. // PUBLIC STUFF
  40017. QUnit.test( "isSprite", ( assert ) => {
  40018. assert.ok( false, "everything's gonna be alright" );
  40019. } );
  40020. QUnit.test( "raycast", ( assert ) => {
  40021. assert.ok( false, "everything's gonna be alright" );
  40022. } );
  40023. QUnit.test( "clone", ( assert ) => {
  40024. assert.ok( false, "everything's gonna be alright" );
  40025. } );
  40026. } );
  40027. } );
  40028. /**
  40029. * @author mrdoob / http://mrdoob.com/
  40030. */
  40031. /**
  40032. * @author TristanVALCKE / https://github.com/Itee
  40033. */
  40034. /* global QUnit */
  40035. QUnit.module( 'Renderers', () => {
  40036. QUnit.module.todo( 'WebGL2Renderer', () => {
  40037. // INSTANCING
  40038. QUnit.test( "Instancing", ( assert ) => {
  40039. assert.ok( false, "everything's gonna be alright" );
  40040. } );
  40041. // PUBLIC STUFF
  40042. QUnit.test( "domElement", ( assert ) => {
  40043. assert.ok( false, "everything's gonna be alright" );
  40044. } );
  40045. QUnit.test( "clear", ( assert ) => {
  40046. assert.ok( false, "everything's gonna be alright" );
  40047. } );
  40048. QUnit.test( "setPixelRatio", ( assert ) => {
  40049. assert.ok( false, "everything's gonna be alright" );
  40050. } );
  40051. QUnit.test( "setSize", ( assert ) => {
  40052. assert.ok( false, "everything's gonna be alright" );
  40053. } );
  40054. QUnit.test( "render", ( assert ) => {
  40055. assert.ok( false, "everything's gonna be alright" );
  40056. } );
  40057. } );
  40058. } );
  40059. /**
  40060. * @author TristanVALCKE / https://github.com/Itee
  40061. */
  40062. /* global QUnit */
  40063. QUnit.module( 'Renderers', () => {
  40064. QUnit.module.todo( 'WebGLRenderer', () => {
  40065. // INSTANCING
  40066. QUnit.test( "Instancing", ( assert ) => {
  40067. assert.ok( false, "everything's gonna be alright" );
  40068. } );
  40069. // PUBLIC STUFF
  40070. QUnit.test( "PrayForUs", ( assert ) => {
  40071. assert.ok( false, "everything's gonna be alright" );
  40072. } );
  40073. } );
  40074. } );
  40075. /**
  40076. * @author TristanVALCKE / https://github.com/Itee
  40077. */
  40078. /* global QUnit */
  40079. QUnit.module( 'Renderers', () => {
  40080. QUnit.module.todo( 'WebGLRenderTarget', () => {
  40081. // INHERITANCE
  40082. QUnit.test( "Extending", ( assert ) => {
  40083. assert.ok( false, "everything's gonna be alright" );
  40084. } );
  40085. // INSTANCING
  40086. QUnit.test( "Instancing", ( assert ) => {
  40087. assert.ok( false, "everything's gonna be alright" );
  40088. } );
  40089. // PUBLIC STUFF
  40090. QUnit.test( "isWebGLRenderTarget", ( assert ) => {
  40091. assert.ok( false, "everything's gonna be alright" );
  40092. } );
  40093. QUnit.test( "setSize", ( assert ) => {
  40094. assert.ok( false, "everything's gonna be alright" );
  40095. } );
  40096. QUnit.test( "clone", ( assert ) => {
  40097. assert.ok( false, "everything's gonna be alright" );
  40098. } );
  40099. QUnit.test( "copy", ( assert ) => {
  40100. assert.ok( false, "everything's gonna be alright" );
  40101. } );
  40102. QUnit.test( "dispose", ( assert ) => {
  40103. assert.ok( false, "everything's gonna be alright" );
  40104. } );
  40105. } );
  40106. } );
  40107. /**
  40108. * @author TristanVALCKE / https://github.com/Itee
  40109. */
  40110. /* global QUnit */
  40111. QUnit.module( 'Renderers', () => {
  40112. QUnit.module.todo( 'WebGLRenderTargetCube', () => {
  40113. // INSTANCING
  40114. QUnit.test( "Instancing", ( assert ) => {
  40115. assert.ok( false, "everything's gonna be alright" );
  40116. } );
  40117. // PUBLIC STUFF
  40118. QUnit.test( "isWebGLRenderTargetCube", ( assert ) => {
  40119. assert.ok( false, "everything's gonna be alright" );
  40120. } );
  40121. } );
  40122. } );
  40123. /**
  40124. * @author TristanVALCKE / https://github.com/Itee
  40125. */
  40126. /* global QUnit */
  40127. QUnit.module( 'Renderers', () => {
  40128. QUnit.module( 'Shaders', () => {
  40129. QUnit.module.todo( 'ShaderChunk', () => {
  40130. QUnit.test( 'write me !', ( assert ) => {
  40131. assert.ok( false, "everything's gonna be alright" );
  40132. } );
  40133. } );
  40134. } );
  40135. } );
  40136. /**
  40137. * @author TristanVALCKE / https://github.com/Itee
  40138. */
  40139. /* global QUnit */
  40140. QUnit.module( 'Renderers', () => {
  40141. QUnit.module( 'Shaders', () => {
  40142. QUnit.module.todo( 'ShaderLib', () => {
  40143. QUnit.test( 'write me !', ( assert ) => {
  40144. assert.ok( false, "everything's gonna be alright" );
  40145. } );
  40146. } );
  40147. } );
  40148. } );
  40149. /**
  40150. * @author TristanVALCKE / https://github.com/Itee
  40151. */
  40152. /* global QUnit */
  40153. QUnit.module( 'Renderers', () => {
  40154. QUnit.module( 'Shaders', () => {
  40155. QUnit.module.todo( 'UniformsLib', () => {
  40156. // PUBLIC STUFF
  40157. QUnit.test( "merge", ( assert ) => {
  40158. assert.ok( false, "everything's gonna be alright" );
  40159. } );
  40160. QUnit.test( "clone", ( assert ) => {
  40161. assert.ok( false, "everything's gonna be alright" );
  40162. } );
  40163. } );
  40164. } );
  40165. } );
  40166. /**
  40167. * @author TristanVALCKE / https://github.com/Itee
  40168. */
  40169. /* global QUnit */
  40170. QUnit.module( 'Renderers', () => {
  40171. QUnit.module( 'Shaders', () => {
  40172. QUnit.module.todo( 'UniformsUtils', () => {
  40173. QUnit.test( 'write me !', ( assert ) => {
  40174. assert.ok( false, "everything's gonna be alright" );
  40175. } );
  40176. } );
  40177. } );
  40178. } );
  40179. /**
  40180. * @author TristanVALCKE / https://github.com/Itee
  40181. */
  40182. /* global QUnit */
  40183. QUnit.module( 'Renderers', () => {
  40184. QUnit.module( 'WebGL', () => {
  40185. QUnit.module.todo( 'WebGLAttributes', () => {
  40186. // INSTANCING
  40187. QUnit.test( "Instancing", ( assert ) => {
  40188. assert.ok( false, "everything's gonna be alright" );
  40189. } );
  40190. // PUBLIC STUFF
  40191. QUnit.test( "get", ( assert ) => {
  40192. assert.ok( false, "everything's gonna be alright" );
  40193. } );
  40194. QUnit.test( "remove", ( assert ) => {
  40195. assert.ok( false, "everything's gonna be alright" );
  40196. } );
  40197. QUnit.test( "update", ( assert ) => {
  40198. assert.ok( false, "everything's gonna be alright" );
  40199. } );
  40200. } );
  40201. } );
  40202. } );
  40203. /**
  40204. * @author TristanVALCKE / https://github.com/Itee
  40205. */
  40206. /* global QUnit */
  40207. QUnit.module( 'Renderers', () => {
  40208. QUnit.module( 'WebGL', () => {
  40209. QUnit.module.todo( 'WebGLBackground', () => {
  40210. // INSTANCING
  40211. QUnit.test( "Instancing", ( assert ) => {
  40212. assert.ok( false, "everything's gonna be alright" );
  40213. } );
  40214. // PUBLIC STUFF
  40215. QUnit.test( "getClearColor", ( assert ) => {
  40216. assert.ok( false, "everything's gonna be alright" );
  40217. } );
  40218. QUnit.test( "setClearColor", ( assert ) => {
  40219. assert.ok( false, "everything's gonna be alright" );
  40220. } );
  40221. QUnit.test( "getClearAlpha", ( assert ) => {
  40222. assert.ok( false, "everything's gonna be alright" );
  40223. } );
  40224. QUnit.test( "setClearAlpha", ( assert ) => {
  40225. assert.ok( false, "everything's gonna be alright" );
  40226. } );
  40227. QUnit.test( "render", ( assert ) => {
  40228. assert.ok( false, "everything's gonna be alright" );
  40229. } );
  40230. } );
  40231. } );
  40232. } );
  40233. /**
  40234. * @author TristanVALCKE / https://github.com/Itee
  40235. */
  40236. /* global QUnit */
  40237. QUnit.module( 'Renderers', () => {
  40238. QUnit.module( 'WebGL', () => {
  40239. QUnit.module.todo( 'WebGLBufferRenderer', () => {
  40240. // INSTANCING
  40241. QUnit.test( "Instancing", ( assert ) => {
  40242. assert.ok( false, "everything's gonna be alright" );
  40243. } );
  40244. // PUBLIC STUFF
  40245. QUnit.test( "setMode", ( assert ) => {
  40246. assert.ok( false, "everything's gonna be alright" );
  40247. } );
  40248. QUnit.test( "render", ( assert ) => {
  40249. assert.ok( false, "everything's gonna be alright" );
  40250. } );
  40251. QUnit.test( "renderInstances", ( assert ) => {
  40252. assert.ok( false, "everything's gonna be alright" );
  40253. } );
  40254. } );
  40255. } );
  40256. } );
  40257. /**
  40258. * @author TristanVALCKE / https://github.com/Itee
  40259. */
  40260. /* global QUnit */
  40261. QUnit.module( 'Renderers', () => {
  40262. QUnit.module( 'WebGL', () => {
  40263. QUnit.module.todo( 'WebGLCapabilities', () => {
  40264. // INSTANCING
  40265. QUnit.test( "Instancing", ( assert ) => {
  40266. assert.ok( false, "everything's gonna be alright" );
  40267. } );
  40268. // PUBLIC STUFF
  40269. QUnit.test( "getMaxAnisotropy", ( assert ) => {
  40270. assert.ok( false, "everything's gonna be alright" );
  40271. } );
  40272. QUnit.test( "getMaxPrecision", ( assert ) => {
  40273. assert.ok( false, "everything's gonna be alright" );
  40274. } );
  40275. QUnit.test( "precision", ( assert ) => {
  40276. assert.ok( false, "everything's gonna be alright" );
  40277. } );
  40278. QUnit.test( "logarithmicDepthBuffer", ( assert ) => {
  40279. assert.ok( false, "everything's gonna be alright" );
  40280. } );
  40281. QUnit.test( "maxTextures", ( assert ) => {
  40282. assert.ok( false, "everything's gonna be alright" );
  40283. } );
  40284. QUnit.test( "maxVertexTextures", ( assert ) => {
  40285. assert.ok( false, "everything's gonna be alright" );
  40286. } );
  40287. QUnit.test( "maxTextureSize", ( assert ) => {
  40288. assert.ok( false, "everything's gonna be alright" );
  40289. } );
  40290. QUnit.test( "maxCubemapSize", ( assert ) => {
  40291. assert.ok( false, "everything's gonna be alright" );
  40292. } );
  40293. QUnit.test( "maxAttributes", ( assert ) => {
  40294. assert.ok( false, "everything's gonna be alright" );
  40295. } );
  40296. QUnit.test( "maxVertexUniforms", ( assert ) => {
  40297. assert.ok( false, "everything's gonna be alright" );
  40298. } );
  40299. QUnit.test( "maxVaryings", ( assert ) => {
  40300. assert.ok( false, "everything's gonna be alright" );
  40301. } );
  40302. QUnit.test( "maxFragmentUniforms", ( assert ) => {
  40303. assert.ok( false, "everything's gonna be alright" );
  40304. } );
  40305. QUnit.test( "vertexTextures", ( assert ) => {
  40306. assert.ok( false, "everything's gonna be alright" );
  40307. } );
  40308. QUnit.test( "floatFragmentTextures", ( assert ) => {
  40309. assert.ok( false, "everything's gonna be alright" );
  40310. } );
  40311. QUnit.test( "floatVertexTextures", ( assert ) => {
  40312. assert.ok( false, "everything's gonna be alright" );
  40313. } );
  40314. } );
  40315. } );
  40316. } );
  40317. /**
  40318. * @author TristanVALCKE / https://github.com/Itee
  40319. */
  40320. /* global QUnit */
  40321. QUnit.module( 'Renderers', () => {
  40322. QUnit.module( 'WebGL', () => {
  40323. QUnit.module.todo( 'WebGLClipping', () => {
  40324. // INSTANCING
  40325. QUnit.test( "Instancing", ( assert ) => {
  40326. assert.ok( false, "everything's gonna be alright" );
  40327. } );
  40328. // PUBLIC STUFF
  40329. QUnit.test( "init", ( assert ) => {
  40330. assert.ok( false, "everything's gonna be alright" );
  40331. } );
  40332. QUnit.test( "beginShadows", ( assert ) => {
  40333. assert.ok( false, "everything's gonna be alright" );
  40334. } );
  40335. QUnit.test( "endShadows", ( assert ) => {
  40336. assert.ok( false, "everything's gonna be alright" );
  40337. } );
  40338. QUnit.test( "setState", ( assert ) => {
  40339. assert.ok( false, "everything's gonna be alright" );
  40340. } );
  40341. } );
  40342. } );
  40343. } );
  40344. /**
  40345. * @author TristanVALCKE / https://github.com/Itee
  40346. */
  40347. /* global QUnit */
  40348. QUnit.module( 'Renderers', () => {
  40349. QUnit.module( 'WebGL', () => {
  40350. QUnit.module.todo( 'WebGLExtensions', () => {
  40351. // INSTANCING
  40352. QUnit.test( "Instancing", ( assert ) => {
  40353. assert.ok( false, "everything's gonna be alright" );
  40354. } );
  40355. // PUBLIC STUFF
  40356. QUnit.test( "get", ( assert ) => {
  40357. assert.ok( false, "everything's gonna be alright" );
  40358. } );
  40359. } );
  40360. } );
  40361. } );
  40362. /**
  40363. * @author TristanVALCKE / https://github.com/Itee
  40364. */
  40365. /* global QUnit */
  40366. QUnit.module( 'Renderers', () => {
  40367. QUnit.module( 'WebGL', () => {
  40368. QUnit.module.todo( 'WebGLFlareRenderer', () => {
  40369. // INSTANCING
  40370. QUnit.test( "Instancing", ( assert ) => {
  40371. assert.ok( false, "everything's gonna be alright" );
  40372. } );
  40373. // PUBLIC STUFF
  40374. QUnit.test( "render", ( assert ) => {
  40375. assert.ok( false, "everything's gonna be alright" );
  40376. } );
  40377. } );
  40378. } );
  40379. } );
  40380. /**
  40381. * @author TristanVALCKE / https://github.com/Itee
  40382. */
  40383. /* global QUnit */
  40384. QUnit.module( 'Renderers', () => {
  40385. QUnit.module( 'WebGL', () => {
  40386. QUnit.module.todo( 'WebGLGeometries', () => {
  40387. // INSTANCING
  40388. QUnit.test( "Instancing", ( assert ) => {
  40389. assert.ok( false, "everything's gonna be alright" );
  40390. } );
  40391. // PUBLIC STUFF
  40392. QUnit.test( "get", ( assert ) => {
  40393. assert.ok( false, "everything's gonna be alright" );
  40394. } );
  40395. QUnit.test( "update", ( assert ) => {
  40396. assert.ok( false, "everything's gonna be alright" );
  40397. } );
  40398. QUnit.test( "getWireframeAttribute", ( 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( 'WebGLIndexedBufferRenderer', () => {
  40411. // INSTANCING
  40412. QUnit.test( "Instancing", ( assert ) => {
  40413. assert.ok( false, "everything's gonna be alright" );
  40414. } );
  40415. // PUBLIC STUFF
  40416. QUnit.test( "setMode", ( assert ) => {
  40417. assert.ok( false, "everything's gonna be alright" );
  40418. } );
  40419. QUnit.test( "setIndex", ( assert ) => {
  40420. assert.ok( false, "everything's gonna be alright" );
  40421. } );
  40422. QUnit.test( "render", ( assert ) => {
  40423. assert.ok( false, "everything's gonna be alright" );
  40424. } );
  40425. QUnit.test( "renderInstances", ( assert ) => {
  40426. assert.ok( false, "everything's gonna be alright" );
  40427. } );
  40428. } );
  40429. } );
  40430. } );
  40431. /**
  40432. * @author TristanVALCKE / https://github.com/Itee
  40433. */
  40434. /* global QUnit */
  40435. QUnit.module( 'Renderers', () => {
  40436. QUnit.module( 'WebGL', () => {
  40437. QUnit.module.todo( 'WebGLLights', () => {
  40438. // INSTANCING
  40439. QUnit.test( "Instancing", ( assert ) => {
  40440. assert.ok( false, "everything's gonna be alright" );
  40441. } );
  40442. // PUBLIC STUFF
  40443. QUnit.test( "setup", ( assert ) => {
  40444. assert.ok( false, "everything's gonna be alright" );
  40445. } );
  40446. QUnit.test( "state", ( assert ) => {
  40447. assert.ok( false, "everything's gonna be alright" );
  40448. } );
  40449. } );
  40450. } );
  40451. } );
  40452. /**
  40453. * @author TristanVALCKE / https://github.com/Itee
  40454. */
  40455. /* global QUnit */
  40456. QUnit.module( 'Renderers', () => {
  40457. QUnit.module( 'WebGL', () => {
  40458. QUnit.module.todo( 'WebGLMorphtargets', () => {
  40459. // INSTANCING
  40460. QUnit.test( "Instancing", ( assert ) => {
  40461. assert.ok( false, "everything's gonna be alright" );
  40462. } );
  40463. // PUBLIC STUFF
  40464. QUnit.test( "update", ( assert ) => {
  40465. assert.ok( false, "everything's gonna be alright" );
  40466. } );
  40467. } );
  40468. } );
  40469. } );
  40470. /**
  40471. * @author TristanVALCKE / https://github.com/Itee
  40472. */
  40473. /* global QUnit */
  40474. QUnit.module( 'Renderers', () => {
  40475. QUnit.module( 'WebGL', () => {
  40476. QUnit.module.todo( 'WebGLObjects', () => {
  40477. // INSTANCING
  40478. QUnit.test( "Instancing", ( assert ) => {
  40479. assert.ok( false, "everything's gonna be alright" );
  40480. } );
  40481. // PUBLIC STUFF
  40482. QUnit.test( "update", ( assert ) => {
  40483. assert.ok( false, "everything's gonna be alright" );
  40484. } );
  40485. QUnit.test( "clear", ( assert ) => {
  40486. assert.ok( false, "everything's gonna be alright" );
  40487. } );
  40488. } );
  40489. } );
  40490. } );
  40491. /**
  40492. * @author TristanVALCKE / https://github.com/Itee
  40493. */
  40494. /* global QUnit */
  40495. QUnit.module( 'Renderers', () => {
  40496. QUnit.module( 'WebGL', () => {
  40497. QUnit.module.todo( 'WebGLProgram', () => {
  40498. // INSTANCING
  40499. QUnit.test( "Instancing", ( assert ) => {
  40500. assert.ok( false, "everything's gonna be alright" );
  40501. } );
  40502. // PROPERTIES
  40503. QUnit.test( "uniforms", ( assert ) => {
  40504. assert.ok( false, "everything's gonna be alright" );
  40505. } );
  40506. QUnit.test( "attributes", ( assert ) => {
  40507. assert.ok( false, "everything's gonna be alright" );
  40508. } );
  40509. // PUBLIC STUFF
  40510. QUnit.test( "getUniforms", ( assert ) => {
  40511. assert.ok( false, "everything's gonna be alright" );
  40512. } );
  40513. QUnit.test( "getAttributes", ( assert ) => {
  40514. assert.ok( false, "everything's gonna be alright" );
  40515. } );
  40516. QUnit.test( "destroy", ( assert ) => {
  40517. assert.ok( false, "everything's gonna be alright" );
  40518. } );
  40519. } );
  40520. } );
  40521. } );
  40522. /**
  40523. * @author TristanVALCKE / https://github.com/Itee
  40524. */
  40525. /* global QUnit */
  40526. QUnit.module( 'Renderers', () => {
  40527. QUnit.module( 'WebGL', () => {
  40528. QUnit.module.todo( 'WebGLPrograms', () => {
  40529. // INSTANCING
  40530. QUnit.test( "Instancing", ( assert ) => {
  40531. assert.ok( false, "everything's gonna be alright" );
  40532. } );
  40533. // PUBLIC STUFF
  40534. QUnit.test( "getParameters", ( assert ) => {
  40535. assert.ok( false, "everything's gonna be alright" );
  40536. } );
  40537. QUnit.test( "getProgramCode", ( assert ) => {
  40538. assert.ok( false, "everything's gonna be alright" );
  40539. } );
  40540. QUnit.test( "acquireProgram", ( assert ) => {
  40541. assert.ok( false, "everything's gonna be alright" );
  40542. } );
  40543. QUnit.test( "releaseProgram", ( assert ) => {
  40544. assert.ok( false, "everything's gonna be alright" );
  40545. } );
  40546. QUnit.test( "programs", ( assert ) => {
  40547. assert.ok( false, "everything's gonna be alright" );
  40548. } );
  40549. } );
  40550. } );
  40551. } );
  40552. /**
  40553. * @author TristanVALCKE / https://github.com/Itee
  40554. */
  40555. /* global QUnit */
  40556. QUnit.module( 'Renderers', () => {
  40557. QUnit.module( 'WebGL', () => {
  40558. QUnit.module.todo( 'WebGLProperties', () => {
  40559. // INSTANCING
  40560. QUnit.test( "Instancing", ( assert ) => {
  40561. assert.ok( false, "everything's gonna be alright" );
  40562. } );
  40563. // PUBLIC STUFF
  40564. QUnit.test( "get", ( assert ) => {
  40565. assert.ok( false, "everything's gonna be alright" );
  40566. } );
  40567. QUnit.test( "remove", ( assert ) => {
  40568. assert.ok( false, "everything's gonna be alright" );
  40569. } );
  40570. QUnit.test( "clear", ( assert ) => {
  40571. assert.ok( false, "everything's gonna be alright" );
  40572. } );
  40573. } );
  40574. } );
  40575. } );
  40576. /**
  40577. * @author TristanVALCKE / https://github.com/Itee
  40578. */
  40579. /* global QUnit */
  40580. QUnit.module( 'Renderers', () => {
  40581. QUnit.module( 'WebGL', () => {
  40582. QUnit.module.todo( 'WebGLRenderLists', () => {
  40583. // INSTANCING
  40584. QUnit.test( "Instancing", ( assert ) => {
  40585. assert.ok( false, "everything's gonna be alright" );
  40586. } );
  40587. // PUBLIC STUFF
  40588. QUnit.test( "get", ( assert ) => {
  40589. assert.ok( false, "everything's gonna be alright" );
  40590. } );
  40591. QUnit.test( "dispose", ( assert ) => {
  40592. assert.ok( false, "everything's gonna be alright" );
  40593. } );
  40594. } );
  40595. } );
  40596. } );
  40597. /**
  40598. * @author TristanVALCKE / https://github.com/Itee
  40599. */
  40600. /* global QUnit */
  40601. QUnit.module( 'Renderers', () => {
  40602. QUnit.module( 'WebGL', () => {
  40603. QUnit.module.todo( 'WebGLShader', () => {
  40604. // INSTANCING
  40605. QUnit.test( "Instancing", ( assert ) => {
  40606. assert.ok( false, "everything's gonna be alright" );
  40607. } );
  40608. } );
  40609. } );
  40610. } );
  40611. /**
  40612. * @author TristanVALCKE / https://github.com/Itee
  40613. */
  40614. /* global QUnit */
  40615. QUnit.module( 'Renderers', () => {
  40616. QUnit.module( 'WebGL', () => {
  40617. QUnit.module.todo( 'WebGLShadowMap', () => {
  40618. // INSTANCING
  40619. QUnit.test( "Instancing", ( assert ) => {
  40620. assert.ok( false, "everything's gonna be alright" );
  40621. } );
  40622. // PUBLIC STUFF
  40623. QUnit.test( "render", ( assert ) => {
  40624. assert.ok( false, "everything's gonna be alright" );
  40625. } );
  40626. } );
  40627. } );
  40628. } );
  40629. /**
  40630. * @author TristanVALCKE / https://github.com/Itee
  40631. */
  40632. /* global QUnit */
  40633. QUnit.module( 'Renderers', () => {
  40634. QUnit.module( 'WebGL', () => {
  40635. QUnit.module.todo( 'WebGLSpriteRenderer', () => {
  40636. // INSTANCING
  40637. QUnit.test( "Instancing", ( assert ) => {
  40638. assert.ok( false, "everything's gonna be alright" );
  40639. } );
  40640. // PUBLIC STUFF
  40641. QUnit.test( "render", ( assert ) => {
  40642. assert.ok( false, "everything's gonna be alright" );
  40643. } );
  40644. } );
  40645. } );
  40646. } );
  40647. /**
  40648. * @author TristanVALCKE / https://github.com/Itee
  40649. */
  40650. /* global QUnit */
  40651. QUnit.module( 'Renderers', () => {
  40652. QUnit.module( 'WebGL', () => {
  40653. QUnit.module.todo( 'WebGLState', () => {
  40654. // INSTANCING
  40655. QUnit.test( "Instancing", ( assert ) => {
  40656. assert.ok( false, "everything's gonna be alright" );
  40657. } );
  40658. // PUBLIC STUFF
  40659. QUnit.test( "buffers", ( assert ) => {
  40660. assert.ok( false, "everything's gonna be alright" );
  40661. } );
  40662. QUnit.test( "initAttributes", ( assert ) => {
  40663. assert.ok( false, "everything's gonna be alright" );
  40664. } );
  40665. QUnit.test( "enableAttribute", ( assert ) => {
  40666. assert.ok( false, "everything's gonna be alright" );
  40667. } );
  40668. QUnit.test( "enableAttributeAndDivisor", ( assert ) => {
  40669. assert.ok( false, "everything's gonna be alright" );
  40670. } );
  40671. QUnit.test( "disableUnusedAttributes", ( assert ) => {
  40672. assert.ok( false, "everything's gonna be alright" );
  40673. } );
  40674. QUnit.test( "enable", ( assert ) => {
  40675. assert.ok( false, "everything's gonna be alright" );
  40676. } );
  40677. QUnit.test( "disable", ( assert ) => {
  40678. assert.ok( false, "everything's gonna be alright" );
  40679. } );
  40680. QUnit.test( "getCompressedTextureFormats", ( assert ) => {
  40681. assert.ok( false, "everything's gonna be alright" );
  40682. } );
  40683. QUnit.test( "useProgram", ( assert ) => {
  40684. assert.ok( false, "everything's gonna be alright" );
  40685. } );
  40686. QUnit.test( "setBlending", ( assert ) => {
  40687. assert.ok( false, "everything's gonna be alright" );
  40688. } );
  40689. QUnit.test( "setMaterial", ( assert ) => {
  40690. assert.ok( false, "everything's gonna be alright" );
  40691. } );
  40692. QUnit.test( "setFlipSided", ( assert ) => {
  40693. assert.ok( false, "everything's gonna be alright" );
  40694. } );
  40695. QUnit.test( "setCullFace", ( assert ) => {
  40696. assert.ok( false, "everything's gonna be alright" );
  40697. } );
  40698. QUnit.test( "setLineWidth", ( assert ) => {
  40699. assert.ok( false, "everything's gonna be alright" );
  40700. } );
  40701. QUnit.test( "setPolygonOffset", ( assert ) => {
  40702. assert.ok( false, "everything's gonna be alright" );
  40703. } );
  40704. QUnit.test( "setScissorTest", ( assert ) => {
  40705. assert.ok( false, "everything's gonna be alright" );
  40706. } );
  40707. QUnit.test( "activeTexture", ( assert ) => {
  40708. assert.ok( false, "everything's gonna be alright" );
  40709. } );
  40710. QUnit.test( "bindTexture", ( assert ) => {
  40711. assert.ok( false, "everything's gonna be alright" );
  40712. } );
  40713. QUnit.test( "compressedTexImage2D", ( assert ) => {
  40714. assert.ok( false, "everything's gonna be alright" );
  40715. } );
  40716. QUnit.test( "texImage2D", ( assert ) => {
  40717. assert.ok( false, "everything's gonna be alright" );
  40718. } );
  40719. QUnit.test( "scissor", ( assert ) => {
  40720. assert.ok( false, "everything's gonna be alright" );
  40721. } );
  40722. QUnit.test( "viewport", ( assert ) => {
  40723. assert.ok( false, "everything's gonna be alright" );
  40724. } );
  40725. QUnit.test( "reset", ( assert ) => {
  40726. assert.ok( false, "everything's gonna be alright" );
  40727. } );
  40728. } );
  40729. } );
  40730. } );
  40731. /**
  40732. * @author TristanVALCKE / https://github.com/Itee
  40733. */
  40734. /* global QUnit */
  40735. QUnit.module( 'Renderers', () => {
  40736. QUnit.module( 'WebGL', () => {
  40737. QUnit.module.todo( 'WebGLTextures', () => {
  40738. // INSTANCING
  40739. QUnit.test( "Instancing", ( assert ) => {
  40740. assert.ok( false, "everything's gonna be alright" );
  40741. } );
  40742. // PUBLIC STUFF
  40743. QUnit.test( "setTexture2D", ( assert ) => {
  40744. assert.ok( false, "everything's gonna be alright" );
  40745. } );
  40746. QUnit.test( "setTextureCube", ( assert ) => {
  40747. assert.ok( false, "everything's gonna be alright" );
  40748. } );
  40749. QUnit.test( "setTextureCubeDynamic", ( assert ) => {
  40750. assert.ok( false, "everything's gonna be alright" );
  40751. } );
  40752. QUnit.test( "setupRenderTarget", ( assert ) => {
  40753. assert.ok( false, "everything's gonna be alright" );
  40754. } );
  40755. QUnit.test( "updateRenderTargetMipmap", ( assert ) => {
  40756. assert.ok( false, "everything's gonna be alright" );
  40757. } );
  40758. } );
  40759. } );
  40760. } );
  40761. /**
  40762. * @author TristanVALCKE / https://github.com/Itee
  40763. */
  40764. /* global QUnit */
  40765. QUnit.module( 'Renderers', () => {
  40766. QUnit.module( 'WebGL', () => {
  40767. QUnit.module.todo( 'WebGLUniforms', () => {
  40768. // INSTANCING
  40769. QUnit.test( "Instancing", ( assert ) => {
  40770. assert.ok( false, "everything's gonna be alright" );
  40771. } );
  40772. // PUBLIC STUFF
  40773. QUnit.test( "setValue", ( assert ) => {
  40774. assert.ok( false, "everything's gonna be alright" );
  40775. } );
  40776. QUnit.test( "setOptional", ( assert ) => {
  40777. assert.ok( false, "everything's gonna be alright" );
  40778. } );
  40779. QUnit.test( "upload", ( assert ) => {
  40780. assert.ok( false, "everything's gonna be alright" );
  40781. } );
  40782. QUnit.test( "seqWithValue", ( assert ) => {
  40783. assert.ok( false, "everything's gonna be alright" );
  40784. } );
  40785. } );
  40786. } );
  40787. } );
  40788. /**
  40789. * @author TristanVALCKE / https://github.com/Itee
  40790. */
  40791. /* global QUnit */
  40792. QUnit.module( 'Renderers', () => {
  40793. QUnit.module( 'WebGL', () => {
  40794. QUnit.module.todo( 'WebGLUtils', () => {
  40795. // INSTANCING
  40796. QUnit.test( "Instancing", ( assert ) => {
  40797. assert.ok( false, "everything's gonna be alright" );
  40798. } );
  40799. // PUBLIC STUFF
  40800. QUnit.test( "convert", ( assert ) => {
  40801. assert.ok( false, "everything's gonna be alright" );
  40802. } );
  40803. } );
  40804. } );
  40805. } );
  40806. /**
  40807. * @author TristanVALCKE / https://github.com/Itee
  40808. */
  40809. /* global QUnit */
  40810. QUnit.module( 'Renderers', () => {
  40811. QUnit.module( 'WebGL', () => {
  40812. QUnit.module.todo( 'WebVRManager', () => {
  40813. // INSTANCING
  40814. QUnit.test( "Instancing", ( assert ) => {
  40815. assert.ok( false, "everything's gonna be alright" );
  40816. } );
  40817. // PUBLIC STUFF
  40818. QUnit.test( "getDevice", ( assert ) => {
  40819. assert.ok( false, "everything's gonna be alright" );
  40820. } );
  40821. QUnit.test( "setDevice", ( assert ) => {
  40822. assert.ok( false, "everything's gonna be alright" );
  40823. } );
  40824. QUnit.test( "getCamera", ( assert ) => {
  40825. assert.ok( false, "everything's gonna be alright" );
  40826. } );
  40827. QUnit.test( "getStandingMatrix", ( assert ) => {
  40828. assert.ok( false, "everything's gonna be alright" );
  40829. } );
  40830. QUnit.test( "submitFrame", ( assert ) => {
  40831. assert.ok( false, "everything's gonna be alright" );
  40832. } );
  40833. QUnit.test( "dispose", ( assert ) => {
  40834. assert.ok( false, "everything's gonna be alright" );
  40835. } );
  40836. } );
  40837. } );
  40838. } );
  40839. /**
  40840. * @author TristanVALCKE / https://github.com/Itee
  40841. */
  40842. /* global QUnit */
  40843. QUnit.module( 'Fog', () => {
  40844. QUnit.module.todo( 'Scene', () => {
  40845. // INHERITANCE
  40846. QUnit.test( "Extending", ( assert ) => {
  40847. assert.ok( false, "everything's gonna be alright" );
  40848. } );
  40849. // INSTANCING
  40850. QUnit.test( "Instancing", ( assert ) => {
  40851. assert.ok( false, "everything's gonna be alright" );
  40852. } );
  40853. // PUBLIC STUFF
  40854. QUnit.test( "isFog", ( assert ) => {
  40855. assert.ok( false, "everything's gonna be alright" );
  40856. } );
  40857. QUnit.test( "clone", ( assert ) => {
  40858. assert.ok( false, "everything's gonna be alright" );
  40859. } );
  40860. QUnit.test( "toJSON", ( assert ) => {
  40861. assert.ok( false, "everything's gonna be alright" );
  40862. } );
  40863. } );
  40864. } );
  40865. /**
  40866. * @author TristanVALCKE / https://github.com/Itee
  40867. */
  40868. /* global QUnit */
  40869. QUnit.module( 'FoxExp2', () => {
  40870. QUnit.module.todo( 'Scene', () => {
  40871. // INHERITANCE
  40872. QUnit.test( "Extending", ( assert ) => {
  40873. assert.ok( false, "everything's gonna be alright" );
  40874. } );
  40875. // INSTANCING
  40876. QUnit.test( "Instancing", ( assert ) => {
  40877. assert.ok( false, "everything's gonna be alright" );
  40878. } );
  40879. // PUBLIC STUFF
  40880. QUnit.test( "isFogExp2", ( assert ) => {
  40881. assert.ok( false, "everything's gonna be alright" );
  40882. } );
  40883. QUnit.test( "clone", ( assert ) => {
  40884. assert.ok( false, "everything's gonna be alright" );
  40885. } );
  40886. QUnit.test( "toJSON", ( assert ) => {
  40887. assert.ok( false, "everything's gonna be alright" );
  40888. } );
  40889. } );
  40890. } );
  40891. /**
  40892. * @author TristanVALCKE / https://github.com/Itee
  40893. */
  40894. /* global QUnit */
  40895. QUnit.module( 'Scenes', () => {
  40896. QUnit.module.todo( 'Scene', () => {
  40897. // INHERITANCE
  40898. QUnit.test( "Extending", ( assert ) => {
  40899. assert.ok( false, "everything's gonna be alright" );
  40900. } );
  40901. // INSTANCING
  40902. QUnit.test( "Instancing", ( assert ) => {
  40903. assert.ok( false, "everything's gonna be alright" );
  40904. } );
  40905. // PUBLIC STUFF
  40906. QUnit.test( "isScene", ( assert ) => {
  40907. assert.ok( false, "everything's gonna be alright" );
  40908. } );
  40909. QUnit.test( "copy", ( assert ) => {
  40910. assert.ok( false, "everything's gonna be alright" );
  40911. } );
  40912. QUnit.test( "toJSON", ( assert ) => {
  40913. assert.ok( false, "everything's gonna be alright" );
  40914. } );
  40915. } );
  40916. } );
  40917. /**
  40918. * @author TristanVALCKE / https://github.com/Itee
  40919. */
  40920. /* global QUnit */
  40921. QUnit.module( 'Textures', () => {
  40922. QUnit.module.todo( 'CanvasTexture', () => {
  40923. // INHERITANCE
  40924. QUnit.test( "Extending", ( assert ) => {
  40925. assert.ok( false, "everything's gonna be alright" );
  40926. } );
  40927. // INSTANCING
  40928. QUnit.test( "Instancing", ( assert ) => {
  40929. assert.ok( false, "everything's gonna be alright" );
  40930. } );
  40931. // PUBLIC STUFF
  40932. QUnit.test( "isCanvasTexture", ( assert ) => {
  40933. assert.ok( false, "everything's gonna be alright" );
  40934. } );
  40935. } );
  40936. } );
  40937. /**
  40938. * @author TristanVALCKE / https://github.com/Itee
  40939. */
  40940. /* global QUnit */
  40941. QUnit.module( 'Textures', () => {
  40942. QUnit.module.todo( 'CompressedTexture', () => {
  40943. // INHERITANCE
  40944. QUnit.test( "Extending", ( assert ) => {
  40945. assert.ok( false, "everything's gonna be alright" );
  40946. } );
  40947. // INSTANCING
  40948. QUnit.test( "Instancing", ( assert ) => {
  40949. assert.ok( false, "everything's gonna be alright" );
  40950. } );
  40951. // PUBLIC STUFF
  40952. QUnit.test( "isCompressedTexture", ( assert ) => {
  40953. assert.ok( false, "everything's gonna be alright" );
  40954. } );
  40955. } );
  40956. } );
  40957. /**
  40958. * @author TristanVALCKE / https://github.com/Itee
  40959. */
  40960. /* global QUnit */
  40961. QUnit.module( 'Textures', () => {
  40962. QUnit.module.todo( 'CubeTexture', () => {
  40963. // INHERITANCE
  40964. QUnit.test( "Extending", ( assert ) => {
  40965. assert.ok( false, "everything's gonna be alright" );
  40966. } );
  40967. // INSTANCING
  40968. QUnit.test( "Instancing", ( assert ) => {
  40969. assert.ok( false, "everything's gonna be alright" );
  40970. } );
  40971. // PROPERTIES
  40972. QUnit.test( "images", ( assert ) => {
  40973. assert.ok( false, "everything's gonna be alright" );
  40974. } );
  40975. // PUBLIC STUFF
  40976. QUnit.test( "isCubeTexture", ( assert ) => {
  40977. assert.ok( false, "everything's gonna be alright" );
  40978. } );
  40979. } );
  40980. } );
  40981. /**
  40982. * @author TristanVALCKE / https://github.com/Itee
  40983. */
  40984. /* global QUnit */
  40985. QUnit.module( 'Textures', () => {
  40986. QUnit.module.todo( 'DataTexture', () => {
  40987. // INHERITANCE
  40988. QUnit.test( "Extending", ( assert ) => {
  40989. assert.ok( false, "everything's gonna be alright" );
  40990. } );
  40991. // INSTANCING
  40992. QUnit.test( "Instancing", ( assert ) => {
  40993. assert.ok( false, "everything's gonna be alright" );
  40994. } );
  40995. // PUBLIC STUFF
  40996. QUnit.test( "isDataTexture", ( assert ) => {
  40997. assert.ok( false, "everything's gonna be alright" );
  40998. } );
  40999. } );
  41000. } );
  41001. /**
  41002. * @author Matt DesLauriers / @mattdesl
  41003. * @author atix / arthursilber.de
  41004. */
  41005. /**
  41006. * @author TristanVALCKE / https://github.com/Itee
  41007. */
  41008. /* global QUnit */
  41009. QUnit.module( 'Textures', () => {
  41010. QUnit.module.todo( 'DepthTexture', () => {
  41011. // INHERITANCE
  41012. QUnit.test( "Extending", ( assert ) => {
  41013. assert.ok( false, "everything's gonna be alright" );
  41014. } );
  41015. // INSTANCING
  41016. QUnit.test( "Instancing", ( assert ) => {
  41017. assert.ok( false, "everything's gonna be alright" );
  41018. } );
  41019. // PUBLIC STUFF
  41020. QUnit.test( "isDepthTexture", ( assert ) => {
  41021. assert.ok( false, "everything's gonna be alright" );
  41022. } );
  41023. } );
  41024. } );
  41025. /**
  41026. * @author TristanVALCKE / https://github.com/Itee
  41027. */
  41028. /* global QUnit */
  41029. QUnit.module( 'Textures', () => {
  41030. QUnit.module.todo( 'Texture', () => {
  41031. // INSTANCING
  41032. QUnit.test( "Instancing", ( assert ) => {
  41033. assert.ok( false, "everything's gonna be alright" );
  41034. } );
  41035. // PROPERTIES
  41036. QUnit.test( "needsUpdate", ( assert ) => {
  41037. assert.ok( false, "everything's gonna be alright" );
  41038. } );
  41039. // PUBLIC STUFF
  41040. QUnit.test( "isTexture", ( assert ) => {
  41041. assert.ok( false, "everything's gonna be alright" );
  41042. } );
  41043. QUnit.test( "clone", ( assert ) => {
  41044. assert.ok( false, "everything's gonna be alright" );
  41045. } );
  41046. QUnit.test( "copy", ( assert ) => {
  41047. assert.ok( false, "everything's gonna be alright" );
  41048. } );
  41049. QUnit.test( "toJSON", ( assert ) => {
  41050. assert.ok( false, "everything's gonna be alright" );
  41051. } );
  41052. QUnit.test( "dispose", ( assert ) => {
  41053. assert.ok( false, "everything's gonna be alright" );
  41054. } );
  41055. QUnit.test( "transformUv", ( assert ) => {
  41056. assert.ok( false, "everything's gonna be alright" );
  41057. } );
  41058. } );
  41059. } );
  41060. /**
  41061. * @author mrdoob / http://mrdoob.com/
  41062. */
  41063. /**
  41064. * @author TristanVALCKE / https://github.com/Itee
  41065. */
  41066. /* global QUnit */
  41067. QUnit.module( 'Textures', () => {
  41068. QUnit.module.todo( 'VideoTexture', () => {
  41069. // INHERITANCE
  41070. QUnit.test( "Extending", ( assert ) => {
  41071. assert.ok( false, "everything's gonna be alright" );
  41072. } );
  41073. // INSTANCING
  41074. QUnit.test( "Instancing", ( assert ) => {
  41075. assert.ok( false, "everything's gonna be alright" );
  41076. } );
  41077. // PUBLIC STUFF
  41078. QUnit.test( "isVideoTexture", ( assert ) => {
  41079. assert.ok( false, "everything's gonna be alright" );
  41080. } );
  41081. } );
  41082. } );
  41083. /**
  41084. * @author TristanVALCKE / https://github.com/Itee
  41085. */
  41086. //src
  41087. //src/animation
  41088. //src/animation/tracks
  41089. //src/audio
  41090. //src/cameras
  41091. //src/core
  41092. //src/extras
  41093. //src/extras/core
  41094. //src/extras/curves
  41095. //src/extras/objects
  41096. //src/geometries
  41097. //src/helpers
  41098. //src/lights
  41099. //src/loaders
  41100. //src/materials
  41101. //src/math
  41102. //src/math/interpolants
  41103. //src/objects
  41104. //src/renderers
  41105. //src/renderers/shaders
  41106. //src/renderers/webgl
  41107. //src/renderers/webvr
  41108. //src/scenes
  41109. //src/textures
  41110. } );
  41111. })));