123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435 |
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
- typeof define === 'function' && define.amd ? define(factory) :
- (factory());
- }(this, (function () { 'use strict';
- QUnit.module( "Editor", () => {
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param editorRef pointer to main editor object used to initialize
- * each command object with a reference to the editor
- * @constructor
- */
- var Command$1 = function ( editorRef ) {
- this.id = - 1;
- this.inMemory = false;
- this.updatable = false;
- this.type = '';
- this.name = '';
- if ( editorRef !== undefined ) {
- Command$1.editor = editorRef;
- }
- this.editor = Command$1.editor;
- };
- Command$1.prototype.toJSON = function () {
- var output = {};
- output.type = this.type;
- output.id = this.id;
- output.name = this.name;
- return output;
- };
- Command$1.prototype.fromJSON = function ( json ) {
- this.inMemory = true;
- this.type = json.type;
- this.id = json.id;
- this.name = json.name;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Command', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Config', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- var Editor = function () {
- this.DEFAULT_CAMERA = new THREE.PerspectiveCamera( 50, 1, 0.1, 10000 );
- this.DEFAULT_CAMERA.name = 'Camera';
- this.DEFAULT_CAMERA.position.set( 20, 10, 20 );
- this.DEFAULT_CAMERA.lookAt( new THREE.Vector3() );
- var Signal = signals.Signal;
- this.signals = {
- // script
- editScript: new Signal(),
- // player
- startPlayer: new Signal(),
- stopPlayer: new Signal(),
- // actions
- showModal: new Signal(),
- // notifications
- editorCleared: new Signal(),
- savingStarted: new Signal(),
- savingFinished: new Signal(),
- themeChanged: new Signal(),
- transformModeChanged: new Signal(),
- snapChanged: new Signal(),
- spaceChanged: new Signal(),
- rendererChanged: new Signal(),
- sceneBackgroundChanged: new Signal(),
- sceneFogChanged: new Signal(),
- sceneGraphChanged: new Signal(),
- cameraChanged: new Signal(),
- geometryChanged: new Signal(),
- objectSelected: new Signal(),
- objectFocused: new Signal(),
- objectAdded: new Signal(),
- objectChanged: new Signal(),
- objectRemoved: new Signal(),
- helperAdded: new Signal(),
- helperRemoved: new Signal(),
- materialChanged: new Signal(),
- scriptAdded: new Signal(),
- scriptChanged: new Signal(),
- scriptRemoved: new Signal(),
- windowResize: new Signal(),
- showGridChanged: new Signal(),
- refreshSidebarObject3D: new Signal(),
- historyChanged: new Signal()
- };
- this.config = new Config( 'threejs-editor' );
- this.history = new History( this );
- this.storage = new Storage();
- this.loader = new Loader( this );
- this.camera = this.DEFAULT_CAMERA.clone();
- this.scene = new THREE.Scene();
- this.scene.name = 'Scene';
- this.scene.background = new THREE.Color( 0xaaaaaa );
- this.sceneHelpers = new THREE.Scene();
- this.object = {};
- this.geometries = {};
- this.materials = {};
- this.textures = {};
- this.scripts = {};
- this.selected = null;
- this.helpers = {};
- };
- Editor.prototype = {
- setTheme: function ( value ) {
- document.getElementById( 'theme' ).href = value;
- this.signals.themeChanged.dispatch( value );
- },
- //
- setScene: function ( scene ) {
- this.scene.uuid = scene.uuid;
- this.scene.name = scene.name;
- if ( scene.background !== null ) this.scene.background = scene.background.clone();
- if ( scene.fog !== null ) this.scene.fog = scene.fog.clone();
- this.scene.userData = JSON.parse( JSON.stringify( scene.userData ) );
- // avoid render per object
- this.signals.sceneGraphChanged.active = false;
- while ( scene.children.length > 0 ) {
- this.addObject( scene.children[ 0 ] );
- }
- this.signals.sceneGraphChanged.active = true;
- this.signals.sceneGraphChanged.dispatch();
- },
- //
- addObject: function ( object ) {
- var scope = this;
- object.traverse( function ( child ) {
- if ( child.geometry !== undefined ) scope.addGeometry( child.geometry );
- if ( child.material !== undefined ) scope.addMaterial( child.material );
- scope.addHelper( child );
- } );
- this.scene.add( object );
- this.signals.objectAdded.dispatch( object );
- this.signals.sceneGraphChanged.dispatch();
- },
- moveObject: function ( object, parent, before ) {
- if ( parent === undefined ) {
- parent = this.scene;
- }
- parent.add( object );
- // sort children array
- if ( before !== undefined ) {
- var index = parent.children.indexOf( before );
- parent.children.splice( index, 0, object );
- parent.children.pop();
- }
- this.signals.sceneGraphChanged.dispatch();
- },
- nameObject: function ( object, name ) {
- object.name = name;
- this.signals.sceneGraphChanged.dispatch();
- },
- removeObject: function ( object ) {
- if ( object.parent === null ) return; // avoid deleting the camera or scene
- var scope = this;
- object.traverse( function ( child ) {
- scope.removeHelper( child );
- } );
- object.parent.remove( object );
- this.signals.objectRemoved.dispatch( object );
- this.signals.sceneGraphChanged.dispatch();
- },
- addGeometry: function ( geometry ) {
- this.geometries[ geometry.uuid ] = geometry;
- },
- setGeometryName: function ( geometry, name ) {
- geometry.name = name;
- this.signals.sceneGraphChanged.dispatch();
- },
- addMaterial: function ( material ) {
- this.materials[ material.uuid ] = material;
- },
- setMaterialName: function ( material, name ) {
- material.name = name;
- this.signals.sceneGraphChanged.dispatch();
- },
- addTexture: function ( texture ) {
- this.textures[ texture.uuid ] = texture;
- },
- //
- addHelper: function () {
- var geometry = new THREE.SphereBufferGeometry( 2, 4, 2 );
- var material = new THREE.MeshBasicMaterial( { color: 0xff0000, visible: false } );
- return function ( object ) {
- var helper;
- if ( object instanceof THREE.Camera ) {
- helper = new THREE.CameraHelper( object, 1 );
- } else if ( object instanceof THREE.PointLight ) {
- helper = new THREE.PointLightHelper( object, 1 );
- } else if ( object instanceof THREE.DirectionalLight ) {
- helper = new THREE.DirectionalLightHelper( object, 1 );
- } else if ( object instanceof THREE.SpotLight ) {
- helper = new THREE.SpotLightHelper( object, 1 );
- } else if ( object instanceof THREE.HemisphereLight ) {
- helper = new THREE.HemisphereLightHelper( object, 1 );
- } else if ( object instanceof THREE.SkinnedMesh ) {
- helper = new THREE.SkeletonHelper( object );
- } else {
- // no helper for this object type
- return;
- }
- var picker = new THREE.Mesh( geometry, material );
- picker.name = 'picker';
- picker.userData.object = object;
- helper.add( picker );
- this.sceneHelpers.add( helper );
- this.helpers[ object.id ] = helper;
- this.signals.helperAdded.dispatch( helper );
- };
- }(),
- removeHelper: function ( object ) {
- if ( this.helpers[ object.id ] !== undefined ) {
- var helper = this.helpers[ object.id ];
- helper.parent.remove( helper );
- delete this.helpers[ object.id ];
- this.signals.helperRemoved.dispatch( helper );
- }
- },
- //
- addScript: function ( object, script ) {
- if ( this.scripts[ object.uuid ] === undefined ) {
- this.scripts[ object.uuid ] = [];
- }
- this.scripts[ object.uuid ].push( script );
- this.signals.scriptAdded.dispatch( script );
- },
- removeScript: function ( object, script ) {
- if ( this.scripts[ object.uuid ] === undefined ) return;
- var index = this.scripts[ object.uuid ].indexOf( script );
- if ( index !== - 1 ) {
- this.scripts[ object.uuid ].splice( index, 1 );
- }
- this.signals.scriptRemoved.dispatch( script );
- },
- getObjectMaterial: function ( object, slot ) {
- var material = object.material;
- if ( Array.isArray( material ) ) {
- material = material[ slot ];
- }
- return material;
- },
- setObjectMaterial: function ( object, slot, newMaterial ) {
- if ( Array.isArray( object.material ) ) {
- object.material[ slot ] = newMaterial;
- } else {
- object.material = newMaterial;
- }
- },
- //
- select: function ( object ) {
- if ( this.selected === object ) return;
- var uuid = null;
- if ( object !== null ) {
- uuid = object.uuid;
- }
- this.selected = object;
- this.config.setKey( 'selected', uuid );
- this.signals.objectSelected.dispatch( object );
- },
- selectById: function ( id ) {
- if ( id === this.camera.id ) {
- this.select( this.camera );
- return;
- }
- this.select( this.scene.getObjectById( id, true ) );
- },
- selectByUuid: function ( uuid ) {
- var scope = this;
- this.scene.traverse( function ( child ) {
- if ( child.uuid === uuid ) {
- scope.select( child );
- }
- } );
- },
- deselect: function () {
- this.select( null );
- },
- focus: function ( object ) {
- this.signals.objectFocused.dispatch( object );
- },
- focusById: function ( id ) {
- this.focus( this.scene.getObjectById( id, true ) );
- },
- clear: function () {
- this.history.clear();
- this.storage.clear();
- this.camera.copy( this.DEFAULT_CAMERA );
- this.scene.background.setHex( 0xaaaaaa );
- this.scene.fog = null;
- var objects = this.scene.children;
- while ( objects.length > 0 ) {
- this.removeObject( objects[ 0 ] );
- }
- this.geometries = {};
- this.materials = {};
- this.textures = {};
- this.scripts = {};
- this.deselect();
- this.signals.editorCleared.dispatch();
- },
- //
- fromJSON: function ( json ) {
- var loader = new THREE.ObjectLoader();
- // backwards
- if ( json.scene === undefined ) {
- this.setScene( loader.parse( json ) );
- return;
- }
- var camera = loader.parse( json.camera );
- this.camera.copy( camera );
- this.camera.aspect = this.DEFAULT_CAMERA.aspect;
- this.camera.updateProjectionMatrix();
- this.history.fromJSON( json.history );
- this.scripts = json.scripts;
- this.setScene( loader.parse( json.scene ) );
- },
- toJSON: function () {
- // scripts clean up
- var scene = this.scene;
- var scripts = this.scripts;
- for ( var key in scripts ) {
- var script = scripts[ key ];
- if ( script.length === 0 || scene.getObjectByProperty( 'uuid', key ) === undefined ) {
- delete scripts[ key ];
- }
- }
- //
- return {
- metadata: {},
- project: {
- gammaInput: this.config.getKey( 'project/renderer/gammaInput' ),
- gammaOutput: this.config.getKey( 'project/renderer/gammaOutput' ),
- shadows: this.config.getKey( 'project/renderer/shadows' ),
- vr: this.config.getKey( 'project/vr' )
- },
- camera: this.camera.toJSON(),
- scene: this.scene.toJSON(),
- scripts: this.scripts,
- history: this.history.toJSON()
- };
- },
- objectByUuid: function ( uuid ) {
- return this.scene.getObjectByProperty( 'uuid', uuid, true );
- },
- execute: function ( cmd, optionalName ) {
- this.history.execute( cmd, optionalName );
- },
- undo: function () {
- this.history.undo();
- },
- redo: function () {
- this.history.redo();
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Editor', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- History = function ( editor ) {
- this.editor = editor;
- this.undos = [];
- this.redos = [];
- this.lastCmdTime = new Date();
- this.idCounter = 0;
- this.historyDisabled = false;
- this.config = editor.config;
- //Set editor-reference in Command
- Command( editor );
- // signals
- var scope = this;
- this.editor.signals.startPlayer.add( function () {
- scope.historyDisabled = true;
- } );
- this.editor.signals.stopPlayer.add( function () {
- scope.historyDisabled = false;
- } );
- };
- History.prototype = {
- execute: function ( cmd, optionalName ) {
- var lastCmd = this.undos[ this.undos.length - 1 ];
- var timeDifference = new Date().getTime() - this.lastCmdTime.getTime();
- var isUpdatableCmd = lastCmd &&
- lastCmd.updatable &&
- cmd.updatable &&
- lastCmd.object === cmd.object &&
- lastCmd.type === cmd.type &&
- lastCmd.script === cmd.script &&
- lastCmd.attributeName === cmd.attributeName;
- if ( isUpdatableCmd && cmd.type === "SetScriptValueCommand" ) {
- // When the cmd.type is "SetScriptValueCommand" the timeDifference is ignored
- lastCmd.update( cmd );
- cmd = lastCmd;
- } else if ( isUpdatableCmd && timeDifference < 500 ) {
- lastCmd.update( cmd );
- cmd = lastCmd;
- } else {
- // the command is not updatable and is added as a new part of the history
- this.undos.push( cmd );
- cmd.id = ++ this.idCounter;
- }
- cmd.name = ( optionalName !== undefined ) ? optionalName : cmd.name;
- cmd.execute();
- cmd.inMemory = true;
- if ( this.config.getKey( 'settings/history' ) ) {
- cmd.json = cmd.toJSON(); // serialize the cmd immediately after execution and append the json to the cmd
- }
- this.lastCmdTime = new Date();
- // clearing all the redo-commands
- this.redos = [];
- this.editor.signals.historyChanged.dispatch( cmd );
- },
- undo: function () {
- if ( this.historyDisabled ) {
- alert( "Undo/Redo disabled while scene is playing." );
- return;
- }
- var cmd = undefined;
- if ( this.undos.length > 0 ) {
- cmd = this.undos.pop();
- if ( cmd.inMemory === false ) {
- cmd.fromJSON( cmd.json );
- }
- }
- if ( cmd !== undefined ) {
- cmd.undo();
- this.redos.push( cmd );
- this.editor.signals.historyChanged.dispatch( cmd );
- }
- return cmd;
- },
- redo: function () {
- if ( this.historyDisabled ) {
- alert( "Undo/Redo disabled while scene is playing." );
- return;
- }
- var cmd = undefined;
- if ( this.redos.length > 0 ) {
- cmd = this.redos.pop();
- if ( cmd.inMemory === false ) {
- cmd.fromJSON( cmd.json );
- }
- }
- if ( cmd !== undefined ) {
- cmd.execute();
- this.undos.push( cmd );
- this.editor.signals.historyChanged.dispatch( cmd );
- }
- return cmd;
- },
- toJSON: function () {
- var history = {};
- history.undos = [];
- history.redos = [];
- if ( ! this.config.getKey( 'settings/history' ) ) {
- return history;
- }
- // Append Undos to History
- for ( var i = 0 ; i < this.undos.length; i ++ ) {
- if ( this.undos[ i ].hasOwnProperty( "json" ) ) {
- history.undos.push( this.undos[ i ].json );
- }
- }
- // Append Redos to History
- for ( var i = 0 ; i < this.redos.length; i ++ ) {
- if ( this.redos[ i ].hasOwnProperty( "json" ) ) {
- history.redos.push( this.redos[ i ].json );
- }
- }
- return history;
- },
- fromJSON: function ( json ) {
- if ( json === undefined ) return;
- for ( var i = 0; i < json.undos.length; i ++ ) {
- var cmdJSON = json.undos[ i ];
- var cmd = new window[ cmdJSON.type ](); // creates a new object of type "json.type"
- cmd.json = cmdJSON;
- cmd.id = cmdJSON.id;
- cmd.name = cmdJSON.name;
- this.undos.push( cmd );
- this.idCounter = ( cmdJSON.id > this.idCounter ) ? cmdJSON.id : this.idCounter; // set last used idCounter
- }
- for ( var i = 0; i < json.redos.length; i ++ ) {
- var cmdJSON = json.redos[ i ];
- var cmd = new window[ cmdJSON.type ](); // creates a new object of type "json.type"
- cmd.json = cmdJSON;
- cmd.id = cmdJSON.id;
- cmd.name = cmdJSON.name;
- this.redos.push( cmd );
- this.idCounter = ( cmdJSON.id > this.idCounter ) ? cmdJSON.id : this.idCounter; // set last used idCounter
- }
- // Select the last executed undo-command
- this.editor.signals.historyChanged.dispatch( this.undos[ this.undos.length - 1 ] );
- },
- clear: function () {
- this.undos = [];
- this.redos = [];
- this.idCounter = 0;
- this.editor.signals.historyChanged.dispatch();
- },
- goToState: function ( id ) {
- if ( this.historyDisabled ) {
- alert( "Undo/Redo disabled while scene is playing." );
- return;
- }
- this.editor.signals.sceneGraphChanged.active = false;
- this.editor.signals.historyChanged.active = false;
- var cmd = this.undos.length > 0 ? this.undos[ this.undos.length - 1 ] : undefined; // next cmd to pop
- if ( cmd === undefined || id > cmd.id ) {
- cmd = this.redo();
- while ( cmd !== undefined && id > cmd.id ) {
- cmd = this.redo();
- }
- } else {
- while ( true ) {
- cmd = this.undos[ this.undos.length - 1 ]; // next cmd to pop
- if ( cmd === undefined || id === cmd.id ) break;
- this.undo();
- }
- }
- this.editor.signals.sceneGraphChanged.active = true;
- this.editor.signals.historyChanged.active = true;
- this.editor.signals.sceneGraphChanged.dispatch();
- this.editor.signals.historyChanged.dispatch( cmd );
- },
- enableSerialization: function ( id ) {
- /**
- * because there might be commands in this.undos and this.redos
- * which have not been serialized with .toJSON() we go back
- * to the oldest command and redo one command after the other
- * while also calling .toJSON() on them.
- */
- this.goToState( - 1 );
- this.editor.signals.sceneGraphChanged.active = false;
- this.editor.signals.historyChanged.active = false;
- var cmd = this.redo();
- while ( cmd !== undefined ) {
- if ( ! cmd.hasOwnProperty( "json" ) ) {
- cmd.json = cmd.toJSON();
- }
- cmd = this.redo();
- }
- this.editor.signals.sceneGraphChanged.active = true;
- this.editor.signals.historyChanged.active = true;
- this.goToState( id );
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'History', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Loader', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Player', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Script', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Menubar', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Menubar.Add = function ( editor ) {
- var container = new UI.Panel();
- container.setClass( 'menu' );
- var title = new UI.Panel();
- title.setClass( 'title' );
- title.setTextContent( 'Add' );
- container.add( title );
- var options = new UI.Panel();
- options.setClass( 'options' );
- container.add( options );
- //
- var meshCount = 0;
- var lightCount = 0;
- var cameraCount = 0;
- editor.signals.editorCleared.add( function () {
- meshCount = 0;
- lightCount = 0;
- cameraCount = 0;
- } );
- // Group
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Group' );
- option.onClick( function () {
- var mesh = new THREE.Group();
- mesh.name = 'Group ' + ( ++ meshCount );
- editor.execute( new AddObjectCommand( mesh ) );
- } );
- options.add( option );
- //
- options.add( new UI.HorizontalRule() );
- // Plane
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Plane' );
- option.onClick( function () {
- var geometry = new THREE.PlaneBufferGeometry( 1, 1, 1, 1 );
- var material = new THREE.MeshStandardMaterial();
- var mesh = new THREE.Mesh( geometry, material );
- mesh.name = 'Plane ' + ( ++ meshCount );
- editor.execute( new AddObjectCommand( mesh ) );
- } );
- options.add( option );
- // Box
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Box' );
- option.onClick( function () {
- var geometry = new THREE.BoxBufferGeometry( 1, 1, 1, 1, 1, 1 );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
- mesh.name = 'Box ' + ( ++ meshCount );
- editor.execute( new AddObjectCommand( mesh ) );
- } );
- options.add( option );
- // Circle
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Circle' );
- option.onClick( function () {
- var geometry = new THREE.CircleBufferGeometry( 1, 8, 0, Math.PI * 2 );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
- mesh.name = 'Circle ' + ( ++ meshCount );
- editor.execute( new AddObjectCommand( mesh ) );
- } );
- options.add( option );
- // Cylinder
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Cylinder' );
- option.onClick( function () {
- var geometry = new THREE.CylinderBufferGeometry( 1, 1, 1, 8, 1, false, 0, Math.PI * 2 );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
- mesh.name = 'Cylinder ' + ( ++ meshCount );
- editor.execute( new AddObjectCommand( mesh ) );
- } );
- options.add( option );
- // Sphere
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Sphere' );
- option.onClick( function () {
- var geometry = new THREE.SphereBufferGeometry( 1, 8, 6, 0, Math.PI * 2, 0, Math.PI );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
- mesh.name = 'Sphere ' + ( ++ meshCount );
- editor.execute( new AddObjectCommand( mesh ) );
- } );
- options.add( option );
- // Icosahedron
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Icosahedron' );
- option.onClick( function () {
- var geometry = new THREE.IcosahedronGeometry( 1, 0 );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
- mesh.name = 'Icosahedron ' + ( ++ meshCount );
- editor.execute( new AddObjectCommand( mesh ) );
- } );
- options.add( option );
- // Torus
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Torus' );
- option.onClick( function () {
- var geometry = new THREE.TorusBufferGeometry( 1, 0.4, 8, 6, Math.PI * 2 );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
- mesh.name = 'Torus ' + ( ++ meshCount );
- editor.execute( new AddObjectCommand( mesh ) );
- } );
- options.add( option );
- // TorusKnot
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'TorusKnot' );
- option.onClick( function () {
- var geometry = new THREE.TorusKnotBufferGeometry( 1, 0.4, 64, 8, 2, 3 );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
- mesh.name = 'TorusKnot ' + ( ++ meshCount );
- editor.execute( new AddObjectCommand( mesh ) );
- } );
- options.add( option );
- /*
- // Teapot
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Teapot' );
- option.onClick( function () {
- var size = 50;
- var segments = 10;
- var bottom = true;
- var lid = true;
- var body = true;
- var fitLid = false;
- var blinnScale = true;
- var material = new THREE.MeshStandardMaterial();
- var geometry = new THREE.TeapotBufferGeometry( size, segments, bottom, lid, body, fitLid, blinnScale );
- var mesh = new THREE.Mesh( geometry, material );
- mesh.name = 'Teapot ' + ( ++ meshCount );
- editor.addObject( mesh );
- editor.select( mesh );
- } );
- options.add( option );
- */
- // Lathe
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Lathe' );
- option.onClick( function() {
- var points = [
- new THREE.Vector2( 0, 0 ),
- new THREE.Vector2( 0.4, 0 ),
- new THREE.Vector2( 0.35, 0.05 ),
- new THREE.Vector2( 0.1, 0.075 ),
- new THREE.Vector2( 0.08, 0.1 ),
- new THREE.Vector2( 0.08, 0.4 ),
- new THREE.Vector2( 0.1, 0.42 ),
- new THREE.Vector2( 0.14, 0.48 ),
- new THREE.Vector2( 0.2, 0.5 ),
- new THREE.Vector2( 0.25, 0.54 ),
- new THREE.Vector2( 0.3, 1.2 )
- ];
- var geometry = new THREE.LatheBufferGeometry( points, 12, 0, Math.PI * 2 );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial( { side: THREE.DoubleSide } ) );
- mesh.name = 'Lathe ' + ( ++ meshCount );
- editor.execute( new AddObjectCommand( mesh ) );
- } );
- options.add( option );
- // Sprite
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Sprite' );
- option.onClick( function () {
- var sprite = new THREE.Sprite( new THREE.SpriteMaterial() );
- sprite.name = 'Sprite ' + ( ++ meshCount );
- editor.execute( new AddObjectCommand( sprite ) );
- } );
- options.add( option );
- //
- options.add( new UI.HorizontalRule() );
- // PointLight
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'PointLight' );
- option.onClick( function () {
- var color = 0xffffff;
- var intensity = 1;
- var distance = 0;
- var light = new THREE.PointLight( color, intensity, distance );
- light.name = 'PointLight ' + ( ++ lightCount );
- editor.execute( new AddObjectCommand( light ) );
- } );
- options.add( option );
- // SpotLight
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'SpotLight' );
- option.onClick( function () {
- var color = 0xffffff;
- var intensity = 1;
- var distance = 0;
- var angle = Math.PI * 0.1;
- var penumbra = 0;
- var light = new THREE.SpotLight( color, intensity, distance, angle, penumbra );
- light.name = 'SpotLight ' + ( ++ lightCount );
- light.target.name = 'SpotLight ' + ( lightCount ) + ' Target';
- light.position.set( 5, 10, 7.5 );
- editor.execute( new AddObjectCommand( light ) );
- } );
- options.add( option );
- // DirectionalLight
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'DirectionalLight' );
- option.onClick( function () {
- var color = 0xffffff;
- var intensity = 1;
- var light = new THREE.DirectionalLight( color, intensity );
- light.name = 'DirectionalLight ' + ( ++ lightCount );
- light.target.name = 'DirectionalLight ' + ( lightCount ) + ' Target';
- light.position.set( 5, 10, 7.5 );
- editor.execute( new AddObjectCommand( light ) );
- } );
- options.add( option );
- // HemisphereLight
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'HemisphereLight' );
- option.onClick( function () {
- var skyColor = 0x00aaff;
- var groundColor = 0xffaa00;
- var intensity = 1;
- var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
- light.name = 'HemisphereLight ' + ( ++ lightCount );
- light.position.set( 0, 10, 0 );
- editor.execute( new AddObjectCommand( light ) );
- } );
- options.add( option );
- // AmbientLight
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'AmbientLight' );
- option.onClick( function() {
- var color = 0x222222;
- var light = new THREE.AmbientLight( color );
- light.name = 'AmbientLight ' + ( ++ lightCount );
- editor.execute( new AddObjectCommand( light ) );
- } );
- options.add( option );
- //
- options.add( new UI.HorizontalRule() );
- // PerspectiveCamera
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'PerspectiveCamera' );
- option.onClick( function() {
- var camera = new THREE.PerspectiveCamera( 50, 1, 1, 10000 );
- camera.name = 'PerspectiveCamera ' + ( ++ cameraCount );
- editor.execute( new AddObjectCommand( camera ) );
- } );
- options.add( option );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Menubar.Add', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Menubar.Edit = function ( editor ) {
- var container = new UI.Panel();
- container.setClass( 'menu' );
- var title = new UI.Panel();
- title.setClass( 'title' );
- title.setTextContent( 'Edit' );
- container.add( title );
- var options = new UI.Panel();
- options.setClass( 'options' );
- container.add( options );
- // Undo
- var undo = new UI.Row();
- undo.setClass( 'option' );
- undo.setTextContent( 'Undo (Ctrl+Z)' );
- undo.onClick( function () {
- editor.undo();
- } );
- options.add( undo );
- // Redo
- var redo = new UI.Row();
- redo.setClass( 'option' );
- redo.setTextContent( 'Redo (Ctrl+Shift+Z)' );
- redo.onClick( function () {
- editor.redo();
- } );
- options.add( redo );
- // Clear History
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Clear History' );
- option.onClick( function () {
- if ( confirm( 'The Undo/Redo History will be cleared. Are you sure?' ) ) {
- editor.history.clear();
- }
- } );
- options.add( option );
- editor.signals.historyChanged.add( function () {
- var history = editor.history;
- undo.setClass( 'option' );
- redo.setClass( 'option' );
- if ( history.undos.length == 0 ) {
- undo.setClass( 'inactive' );
- }
- if ( history.redos.length == 0 ) {
- redo.setClass( 'inactive' );
- }
- } );
- // ---
- options.add( new UI.HorizontalRule() );
- // Clone
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Clone' );
- option.onClick( function () {
- var object = editor.selected;
- if ( object.parent === null ) return; // avoid cloning the camera or scene
- object = object.clone();
- editor.execute( new AddObjectCommand( object ) );
- } );
- options.add( option );
- // Delete
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Delete (Del)' );
- option.onClick( function () {
- var object = editor.selected;
- if ( confirm( 'Delete ' + object.name + '?' ) === false ) return;
- var parent = object.parent;
- if ( parent === undefined ) return; // avoid deleting the camera or scene
- editor.execute( new RemoveObjectCommand( object ) );
- } );
- options.add( option );
- // Minify shaders
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Minify Shaders' );
- option.onClick( function() {
- var root = editor.selected || editor.scene;
- var errors = [];
- var nMaterialsChanged = 0;
- var path = [];
- function getPath ( object ) {
- path.length = 0;
- var parent = object.parent;
- if ( parent !== undefined ) getPath( parent );
- path.push( object.name || object.uuid );
- return path;
- }
- var cmds = [];
- root.traverse( function ( object ) {
- var material = object.material;
- if ( material instanceof THREE.ShaderMaterial ) {
- try {
- var shader = glslprep.minifyGlsl( [
- material.vertexShader, material.fragmentShader ] );
- cmds.push( new SetMaterialValueCommand( object, 'vertexShader', shader[ 0 ] ) );
- cmds.push( new SetMaterialValueCommand( object, 'fragmentShader', shader[ 1 ] ) );
- ++nMaterialsChanged;
- } catch ( e ) {
- var path = getPath( object ).join( "/" );
- if ( e instanceof glslprep.SyntaxError )
- errors.push( path + ":" +
- e.line + ":" + e.column + ": " + e.message );
- else {
- errors.push( path +
- ": Unexpected error (see console for details)." );
- console.error( e.stack || e );
- }
- }
- }
- } );
- if ( nMaterialsChanged > 0 ) {
- editor.execute( new MultiCmdsCommand( cmds ), 'Minify Shaders' );
- }
- window.alert( nMaterialsChanged +
- " material(s) were changed.\n" + errors.join( "\n" ) );
- } );
- options.add( option );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Menubar.Edit', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Menubar.Examples = function ( editor ) {
- var container = new UI.Panel();
- container.setClass( 'menu' );
- var title = new UI.Panel();
- title.setClass( 'title' );
- title.setTextContent( 'Examples' );
- container.add( title );
- var options = new UI.Panel();
- options.setClass( 'options' );
- container.add( options );
- // Examples
- var items = [
- { title: 'Arkanoid', file: 'arkanoid.app.json' },
- { title: 'Camera', file: 'camera.app.json' },
- { title: 'Particles', file: 'particles.app.json' },
- { title: 'Pong', file: 'pong.app.json' },
- { title: 'Shaders', file: 'shaders.app.json' }
- ];
- var loader = new THREE.FileLoader();
- for ( var i = 0; i < items.length; i ++ ) {
- ( function ( i ) {
- var item = items[ i ];
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( item.title );
- option.onClick( function () {
- if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
- loader.load( 'examples/' + item.file, function ( text ) {
- editor.clear();
- editor.fromJSON( JSON.parse( text ) );
- } );
- }
- } );
- options.add( option );
- } )( i );
- }
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Menubar.Examples', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Menubar.File = function ( editor ) {
- var NUMBER_PRECISION = 6;
- function parseNumber( key, value ) {
- return typeof value === 'number' ? parseFloat( value.toFixed( NUMBER_PRECISION ) ) : value;
- }
- //
- var container = new UI.Panel();
- container.setClass( 'menu' );
- var title = new UI.Panel();
- title.setClass( 'title' );
- title.setTextContent( 'File' );
- container.add( title );
- var options = new UI.Panel();
- options.setClass( 'options' );
- container.add( options );
- // New
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'New' );
- option.onClick( function () {
- if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
- editor.clear();
- }
- } );
- options.add( option );
- //
- options.add( new UI.HorizontalRule() );
- // Import
- var form = document.createElement( 'form' );
- form.style.display = 'none';
- document.body.appendChild( form );
- var fileInput = document.createElement( 'input' );
- fileInput.type = 'file';
- fileInput.addEventListener( 'change', function ( event ) {
- editor.loader.loadFile( fileInput.files[ 0 ] );
- form.reset();
- } );
- form.appendChild( fileInput );
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Import' );
- option.onClick( function () {
- fileInput.click();
- } );
- options.add( option );
- //
- options.add( new UI.HorizontalRule() );
- // Export Geometry
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Export Geometry' );
- option.onClick( function () {
- var object = editor.selected;
- if ( object === null ) {
- alert( 'No object selected.' );
- return;
- }
- var geometry = object.geometry;
- if ( geometry === undefined ) {
- alert( 'The selected object doesn\'t have geometry.' );
- return;
- }
- var output = geometry.toJSON();
- try {
- output = JSON.stringify( output, parseNumber, '\t' );
- output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
- } catch ( e ) {
- output = JSON.stringify( output );
- }
- saveString( output, 'geometry.json' );
- } );
- options.add( option );
- // Export Object
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Export Object' );
- option.onClick( function () {
- var object = editor.selected;
- if ( object === null ) {
- alert( 'No object selected' );
- return;
- }
- var output = object.toJSON();
- try {
- output = JSON.stringify( output, parseNumber, '\t' );
- output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
- } catch ( e ) {
- output = JSON.stringify( output );
- }
- saveString( output, 'model.json' );
- } );
- options.add( option );
- // Export Scene
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Export Scene' );
- option.onClick( function () {
- var output = editor.scene.toJSON();
- try {
- output = JSON.stringify( output, parseNumber, '\t' );
- output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
- } catch ( e ) {
- output = JSON.stringify( output );
- }
- saveString( output, 'scene.json' );
- } );
- options.add( option );
- //
- options.add( new UI.HorizontalRule() );
- // Export GLTF
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Export GLTF' );
- option.onClick( function () {
- var exporter = new THREE.GLTFExporter();
- exporter.parse( editor.scene, function ( result ) {
- saveString( JSON.stringify( result, null, 2 ), 'scene.gltf' );
- } );
- } );
- options.add( option );
- // Export OBJ
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Export OBJ' );
- option.onClick( function () {
- var object = editor.selected;
- if ( object === null ) {
- alert( 'No object selected.' );
- return;
- }
- var exporter = new THREE.OBJExporter();
- saveString( exporter.parse( object ), 'model.obj' );
- } );
- options.add( option );
- // Export STL
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Export STL' );
- option.onClick( function () {
- var exporter = new THREE.STLExporter();
- saveString( exporter.parse( editor.scene ), 'model.stl' );
- } );
- options.add( option );
- //
- options.add( new UI.HorizontalRule() );
- // Publish
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Publish' );
- option.onClick( function () {
- var zip = new JSZip();
- //
- var output = editor.toJSON();
- output.metadata.type = 'App';
- delete output.history;
- var vr = output.project.vr;
- output = JSON.stringify( output, parseNumber, '\t' );
- output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
- zip.file( 'app.json', output );
- //
- var manager = new THREE.LoadingManager( function () {
- save( zip.generate( { type: 'blob' } ), 'download.zip' );
- } );
- var loader = new THREE.FileLoader( manager );
- loader.load( 'js/libs/app/index.html', function ( content ) {
- var includes = [];
- if ( vr ) {
- includes.push( '<script src="js/WebVR.js"></script>' );
- }
- content = content.replace( '<!-- includes -->', includes.join( '\n\t\t' ) );
- var editButton = '';
- if ( editor.config.getKey( 'project/editable' ) ) {
- editButton = `
- var button = document.createElement( 'a' );
- button.href = 'https://threejs.org/editor/#file=' + location.href.split( '/' ).slice( 0, - 1 ).join( '/' ) + '/app.json';
- button.style.cssText = 'position: absolute; bottom: 20px; right: 20px; padding: 7px 10px 6px 10px; color: #fff; border: 1px solid #fff; text-decoration: none;';
- button.target = '_blank';
- button.textContent = 'EDIT';
- document.body.appendChild( button );
- `;
- }
- content = content.replace( '/* edit button */', editButton );
- zip.file( 'index.html', content );
- } );
- loader.load( 'js/libs/app.js', function ( content ) {
- zip.file( 'js/app.js', content );
- } );
- loader.load( '../build/three.min.js', function ( content ) {
- zip.file( 'js/three.min.js', content );
- } );
- if ( vr ) {
- loader.load( '../examples/js/vr/WebVR.js', function ( content ) {
- zip.file( 'js/WebVR.js', content );
- } );
- }
- } );
- options.add( option );
- /*
- // Publish (Dropbox)
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Publish (Dropbox)' );
- option.onClick( function () {
- var parameters = {
- files: [
- { 'url': 'data:text/plain;base64,' + window.btoa( "Hello, World" ), 'filename': 'app/test.txt' }
- ]
- };
- Dropbox.save( parameters );
- } );
- options.add( option );
- */
- //
- var link = document.createElement( 'a' );
- link.style.display = 'none';
- document.body.appendChild( link ); // Firefox workaround, see #6594
- function save( blob, filename ) {
- link.href = URL.createObjectURL( blob );
- link.download = filename || 'data.json';
- link.click();
- // URL.revokeObjectURL( url ); breaks Firefox...
- }
- function saveString( text, filename ) {
- save( new Blob( [ text ], { type: 'text/plain' } ), filename );
- }
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Menubar.File', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Menubar.Help = function ( editor ) {
- var container = new UI.Panel();
- container.setClass( 'menu' );
- var title = new UI.Panel();
- title.setClass( 'title' );
- title.setTextContent( 'Help' );
- container.add( title );
- var options = new UI.Panel();
- options.setClass( 'options' );
- container.add( options );
- // Source code
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'Source code' );
- option.onClick( function () {
- window.open( 'https://github.com/mrdoob/three.js/tree/master/editor', '_blank' );
- } );
- options.add( option );
- // About
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'About' );
- option.onClick( function () {
- window.open( 'http://threejs.org', '_blank' );
- } );
- options.add( option );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Menubar.Help', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Menubar.Play = function ( editor ) {
- var signals = editor.signals;
- var container = new UI.Panel();
- container.setClass( 'menu' );
- var isPlaying = false;
- var title = new UI.Panel();
- title.setClass( 'title' );
- title.setTextContent( 'Play' );
- title.onClick( function () {
- if ( isPlaying === false ) {
- isPlaying = true;
- title.setTextContent( 'Stop' );
- signals.startPlayer.dispatch();
- } else {
- isPlaying = false;
- title.setTextContent( 'Play' );
- signals.stopPlayer.dispatch();
- }
- } );
- container.add( title );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Menubar.Play', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Menubar.Status = function ( editor ) {
- var container = new UI.Panel();
- container.setClass( 'menu right' );
- var autosave = new UI.THREE.Boolean( editor.config.getKey( 'autosave' ), 'autosave' );
- autosave.text.setColor( '#888' );
- autosave.onChange( function () {
- var value = this.getValue();
- editor.config.setKey( 'autosave', value );
- if ( value === true ) {
- editor.signals.sceneGraphChanged.dispatch();
- }
- } );
- container.add( autosave );
- editor.signals.savingStarted.add( function () {
- autosave.text.setTextDecoration( 'underline' );
- } );
- editor.signals.savingFinished.add( function () {
- autosave.text.setTextDecoration( 'none' );
- } );
- var version = new UI.Text( 'r' + THREE.REVISION );
- version.setClass( 'title' );
- version.setOpacity( 0.5 );
- container.add( version );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Menubar.Status', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Menubar.View = function ( editor ) {
- var container = new UI.Panel();
- container.setClass( 'menu' );
- var title = new UI.Panel();
- title.setClass( 'title' );
- title.setTextContent( 'View' );
- container.add( title );
- var options = new UI.Panel();
- options.setClass( 'options' );
- container.add( options );
- // VR mode
- var option = new UI.Row();
- option.setClass( 'option' );
- option.setTextContent( 'VR mode' );
- option.onClick( function () {
- if ( WEBVR.isAvailable() === true ) {
- editor.signals.enterVR.dispatch();
- } else {
- alert( 'WebVR not available' );
- }
- } );
- options.add( option );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Menubar.View', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Animation = function ( editor ) {
- var signals = editor.signals;
- var options = {};
- var possibleAnimations = {};
- var container = new UI.Panel();
- container.setDisplay( 'none' );
- container.add( new UI.Text( 'Animation' ).setTextTransform( 'uppercase' ) );
- container.add( new UI.Break() );
- container.add( new UI.Break() );
- var animationsRow = new UI.Row();
- container.add( animationsRow );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Animation', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Geometry = function ( editor ) {
- var signals = editor.signals;
- var container = new UI.Panel();
- container.setBorderTop( '0' );
- container.setPaddingTop( '20px' );
- // Actions
- /*
- var objectActions = new UI.Select().setPosition( 'absolute' ).setRight( '8px' ).setFontSize( '11px' );
- objectActions.setOptions( {
- 'Actions': 'Actions',
- 'Center': 'Center',
- 'Convert': 'Convert',
- 'Flatten': 'Flatten'
- } );
- objectActions.onClick( function ( event ) {
- event.stopPropagation(); // Avoid panel collapsing
- } );
- objectActions.onChange( function ( event ) {
- var action = this.getValue();
- var object = editor.selected;
- var geometry = object.geometry;
- if ( confirm( action + ' ' + object.name + '?' ) === false ) return;
- switch ( action ) {
- case 'Center':
- var offset = geometry.center();
- var newPosition = object.position.clone();
- newPosition.sub( offset );
- editor.execute( new SetPositionCommand( object, newPosition ) );
- editor.signals.geometryChanged.dispatch( object );
- break;
- case 'Convert':
- if ( geometry instanceof THREE.Geometry ) {
- editor.execute( new SetGeometryCommand( object, new THREE.BufferGeometry().fromGeometry( geometry ) ) );
- }
- break;
- case 'Flatten':
- var newGeometry = geometry.clone();
- newGeometry.uuid = geometry.uuid;
- newGeometry.applyMatrix( object.matrix );
- var cmds = [ new SetGeometryCommand( object, newGeometry ),
- new SetPositionCommand( object, new THREE.Vector3( 0, 0, 0 ) ),
- new SetRotationCommand( object, new THREE.Euler( 0, 0, 0 ) ),
- new SetScaleCommand( object, new THREE.Vector3( 1, 1, 1 ) ) ];
- editor.execute( new MultiCmdsCommand( cmds ), 'Flatten Geometry' );
- break;
- }
- this.setValue( 'Actions' );
- } );
- container.addStatic( objectActions );
- */
- // type
- var geometryTypeRow = new UI.Row();
- var geometryType = new UI.Text();
- geometryTypeRow.add( new UI.Text( 'Type' ).setWidth( '90px' ) );
- geometryTypeRow.add( geometryType );
- container.add( geometryTypeRow );
- // uuid
- var geometryUUIDRow = new UI.Row();
- var geometryUUID = new UI.Input().setWidth( '102px' ).setFontSize( '12px' ).setDisabled( true );
- var geometryUUIDRenew = new UI.Button( 'New' ).setMarginLeft( '7px' ).onClick( function () {
- geometryUUID.setValue( THREE.Math.generateUUID() );
- editor.execute( new SetGeometryValueCommand( editor.selected, 'uuid', geometryUUID.getValue() ) );
- } );
- geometryUUIDRow.add( new UI.Text( 'UUID' ).setWidth( '90px' ) );
- geometryUUIDRow.add( geometryUUID );
- geometryUUIDRow.add( geometryUUIDRenew );
- container.add( geometryUUIDRow );
- // name
- var geometryNameRow = new UI.Row();
- var geometryName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
- editor.execute( new SetGeometryValueCommand( editor.selected, 'name', geometryName.getValue() ) );
- } );
- geometryNameRow.add( new UI.Text( 'Name' ).setWidth( '90px' ) );
- geometryNameRow.add( geometryName );
- container.add( geometryNameRow );
- // geometry
- container.add( new Sidebar.Geometry.Geometry( editor ) );
- // buffergeometry
- container.add( new Sidebar.Geometry.BufferGeometry( editor ) );
- // parameters
- var parameters = new UI.Span();
- container.add( parameters );
- //
- function build() {
- var object = editor.selected;
- if ( object && object.geometry ) {
- var geometry = object.geometry;
- container.setDisplay( 'block' );
- geometryType.setValue( geometry.type );
- geometryUUID.setValue( geometry.uuid );
- geometryName.setValue( geometry.name );
- //
- parameters.clear();
- if ( geometry.type === 'BufferGeometry' || geometry.type === 'Geometry' ) {
- parameters.add( new Sidebar.Geometry.Modifiers( editor, object ) );
- } else if ( Sidebar.Geometry[ geometry.type ] !== undefined ) {
- parameters.add( new Sidebar.Geometry[ geometry.type ]( editor, object ) );
- }
- } else {
- container.setDisplay( 'none' );
- }
- }
- signals.objectSelected.add( build );
- signals.geometryChanged.add( build );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Geometry.BoxGeometry = function ( editor, object ) {
- var signals = editor.signals;
- var container = new UI.Row();
- var geometry = object.geometry;
- var parameters = geometry.parameters;
- // width
- var widthRow = new UI.Row();
- var width = new UI.Number( parameters.width ).onChange( update );
- widthRow.add( new UI.Text( 'Width' ).setWidth( '90px' ) );
- widthRow.add( width );
- container.add( widthRow );
- // height
- var heightRow = new UI.Row();
- var height = new UI.Number( parameters.height ).onChange( update );
- heightRow.add( new UI.Text( 'Height' ).setWidth( '90px' ) );
- heightRow.add( height );
- container.add( heightRow );
- // depth
- var depthRow = new UI.Row();
- var depth = new UI.Number( parameters.depth ).onChange( update );
- depthRow.add( new UI.Text( 'Depth' ).setWidth( '90px' ) );
- depthRow.add( depth );
- container.add( depthRow );
- // widthSegments
- var widthSegmentsRow = new UI.Row();
- var widthSegments = new UI.Integer( parameters.widthSegments ).setRange( 1, Infinity ).onChange( update );
- widthSegmentsRow.add( new UI.Text( 'Width segments' ).setWidth( '90px' ) );
- widthSegmentsRow.add( widthSegments );
- container.add( widthSegmentsRow );
- // heightSegments
- var heightSegmentsRow = new UI.Row();
- var heightSegments = new UI.Integer( parameters.heightSegments ).setRange( 1, Infinity ).onChange( update );
- heightSegmentsRow.add( new UI.Text( 'Height segments' ).setWidth( '90px' ) );
- heightSegmentsRow.add( heightSegments );
- container.add( heightSegmentsRow );
- // depthSegments
- var depthSegmentsRow = new UI.Row();
- var depthSegments = new UI.Integer( parameters.depthSegments ).setRange( 1, Infinity ).onChange( update );
- depthSegmentsRow.add( new UI.Text( 'Depth segments' ).setWidth( '90px' ) );
- depthSegmentsRow.add( depthSegments );
- container.add( depthSegmentsRow );
- //
- function update() {
- editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
- width.getValue(),
- height.getValue(),
- depth.getValue(),
- widthSegments.getValue(),
- heightSegments.getValue(),
- depthSegments.getValue()
- ) ) );
- }
- return container;
- };
- Sidebar.Geometry.BoxBufferGeometry = Sidebar.Geometry.BoxGeometry;
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry.BoxGeometry', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Geometry.BufferGeometry = function ( editor ) {
- var signals = editor.signals;
- var container = new UI.Row();
- function update( object ) {
- if ( object === null ) return; // objectSelected.dispatch( null )
- if ( object === undefined ) return;
- var geometry = object.geometry;
- if ( geometry instanceof THREE.BufferGeometry ) {
- container.clear();
- container.setDisplay( 'block' );
- var index = geometry.index;
- if ( index !== null ) {
- var panel = new UI.Row();
- panel.add( new UI.Text( 'index' ).setWidth( '90px' ) );
- panel.add( new UI.Text( ( index.count ).format() ).setFontSize( '12px' ) );
- container.add( panel );
- }
- var attributes = geometry.attributes;
- for ( var name in attributes ) {
- var attribute = attributes[ name ];
- var panel = new UI.Row();
- panel.add( new UI.Text( name ).setWidth( '90px' ) );
- panel.add( new UI.Text( ( attribute.count ).format() + ' (' + attribute.itemSize + ')' ).setFontSize( '12px' ) );
- container.add( panel );
- }
- } else {
- container.setDisplay( 'none' );
- }
- }
- signals.objectSelected.add( update );
- signals.geometryChanged.add( update );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry.BufferGeometry', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Geometry.CircleGeometry = function ( editor, object ) {
- var signals = editor.signals;
- var container = new UI.Row();
- var geometry = object.geometry;
- var parameters = geometry.parameters;
- // radius
- var radiusRow = new UI.Row();
- var radius = new UI.Number( parameters.radius ).onChange( update );
- radiusRow.add( new UI.Text( 'Radius' ).setWidth( '90px' ) );
- radiusRow.add( radius );
- container.add( radiusRow );
- // segments
- var segmentsRow = new UI.Row();
- var segments = new UI.Integer( parameters.segments ).setRange( 3, Infinity ).onChange( update );
- segmentsRow.add( new UI.Text( 'Segments' ).setWidth( '90px' ) );
- segmentsRow.add( segments );
- container.add( segmentsRow );
- // thetaStart
- var thetaStartRow = new UI.Row();
- var thetaStart = new UI.Number( parameters.thetaStart ).onChange( update );
- thetaStartRow.add( new UI.Text( 'Theta start' ).setWidth( '90px' ) );
- thetaStartRow.add( thetaStart );
- container.add( thetaStartRow );
- // thetaLength
- var thetaLengthRow = new UI.Row();
- var thetaLength = new UI.Number( parameters.thetaLength ).onChange( update );
- thetaLengthRow.add( new UI.Text( 'Theta length' ).setWidth( '90px' ) );
- thetaLengthRow.add( thetaLength );
- container.add( thetaLengthRow );
- //
- function update() {
- editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
- radius.getValue(),
- segments.getValue(),
- thetaStart.getValue(),
- thetaLength.getValue()
- ) ) );
- }
- return container;
- };
- Sidebar.Geometry.CircleBufferGeometry = Sidebar.Geometry.CircleGeometry;
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry.CircleGeometry', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Geometry.CylinderGeometry = function ( editor, object ) {
- var signals = editor.signals;
- var container = new UI.Row();
- var geometry = object.geometry;
- var parameters = geometry.parameters;
- // radiusTop
- var radiusTopRow = new UI.Row();
- var radiusTop = new UI.Number( parameters.radiusTop ).onChange( update );
- radiusTopRow.add( new UI.Text( 'Radius top' ).setWidth( '90px' ) );
- radiusTopRow.add( radiusTop );
- container.add( radiusTopRow );
- // radiusBottom
- var radiusBottomRow = new UI.Row();
- var radiusBottom = new UI.Number( parameters.radiusBottom ).onChange( update );
- radiusBottomRow.add( new UI.Text( 'Radius bottom' ).setWidth( '90px' ) );
- radiusBottomRow.add( radiusBottom );
- container.add( radiusBottomRow );
- // height
- var heightRow = new UI.Row();
- var height = new UI.Number( parameters.height ).onChange( update );
- heightRow.add( new UI.Text( 'Height' ).setWidth( '90px' ) );
- heightRow.add( height );
- container.add( heightRow );
- // radialSegments
- var radialSegmentsRow = new UI.Row();
- var radialSegments = new UI.Integer( parameters.radialSegments ).setRange( 1, Infinity ).onChange( update );
- radialSegmentsRow.add( new UI.Text( 'Radial segments' ).setWidth( '90px' ) );
- radialSegmentsRow.add( radialSegments );
- container.add( radialSegmentsRow );
- // heightSegments
- var heightSegmentsRow = new UI.Row();
- var heightSegments = new UI.Integer( parameters.heightSegments ).setRange( 1, Infinity ).onChange( update );
- heightSegmentsRow.add( new UI.Text( 'Height segments' ).setWidth( '90px' ) );
- heightSegmentsRow.add( heightSegments );
- container.add( heightSegmentsRow );
- // openEnded
- var openEndedRow = new UI.Row();
- var openEnded = new UI.Checkbox( parameters.openEnded ).onChange( update );
- openEndedRow.add( new UI.Text( 'Open ended' ).setWidth( '90px' ) );
- openEndedRow.add( openEnded );
- container.add( openEndedRow );
- //
- function update() {
- editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
- radiusTop.getValue(),
- radiusBottom.getValue(),
- height.getValue(),
- radialSegments.getValue(),
- heightSegments.getValue(),
- openEnded.getValue()
- ) ) );
- }
- return container;
- };
- Sidebar.Geometry.CylinderBufferGeometry = Sidebar.Geometry.CylinderGeometry;
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry.CylinderGeometry', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Geometry.IcosahedronGeometry = function ( editor, object ) {
- var signals = editor.signals;
- var container = new UI.Row();
- var geometry = object.geometry;
- var parameters = geometry.parameters;
- // radius
- var radiusRow = new UI.Row();
- var radius = new UI.Number( parameters.radius ).onChange( update );
- radiusRow.add( new UI.Text( 'Radius' ).setWidth( '90px' ) );
- radiusRow.add( radius );
- container.add( radiusRow );
- // detail
- var detailRow = new UI.Row();
- var detail = new UI.Integer( parameters.detail ).setRange( 0, Infinity ).onChange( update );
- detailRow.add( new UI.Text( 'Detail' ).setWidth( '90px' ) );
- detailRow.add( detail );
- container.add( detailRow );
- //
- function update() {
- editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
- radius.getValue(),
- detail.getValue()
- ) ) );
- signals.objectChanged.dispatch( object );
- }
- return container;
- };
- Sidebar.Geometry.IcosahedronBufferGeometry = Sidebar.Geometry.IcosahedronGeometry;
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry.IcosahedronGeometry', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author rfm1201
- */
- Sidebar.Geometry.LatheGeometry = function( editor, object ) {
- var signals = editor.signals;
- var container = new UI.Row();
- var geometry = object.geometry;
- var parameters = geometry.parameters;
- // segments
- var segmentsRow = new UI.Row();
- var segments = new UI.Integer( parameters.segments ).onChange( update );
- segmentsRow.add( new UI.Text( 'Segments' ).setWidth( '90px' ) );
- segmentsRow.add( segments );
- container.add( segmentsRow );
- // phiStart
- var phiStartRow = new UI.Row();
- var phiStart = new UI.Number( parameters.phiStart * 180 / Math.PI ).onChange( update );
- phiStartRow.add( new UI.Text( 'Phi start (°)' ).setWidth( '90px' ) );
- phiStartRow.add( phiStart );
- container.add( phiStartRow );
- // phiLength
- var phiLengthRow = new UI.Row();
- var phiLength = new UI.Number( parameters.phiLength * 180 / Math.PI ).onChange( update );
- phiLengthRow.add( new UI.Text( 'Phi length (°)' ).setWidth( '90px' ) );
- phiLengthRow.add( phiLength );
- container.add( phiLengthRow );
- // points
- var lastPointIdx = 0;
- var pointsUI = [];
- var pointsRow = new UI.Row();
- pointsRow.add( new UI.Text( 'Points' ).setWidth( '90px' ) );
- var points = new UI.Span().setDisplay( 'inline-block' );
- pointsRow.add( points );
- var pointsList = new UI.Div();
- points.add( pointsList );
- for ( var i = 0; i < parameters.points.length; i ++ ) {
- var point = parameters.points[ i ];
- pointsList.add( createPointRow( point.x, point.y ) );
- }
- var addPointButton = new UI.Button( '+' ).onClick( function() {
- if( pointsUI.length === 0 ){
- pointsList.add( createPointRow( 0, 0 ) );
- } else {
- var point = pointsUI[ pointsUI.length - 1 ];
- pointsList.add( createPointRow( point.x.getValue(), point.y.getValue() ) );
- }
- update();
- } );
- points.add( addPointButton );
- container.add( pointsRow );
- //
- function createPointRow( x, y ) {
- var pointRow = new UI.Div();
- var lbl = new UI.Text( lastPointIdx + 1 ).setWidth( '20px' );
- var txtX = new UI.Number( x ).setRange( 0, Infinity ).setWidth( '40px' ).onChange( update );
- var txtY = new UI.Number( y ).setWidth( '40px' ).onChange( update );
- var idx = lastPointIdx;
- var btn = new UI.Button( '-' ).onClick( function() {
- deletePointRow( idx );
- } );
- pointsUI.push( { row: pointRow, lbl: lbl, x: txtX, y: txtY } );
- lastPointIdx ++;
- pointRow.add( lbl, txtX, txtY, btn );
- return pointRow;
- }
- function deletePointRow( idx ) {
- if ( ! pointsUI[ idx ] ) return;
- pointsList.remove( pointsUI[ idx ].row );
- pointsUI[ idx ] = null;
- update();
- }
- function update() {
- var points = [];
- var count = 0;
- for ( var i = 0; i < pointsUI.length; i ++ ) {
- var pointUI = pointsUI[ i ];
- if ( ! pointUI ) continue;
- points.push( new THREE.Vector2( pointUI.x.getValue(), pointUI.y.getValue() ) );
- count ++;
- pointUI.lbl.setValue( count );
- }
- editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
- points,
- segments.getValue(),
- phiStart.getValue() / 180 * Math.PI,
- phiLength.getValue() / 180 * Math.PI
- ) ) );
- }
- return container;
- };
- Sidebar.Geometry.LatheBufferGeometry = Sidebar.Geometry.LatheGeometry;
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry.LatheGeometry', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Geometry.Modifiers = function ( editor, object ) {
- var signals = editor.signals;
- var container = new UI.Row().setPaddingLeft( '90px' );
- var geometry = object.geometry;
- // Compute Vertex Normals
- var button = new UI.Button( 'Compute Vertex Normals' );
- button.onClick( function () {
- geometry.computeVertexNormals();
- if ( geometry instanceof THREE.BufferGeometry ) {
- geometry.attributes.normal.needsUpdate = true;
- } else {
- geometry.normalsNeedUpdate = true;
- }
- signals.geometryChanged.dispatch( object );
- } );
- container.add( button );
- //
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry.Modifiers', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Geometry.PlaneGeometry = function ( editor, object ) {
- var signals = editor.signals;
- var container = new UI.Row();
- var geometry = object.geometry;
- var parameters = geometry.parameters;
- // width
- var widthRow = new UI.Row();
- var width = new UI.Number( parameters.width ).onChange( update );
- widthRow.add( new UI.Text( 'Width' ).setWidth( '90px' ) );
- widthRow.add( width );
- container.add( widthRow );
- // height
- var heightRow = new UI.Row();
- var height = new UI.Number( parameters.height ).onChange( update );
- heightRow.add( new UI.Text( 'Height' ).setWidth( '90px' ) );
- heightRow.add( height );
- container.add( heightRow );
- // widthSegments
- var widthSegmentsRow = new UI.Row();
- var widthSegments = new UI.Integer( parameters.widthSegments ).setRange( 1, Infinity ).onChange( update );
- widthSegmentsRow.add( new UI.Text( 'Width segments' ).setWidth( '90px' ) );
- widthSegmentsRow.add( widthSegments );
- container.add( widthSegmentsRow );
- // heightSegments
- var heightSegmentsRow = new UI.Row();
- var heightSegments = new UI.Integer( parameters.heightSegments ).setRange( 1, Infinity ).onChange( update );
- heightSegmentsRow.add( new UI.Text( 'Height segments' ).setWidth( '90px' ) );
- heightSegmentsRow.add( heightSegments );
- container.add( heightSegmentsRow );
- //
- function update() {
- editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
- width.getValue(),
- height.getValue(),
- widthSegments.getValue(),
- heightSegments.getValue()
- ) ) );
- }
- return container;
- };
- Sidebar.Geometry.PlaneBufferGeometry = Sidebar.Geometry.PlaneGeometry;
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry.PlaneGeometry', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Geometry.SphereGeometry = function ( editor, object ) {
- var signals = editor.signals;
- var container = new UI.Row();
- var geometry = object.geometry;
- var parameters = geometry.parameters;
- // radius
- var radiusRow = new UI.Row();
- var radius = new UI.Number( parameters.radius ).onChange( update );
- radiusRow.add( new UI.Text( 'Radius' ).setWidth( '90px' ) );
- radiusRow.add( radius );
- container.add( radiusRow );
- // widthSegments
- var widthSegmentsRow = new UI.Row();
- var widthSegments = new UI.Integer( parameters.widthSegments ).setRange( 1, Infinity ).onChange( update );
- widthSegmentsRow.add( new UI.Text( 'Width segments' ).setWidth( '90px' ) );
- widthSegmentsRow.add( widthSegments );
- container.add( widthSegmentsRow );
- // heightSegments
- var heightSegmentsRow = new UI.Row();
- var heightSegments = new UI.Integer( parameters.heightSegments ).setRange( 1, Infinity ).onChange( update );
- heightSegmentsRow.add( new UI.Text( 'Height segments' ).setWidth( '90px' ) );
- heightSegmentsRow.add( heightSegments );
- container.add( heightSegmentsRow );
- // phiStart
- var phiStartRow = new UI.Row();
- var phiStart = new UI.Number( parameters.phiStart ).onChange( update );
- phiStartRow.add( new UI.Text( 'Phi start' ).setWidth( '90px' ) );
- phiStartRow.add( phiStart );
- container.add( phiStartRow );
- // phiLength
- var phiLengthRow = new UI.Row();
- var phiLength = new UI.Number( parameters.phiLength ).onChange( update );
- phiLengthRow.add( new UI.Text( 'Phi length' ).setWidth( '90px' ) );
- phiLengthRow.add( phiLength );
- container.add( phiLengthRow );
- // thetaStart
- var thetaStartRow = new UI.Row();
- var thetaStart = new UI.Number( parameters.thetaStart ).onChange( update );
- thetaStartRow.add( new UI.Text( 'Theta start' ).setWidth( '90px' ) );
- thetaStartRow.add( thetaStart );
- container.add( thetaStartRow );
- // thetaLength
- var thetaLengthRow = new UI.Row();
- var thetaLength = new UI.Number( parameters.thetaLength ).onChange( update );
- thetaLengthRow.add( new UI.Text( 'Theta length' ).setWidth( '90px' ) );
- thetaLengthRow.add( thetaLength );
- container.add( thetaLengthRow );
- //
- function update() {
- editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
- radius.getValue(),
- widthSegments.getValue(),
- heightSegments.getValue(),
- phiStart.getValue(),
- phiLength.getValue(),
- thetaStart.getValue(),
- thetaLength.getValue()
- ) ) );
- }
- return container;
- };
- Sidebar.Geometry.SphereBufferGeometry = Sidebar.Geometry.SphereGeometry;
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry.SphereGeometry', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author tschw
- */
- Sidebar.Geometry.TeapotBufferGeometry = function ( signals, object ) {
- var container = new UI.Row();
- var parameters = object.geometry.parameters;
- // size
- var sizeRow = new UI.Row();
- var size = new UI.Number( parameters.size ).onChange( update );
- sizeRow.add( new UI.Text( 'Size' ).setWidth( '90px' ) );
- sizeRow.add( size );
- container.add( sizeRow );
- // segments
- var segmentsRow = new UI.Row();
- var segments = new UI.Integer( parameters.segments ).setRange( 1, Infinity ).onChange( update );
- segmentsRow.add( new UI.Text( 'Segments' ).setWidth( '90px' ) );
- segmentsRow.add( segments );
- container.add( segmentsRow );
- // bottom
- var bottomRow = new UI.Row();
- var bottom = new UI.Checkbox( parameters.bottom ).onChange( update );
- bottomRow.add( new UI.Text( 'Bottom' ).setWidth( '90px' ) );
- bottomRow.add( bottom );
- container.add( bottomRow );
- // lid
- var lidRow = new UI.Row();
- var lid = new UI.Checkbox( parameters.lid ).onChange( update );
- lidRow.add( new UI.Text( 'Lid' ).setWidth( '90px' ) );
- lidRow.add( lid );
- container.add( lidRow );
- // body
- var bodyRow = new UI.Row();
- var body = new UI.Checkbox( parameters.body ).onChange( update );
- bodyRow.add( new UI.Text( 'Body' ).setWidth( '90px' ) );
- bodyRow.add( body );
- container.add( bodyRow );
- // fitted lid
- var fitLidRow = new UI.Row();
- var fitLid = new UI.Checkbox( parameters.fitLid ).onChange( update );
- fitLidRow.add( new UI.Text( 'Fitted Lid' ).setWidth( '90px' ) );
- fitLidRow.add( fitLid );
- container.add( fitLidRow );
- // blinn-sized
- var blinnRow = new UI.Row();
- var blinn = new UI.Checkbox( parameters.blinn ).onChange( update );
- blinnRow.add( new UI.Text( 'Blinn-scaled' ).setWidth( '90px' ) );
- blinnRow.add( blinn );
- container.add( blinnRow );
- function update() {
- object.geometry.dispose();
- object.geometry = new THREE.TeapotBufferGeometry(
- size.getValue(),
- segments.getValue(),
- bottom.getValue(),
- lid.getValue(),
- body.getValue(),
- fitLid.getValue(),
- blinn.getValue()
- );
- object.geometry.computeBoundingSphere();
- signals.geometryChanged.dispatch( object );
- }
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry.TeapotBufferGeometry', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Geometry.TorusGeometry = function ( editor, object ) {
- var signals = editor.signals;
- var container = new UI.Row();
- var geometry = object.geometry;
- var parameters = geometry.parameters;
- // radius
- var radiusRow = new UI.Row();
- var radius = new UI.Number( parameters.radius ).onChange( update );
- radiusRow.add( new UI.Text( 'Radius' ).setWidth( '90px' ) );
- radiusRow.add( radius );
- container.add( radiusRow );
- // tube
- var tubeRow = new UI.Row();
- var tube = new UI.Number( parameters.tube ).onChange( update );
- tubeRow.add( new UI.Text( 'Tube' ).setWidth( '90px' ) );
- tubeRow.add( tube );
- container.add( tubeRow );
- // radialSegments
- var radialSegmentsRow = new UI.Row();
- var radialSegments = new UI.Integer( parameters.radialSegments ).setRange( 1, Infinity ).onChange( update );
- radialSegmentsRow.add( new UI.Text( 'Radial segments' ).setWidth( '90px' ) );
- radialSegmentsRow.add( radialSegments );
- container.add( radialSegmentsRow );
- // tubularSegments
- var tubularSegmentsRow = new UI.Row();
- var tubularSegments = new UI.Integer( parameters.tubularSegments ).setRange( 1, Infinity ).onChange( update );
- tubularSegmentsRow.add( new UI.Text( 'Tubular segments' ).setWidth( '90px' ) );
- tubularSegmentsRow.add( tubularSegments );
- container.add( tubularSegmentsRow );
- // arc
- var arcRow = new UI.Row();
- var arc = new UI.Number( parameters.arc ).onChange( update );
- arcRow.add( new UI.Text( 'Arc' ).setWidth( '90px' ) );
- arcRow.add( arc );
- container.add( arcRow );
- //
- function update() {
- editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
- radius.getValue(),
- tube.getValue(),
- radialSegments.getValue(),
- tubularSegments.getValue(),
- arc.getValue()
- ) ) );
- }
- return container;
- };
- Sidebar.Geometry.TorusBufferGeometry = Sidebar.Geometry.TorusGeometry;
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry.TorusGeometry', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Geometry.TorusKnotGeometry = function ( editor, object ) {
- var signals = editor.signals;
- var container = new UI.Row();
- var geometry = object.geometry;
- var parameters = geometry.parameters;
- // radius
- var radiusRow = new UI.Row();
- var radius = new UI.Number( parameters.radius ).onChange( update );
- radiusRow.add( new UI.Text( 'Radius' ).setWidth( '90px' ) );
- radiusRow.add( radius );
- container.add( radiusRow );
- // tube
- var tubeRow = new UI.Row();
- var tube = new UI.Number( parameters.tube ).onChange( update );
- tubeRow.add( new UI.Text( 'Tube' ).setWidth( '90px' ) );
- tubeRow.add( tube );
- container.add( tubeRow );
- // tubularSegments
- var tubularSegmentsRow = new UI.Row();
- var tubularSegments = new UI.Integer( parameters.tubularSegments ).setRange( 1, Infinity ).onChange( update );
- tubularSegmentsRow.add( new UI.Text( 'Tubular segments' ).setWidth( '90px' ) );
- tubularSegmentsRow.add( tubularSegments );
- container.add( tubularSegmentsRow );
- // radialSegments
- var radialSegmentsRow = new UI.Row();
- var radialSegments = new UI.Integer( parameters.radialSegments ).setRange( 1, Infinity ).onChange( update );
- radialSegmentsRow.add( new UI.Text( 'Radial segments' ).setWidth( '90px' ) );
- radialSegmentsRow.add( radialSegments );
- container.add( radialSegmentsRow );
- // p
- var pRow = new UI.Row();
- var p = new UI.Number( parameters.p ).onChange( update );
- pRow.add( new UI.Text( 'P' ).setWidth( '90px' ) );
- pRow.add( p );
- container.add( pRow );
- // q
- var qRow = new UI.Row();
- var q = new UI.Number( parameters.q ).onChange( update );
- pRow.add( new UI.Text( 'Q' ).setWidth( '90px' ) );
- pRow.add( q );
- container.add( qRow );
- //
- function update() {
- editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
- radius.getValue(),
- tube.getValue(),
- tubularSegments.getValue(),
- radialSegments.getValue(),
- p.getValue(),
- q.getValue()
- ) ) );
- }
- return container;
- };
- Sidebar.Geometry.TorusKnotBufferGeometry = Sidebar.Geometry.TorusKnotGeometry;
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Geometry.TorusKnotGeometry', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- Sidebar.History = function ( editor ) {
- var signals = editor.signals;
- var config = editor.config;
- var history = editor.history;
- var container = new UI.Panel();
- container.add( new UI.Text( 'HISTORY' ) );
- //
- var persistent = new UI.THREE.Boolean( config.getKey( 'settings/history' ), 'persistent' );
- persistent.setPosition( 'absolute' ).setRight( '8px' );
- persistent.onChange( function () {
- var value = this.getValue();
- config.setKey( 'settings/history', value );
- if ( value ) {
- alert( 'The history will be preserved across sessions.\nThis can have an impact on performance when working with textures.' );
- var lastUndoCmd = history.undos[ history.undos.length - 1 ];
- var lastUndoId = ( lastUndoCmd !== undefined ) ? lastUndoCmd.id : 0;
- editor.history.enableSerialization( lastUndoId );
- } else {
- signals.historyChanged.dispatch();
- }
- } );
- container.add( persistent );
- container.add( new UI.Break(), new UI.Break() );
- var ignoreObjectSelectedSignal = false;
- var outliner = new UI.Outliner( editor );
- outliner.onChange( function () {
- ignoreObjectSelectedSignal = true;
- editor.history.goToState( parseInt( outliner.getValue() ) );
- ignoreObjectSelectedSignal = false;
- } );
- container.add( outliner );
- //
- var refreshUI = function () {
- var options = [];
- var enumerator = 1;
- function buildOption( object ) {
- var option = document.createElement( 'div' );
- option.value = object.id;
- return option;
- }
- ( function addObjects( objects ) {
- for ( var i = 0, l = objects.length; i < l; i ++ ) {
- var object = objects[ i ];
- var option = buildOption( object );
- option.innerHTML = ' ' + object.name;
- options.push( option );
- }
- } )( history.undos );
- ( function addObjects( objects, pad ) {
- for ( var i = objects.length - 1; i >= 0; i -- ) {
- var object = objects[ i ];
- var option = buildOption( object );
- option.innerHTML = ' ' + object.name;
- option.style.opacity = 0.3;
- options.push( option );
- }
- } )( history.redos, ' ' );
- outliner.setOptions( options );
- };
- refreshUI();
- // events
- signals.editorCleared.add( refreshUI );
- signals.historyChanged.add( refreshUI );
- signals.historyChanged.add( function ( cmd ) {
- outliner.setValue( cmd !== undefined ? cmd.id : null );
- } );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.History', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Material = function ( editor ) {
- var signals = editor.signals;
- var currentObject;
- var currentMaterialSlot = 0;
- var container = new UI.Panel();
- container.setBorderTop( '0' );
- container.setPaddingTop( '20px' );
- // New / Copy / Paste
- var copiedMaterial;
- var managerRow = new UI.Row();
- // Current material slot
- var materialSlotRow = new UI.Row();
- materialSlotRow.add( new UI.Text( 'Slot' ).setWidth( '90px' ) );
- var materialSlotSelect = new UI.Select().setWidth( '170px' ).setFontSize( '12px' ).onChange( update );
- materialSlotSelect.setOptions( { 0: '' } ).setValue( 0 );
- materialSlotRow.add( materialSlotSelect );
- container.add( materialSlotRow );
- managerRow.add( new UI.Text( '' ).setWidth( '90px' ) );
- managerRow.add( new UI.Button( 'New' ).onClick( function () {
- var material = new THREE[ materialClass.getValue() ]();
- editor.execute( new SetMaterialCommand( currentObject, material, currentMaterialSlot ), 'New Material: ' + materialClass.getValue() );
- update();
- } ) );
- managerRow.add( new UI.Button( 'Copy' ).setMarginLeft( '4px' ).onClick( function () {
- copiedMaterial = currentObject.material;
- if ( Array.isArray( copiedMaterial ) ) {
- if ( copiedMaterial.length === 0 ) return;
- copiedMaterial = copiedMaterial[ currentMaterialSlot ];
- }
- } ) );
- managerRow.add( new UI.Button( 'Paste' ).setMarginLeft( '4px' ).onClick( function () {
- if ( copiedMaterial === undefined ) return;
- editor.execute( new SetMaterialCommand( currentObject, copiedMaterial, currentMaterialSlot ), 'Pasted Material: ' + materialClass.getValue() );
- refreshUI();
- update();
- } ) );
- container.add( managerRow );
- // type
- var materialClassRow = new UI.Row();
- var materialClass = new UI.Select().setOptions( {
- 'LineBasicMaterial': 'LineBasicMaterial',
- 'LineDashedMaterial': 'LineDashedMaterial',
- 'MeshBasicMaterial': 'MeshBasicMaterial',
- 'MeshDepthMaterial': 'MeshDepthMaterial',
- 'MeshNormalMaterial': 'MeshNormalMaterial',
- 'MeshLambertMaterial': 'MeshLambertMaterial',
- 'MeshPhongMaterial': 'MeshPhongMaterial',
- 'MeshStandardMaterial': 'MeshStandardMaterial',
- 'MeshPhysicalMaterial': 'MeshPhysicalMaterial',
- 'ShaderMaterial': 'ShaderMaterial',
- 'SpriteMaterial': 'SpriteMaterial'
- } ).setWidth( '150px' ).setFontSize( '12px' ).onChange( update );
- materialClassRow.add( new UI.Text( 'Type' ).setWidth( '90px' ) );
- materialClassRow.add( materialClass );
- container.add( materialClassRow );
- // uuid
- var materialUUIDRow = new UI.Row();
- var materialUUID = new UI.Input().setWidth( '102px' ).setFontSize( '12px' ).setDisabled( true );
- var materialUUIDRenew = new UI.Button( 'New' ).setMarginLeft( '7px' ).onClick( function () {
- materialUUID.setValue( THREE.Math.generateUUID() );
- update();
- } );
- materialUUIDRow.add( new UI.Text( 'UUID' ).setWidth( '90px' ) );
- materialUUIDRow.add( materialUUID );
- materialUUIDRow.add( materialUUIDRenew );
- container.add( materialUUIDRow );
- // name
- var materialNameRow = new UI.Row();
- var materialName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
- editor.execute( new SetMaterialValueCommand( editor.selected, 'name', materialName.getValue(), currentMaterialSlot ) );
- } );
- materialNameRow.add( new UI.Text( 'Name' ).setWidth( '90px' ) );
- materialNameRow.add( materialName );
- container.add( materialNameRow );
- // program
- var materialProgramRow = new UI.Row();
- materialProgramRow.add( new UI.Text( 'Program' ).setWidth( '90px' ) );
- var materialProgramInfo = new UI.Button( 'Info' );
- materialProgramInfo.setMarginLeft( '4px' );
- materialProgramInfo.onClick( function () {
- signals.editScript.dispatch( currentObject, 'programInfo' );
- } );
- materialProgramRow.add( materialProgramInfo );
- var materialProgramVertex = new UI.Button( 'Vertex' );
- materialProgramVertex.setMarginLeft( '4px' );
- materialProgramVertex.onClick( function () {
- signals.editScript.dispatch( currentObject, 'vertexShader' );
- } );
- materialProgramRow.add( materialProgramVertex );
- var materialProgramFragment = new UI.Button( 'Fragment' );
- materialProgramFragment.setMarginLeft( '4px' );
- materialProgramFragment.onClick( function () {
- signals.editScript.dispatch( currentObject, 'fragmentShader' );
- } );
- materialProgramRow.add( materialProgramFragment );
- container.add( materialProgramRow );
- // color
- var materialColorRow = new UI.Row();
- var materialColor = new UI.Color().onChange( update );
- materialColorRow.add( new UI.Text( 'Color' ).setWidth( '90px' ) );
- materialColorRow.add( materialColor );
- container.add( materialColorRow );
- // roughness
- var materialRoughnessRow = new UI.Row();
- var materialRoughness = new UI.Number( 0.5 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
- materialRoughnessRow.add( new UI.Text( 'Roughness' ).setWidth( '90px' ) );
- materialRoughnessRow.add( materialRoughness );
- container.add( materialRoughnessRow );
- // metalness
- var materialMetalnessRow = new UI.Row();
- var materialMetalness = new UI.Number( 0.5 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
- materialMetalnessRow.add( new UI.Text( 'Metalness' ).setWidth( '90px' ) );
- materialMetalnessRow.add( materialMetalness );
- container.add( materialMetalnessRow );
- // emissive
- var materialEmissiveRow = new UI.Row();
- var materialEmissive = new UI.Color().setHexValue( 0x000000 ).onChange( update );
- materialEmissiveRow.add( new UI.Text( 'Emissive' ).setWidth( '90px' ) );
- materialEmissiveRow.add( materialEmissive );
- container.add( materialEmissiveRow );
- // specular
- var materialSpecularRow = new UI.Row();
- var materialSpecular = new UI.Color().setHexValue( 0x111111 ).onChange( update );
- materialSpecularRow.add( new UI.Text( 'Specular' ).setWidth( '90px' ) );
- materialSpecularRow.add( materialSpecular );
- container.add( materialSpecularRow );
- // shininess
- var materialShininessRow = new UI.Row();
- var materialShininess = new UI.Number( 30 ).onChange( update );
- materialShininessRow.add( new UI.Text( 'Shininess' ).setWidth( '90px' ) );
- materialShininessRow.add( materialShininess );
- container.add( materialShininessRow );
- // clearCoat
- var materialClearCoatRow = new UI.Row();
- var materialClearCoat = new UI.Number( 1 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
- materialClearCoatRow.add( new UI.Text( 'ClearCoat' ).setWidth( '90px' ) );
- materialClearCoatRow.add( materialClearCoat );
- container.add( materialClearCoatRow );
- // clearCoatRoughness
- var materialClearCoatRoughnessRow = new UI.Row();
- var materialClearCoatRoughness = new UI.Number( 1 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
- materialClearCoatRoughnessRow.add( new UI.Text( 'ClearCoat Roughness' ).setWidth( '90px' ) );
- materialClearCoatRoughnessRow.add( materialClearCoatRoughness );
- container.add( materialClearCoatRoughnessRow );
- // vertex colors
- var materialVertexColorsRow = new UI.Row();
- var materialVertexColors = new UI.Select().setOptions( {
- 0: 'No',
- 1: 'Face',
- 2: 'Vertex'
- } ).onChange( update );
- materialVertexColorsRow.add( new UI.Text( 'Vertex Colors' ).setWidth( '90px' ) );
- materialVertexColorsRow.add( materialVertexColors );
- container.add( materialVertexColorsRow );
- // skinning
- var materialSkinningRow = new UI.Row();
- var materialSkinning = new UI.Checkbox( false ).onChange( update );
- materialSkinningRow.add( new UI.Text( 'Skinning' ).setWidth( '90px' ) );
- materialSkinningRow.add( materialSkinning );
- container.add( materialSkinningRow );
- // map
- var materialMapRow = new UI.Row();
- var materialMapEnabled = new UI.Checkbox( false ).onChange( update );
- var materialMap = new UI.Texture().onChange( update );
- materialMapRow.add( new UI.Text( 'Map' ).setWidth( '90px' ) );
- materialMapRow.add( materialMapEnabled );
- materialMapRow.add( materialMap );
- container.add( materialMapRow );
- // alpha map
- var materialAlphaMapRow = new UI.Row();
- var materialAlphaMapEnabled = new UI.Checkbox( false ).onChange( update );
- var materialAlphaMap = new UI.Texture().onChange( update );
- materialAlphaMapRow.add( new UI.Text( 'Alpha Map' ).setWidth( '90px' ) );
- materialAlphaMapRow.add( materialAlphaMapEnabled );
- materialAlphaMapRow.add( materialAlphaMap );
- container.add( materialAlphaMapRow );
- // bump map
- var materialBumpMapRow = new UI.Row();
- var materialBumpMapEnabled = new UI.Checkbox( false ).onChange( update );
- var materialBumpMap = new UI.Texture().onChange( update );
- var materialBumpScale = new UI.Number( 1 ).setWidth( '30px' ).onChange( update );
- materialBumpMapRow.add( new UI.Text( 'Bump Map' ).setWidth( '90px' ) );
- materialBumpMapRow.add( materialBumpMapEnabled );
- materialBumpMapRow.add( materialBumpMap );
- materialBumpMapRow.add( materialBumpScale );
- container.add( materialBumpMapRow );
- // normal map
- var materialNormalMapRow = new UI.Row();
- var materialNormalMapEnabled = new UI.Checkbox( false ).onChange( update );
- var materialNormalMap = new UI.Texture().onChange( update );
- materialNormalMapRow.add( new UI.Text( 'Normal Map' ).setWidth( '90px' ) );
- materialNormalMapRow.add( materialNormalMapEnabled );
- materialNormalMapRow.add( materialNormalMap );
- container.add( materialNormalMapRow );
- // displacement map
- var materialDisplacementMapRow = new UI.Row();
- var materialDisplacementMapEnabled = new UI.Checkbox( false ).onChange( update );
- var materialDisplacementMap = new UI.Texture().onChange( update );
- var materialDisplacementScale = new UI.Number( 1 ).setWidth( '30px' ).onChange( update );
- materialDisplacementMapRow.add( new UI.Text( 'Displace Map' ).setWidth( '90px' ) );
- materialDisplacementMapRow.add( materialDisplacementMapEnabled );
- materialDisplacementMapRow.add( materialDisplacementMap );
- materialDisplacementMapRow.add( materialDisplacementScale );
- container.add( materialDisplacementMapRow );
- // roughness map
- var materialRoughnessMapRow = new UI.Row();
- var materialRoughnessMapEnabled = new UI.Checkbox( false ).onChange( update );
- var materialRoughnessMap = new UI.Texture().onChange( update );
- materialRoughnessMapRow.add( new UI.Text( 'Rough. Map' ).setWidth( '90px' ) );
- materialRoughnessMapRow.add( materialRoughnessMapEnabled );
- materialRoughnessMapRow.add( materialRoughnessMap );
- container.add( materialRoughnessMapRow );
- // metalness map
- var materialMetalnessMapRow = new UI.Row();
- var materialMetalnessMapEnabled = new UI.Checkbox( false ).onChange( update );
- var materialMetalnessMap = new UI.Texture().onChange( update );
- materialMetalnessMapRow.add( new UI.Text( 'Metal. Map' ).setWidth( '90px' ) );
- materialMetalnessMapRow.add( materialMetalnessMapEnabled );
- materialMetalnessMapRow.add( materialMetalnessMap );
- container.add( materialMetalnessMapRow );
- // specular map
- var materialSpecularMapRow = new UI.Row();
- var materialSpecularMapEnabled = new UI.Checkbox( false ).onChange( update );
- var materialSpecularMap = new UI.Texture().onChange( update );
- materialSpecularMapRow.add( new UI.Text( 'Specular Map' ).setWidth( '90px' ) );
- materialSpecularMapRow.add( materialSpecularMapEnabled );
- materialSpecularMapRow.add( materialSpecularMap );
- container.add( materialSpecularMapRow );
- // env map
- var materialEnvMapRow = new UI.Row();
- var materialEnvMapEnabled = new UI.Checkbox( false ).onChange( update );
- var materialEnvMap = new UI.Texture( THREE.SphericalReflectionMapping ).onChange( update );
- var materialReflectivity = new UI.Number( 1 ).setWidth( '30px' ).onChange( update );
- materialEnvMapRow.add( new UI.Text( 'Env Map' ).setWidth( '90px' ) );
- materialEnvMapRow.add( materialEnvMapEnabled );
- materialEnvMapRow.add( materialEnvMap );
- materialEnvMapRow.add( materialReflectivity );
- container.add( materialEnvMapRow );
- // light map
- var materialLightMapRow = new UI.Row();
- var materialLightMapEnabled = new UI.Checkbox( false ).onChange( update );
- var materialLightMap = new UI.Texture().onChange( update );
- materialLightMapRow.add( new UI.Text( 'Light Map' ).setWidth( '90px' ) );
- materialLightMapRow.add( materialLightMapEnabled );
- materialLightMapRow.add( materialLightMap );
- container.add( materialLightMapRow );
- // ambient occlusion map
- var materialAOMapRow = new UI.Row();
- var materialAOMapEnabled = new UI.Checkbox( false ).onChange( update );
- var materialAOMap = new UI.Texture().onChange( update );
- var materialAOScale = new UI.Number( 1 ).setRange( 0, 1 ).setWidth( '30px' ).onChange( update );
- materialAOMapRow.add( new UI.Text( 'AO Map' ).setWidth( '90px' ) );
- materialAOMapRow.add( materialAOMapEnabled );
- materialAOMapRow.add( materialAOMap );
- materialAOMapRow.add( materialAOScale );
- container.add( materialAOMapRow );
- // emissive map
- var materialEmissiveMapRow = new UI.Row();
- var materialEmissiveMapEnabled = new UI.Checkbox( false ).onChange( update );
- var materialEmissiveMap = new UI.Texture().onChange( update );
- materialEmissiveMapRow.add( new UI.Text( 'Emissive Map' ).setWidth( '90px' ) );
- materialEmissiveMapRow.add( materialEmissiveMapEnabled );
- materialEmissiveMapRow.add( materialEmissiveMap );
- container.add( materialEmissiveMapRow );
- // side
- var materialSideRow = new UI.Row();
- var materialSide = new UI.Select().setOptions( {
- 0: 'Front',
- 1: 'Back',
- 2: 'Double'
- } ).setWidth( '150px' ).setFontSize( '12px' ).onChange( update );
- materialSideRow.add( new UI.Text( 'Side' ).setWidth( '90px' ) );
- materialSideRow.add( materialSide );
- container.add( materialSideRow );
- // shading
- var materialShadingRow = new UI.Row();
- var materialShading = new UI.Checkbox(false).setLeft( '100px' ).onChange( update );
- materialShadingRow.add( new UI.Text( 'Flat Shaded' ).setWidth( '90px' ) );
- materialShadingRow.add( materialShading );
- container.add( materialShadingRow );
- // blending
- var materialBlendingRow = new UI.Row();
- var materialBlending = new UI.Select().setOptions( {
- 0: 'No',
- 1: 'Normal',
- 2: 'Additive',
- 3: 'Subtractive',
- 4: 'Multiply',
- 5: 'Custom'
- } ).setWidth( '150px' ).setFontSize( '12px' ).onChange( update );
- materialBlendingRow.add( new UI.Text( 'Blending' ).setWidth( '90px' ) );
- materialBlendingRow.add( materialBlending );
- container.add( materialBlendingRow );
- // opacity
- var materialOpacityRow = new UI.Row();
- var materialOpacity = new UI.Number( 1 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
- materialOpacityRow.add( new UI.Text( 'Opacity' ).setWidth( '90px' ) );
- materialOpacityRow.add( materialOpacity );
- container.add( materialOpacityRow );
- // transparent
- var materialTransparentRow = new UI.Row();
- var materialTransparent = new UI.Checkbox().setLeft( '100px' ).onChange( update );
- materialTransparentRow.add( new UI.Text( 'Transparent' ).setWidth( '90px' ) );
- materialTransparentRow.add( materialTransparent );
- container.add( materialTransparentRow );
- // alpha test
- var materialAlphaTestRow = new UI.Row();
- var materialAlphaTest = new UI.Number().setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
- materialAlphaTestRow.add( new UI.Text( 'Alpha Test' ).setWidth( '90px' ) );
- materialAlphaTestRow.add( materialAlphaTest );
- container.add( materialAlphaTestRow );
- // wireframe
- var materialWireframeRow = new UI.Row();
- var materialWireframe = new UI.Checkbox( false ).onChange( update );
- var materialWireframeLinewidth = new UI.Number( 1 ).setWidth( '60px' ).setRange( 0, 100 ).onChange( update );
- materialWireframeRow.add( new UI.Text( 'Wireframe' ).setWidth( '90px' ) );
- materialWireframeRow.add( materialWireframe );
- materialWireframeRow.add( materialWireframeLinewidth );
- container.add( materialWireframeRow );
- //
- function update() {
- var object = currentObject;
- var geometry = object.geometry;
- var previousSelectedSlot = currentMaterialSlot;
- currentMaterialSlot = parseInt( materialSlotSelect.getValue() );
- if ( currentMaterialSlot !== previousSelectedSlot ) refreshUI( true );
- var material = editor.getObjectMaterial( currentObject, currentMaterialSlot );
- var textureWarning = false;
- var objectHasUvs = false;
- if ( object instanceof THREE.Sprite ) objectHasUvs = true;
- if ( geometry instanceof THREE.Geometry && geometry.faceVertexUvs[ 0 ].length > 0 ) objectHasUvs = true;
- if ( geometry instanceof THREE.BufferGeometry && geometry.attributes.uv !== undefined ) objectHasUvs = true;
- if ( material ) {
- if ( material.uuid !== undefined && material.uuid !== materialUUID.getValue() ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'uuid', materialUUID.getValue(), currentMaterialSlot ) );
- }
- if ( material instanceof THREE[ materialClass.getValue() ] === false ) {
- material = new THREE[ materialClass.getValue() ]();
- editor.execute( new SetMaterialCommand( currentObject, material, currentMaterialSlot ), 'New Material: ' + materialClass.getValue() );
- // TODO Copy other references in the scene graph
- // keeping name and UUID then.
- // Also there should be means to create a unique
- // copy for the current object explicitly and to
- // attach the current material to other objects.
- }
- if ( material.color !== undefined && material.color.getHex() !== materialColor.getHexValue() ) {
- editor.execute( new SetMaterialColorCommand( currentObject, 'color', materialColor.getHexValue(), currentMaterialSlot ) );
- }
- if ( material.roughness !== undefined && Math.abs( material.roughness - materialRoughness.getValue() ) >= 0.01 ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'roughness', materialRoughness.getValue(), currentMaterialSlot ) );
- }
- if ( material.metalness !== undefined && Math.abs( material.metalness - materialMetalness.getValue() ) >= 0.01 ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'metalness', materialMetalness.getValue(), currentMaterialSlot ) );
- }
- if ( material.emissive !== undefined && material.emissive.getHex() !== materialEmissive.getHexValue() ) {
- editor.execute( new SetMaterialColorCommand( currentObject, 'emissive', materialEmissive.getHexValue(), currentMaterialSlot ) );
- }
- if ( material.specular !== undefined && material.specular.getHex() !== materialSpecular.getHexValue() ) {
- editor.execute( new SetMaterialColorCommand( currentObject, 'specular', materialSpecular.getHexValue(), currentMaterialSlot ) );
- }
- if ( material.shininess !== undefined && Math.abs( material.shininess - materialShininess.getValue() ) >= 0.01 ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'shininess', materialShininess.getValue(), currentMaterialSlot ) );
- }
- if ( material.clearCoat !== undefined && Math.abs( material.clearCoat - materialClearCoat.getValue() ) >= 0.01 ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'clearCoat', materialClearCoat.getValue(), currentMaterialSlot ) );
- }
- if ( material.clearCoatRoughness !== undefined && Math.abs( material.clearCoatRoughness - materialClearCoatRoughness.getValue() ) >= 0.01 ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'clearCoatRoughness', materialClearCoatRoughness.getValue(), currentMaterialSlot ) );
- }
- if ( material.vertexColors !== undefined ) {
- var vertexColors = parseInt( materialVertexColors.getValue() );
- if ( material.vertexColors !== vertexColors ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'vertexColors', vertexColors, currentMaterialSlot ) );
- }
- }
- if ( material.skinning !== undefined && material.skinning !== materialSkinning.getValue() ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'skinning', materialSkinning.getValue(), currentMaterialSlot ) );
- }
- if ( material.map !== undefined ) {
- var mapEnabled = materialMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var map = mapEnabled ? materialMap.getValue() : null;
- if ( material.map !== map ) {
- editor.execute( new SetMaterialMapCommand( currentObject, 'map', map, currentMaterialSlot ) );
- }
- } else {
- if ( mapEnabled ) textureWarning = true;
- }
- }
- if ( material.alphaMap !== undefined ) {
- var mapEnabled = materialAlphaMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var alphaMap = mapEnabled ? materialAlphaMap.getValue() : null;
- if ( material.alphaMap !== alphaMap ) {
- editor.execute( new SetMaterialMapCommand( currentObject, 'alphaMap', alphaMap, currentMaterialSlot ) );
- }
- } else {
- if ( mapEnabled ) textureWarning = true;
- }
- }
- if ( material.bumpMap !== undefined ) {
- var bumpMapEnabled = materialBumpMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var bumpMap = bumpMapEnabled ? materialBumpMap.getValue() : null;
- if ( material.bumpMap !== bumpMap ) {
- editor.execute( new SetMaterialMapCommand( currentObject, 'bumpMap', bumpMap, currentMaterialSlot ) );
- }
- if ( material.bumpScale !== materialBumpScale.getValue() ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'bumpScale', materialBumpScale.getValue(), currentMaterialSlot ) );
- }
- } else {
- if ( bumpMapEnabled ) textureWarning = true;
- }
- }
- if ( material.normalMap !== undefined ) {
- var normalMapEnabled = materialNormalMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var normalMap = normalMapEnabled ? materialNormalMap.getValue() : null;
- if ( material.normalMap !== normalMap ) {
- editor.execute( new SetMaterialMapCommand( currentObject, 'normalMap', normalMap, currentMaterialSlot ) );
- }
- } else {
- if ( normalMapEnabled ) textureWarning = true;
- }
- }
- if ( material.displacementMap !== undefined ) {
- var displacementMapEnabled = materialDisplacementMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var displacementMap = displacementMapEnabled ? materialDisplacementMap.getValue() : null;
- if ( material.displacementMap !== displacementMap ) {
- editor.execute( new SetMaterialMapCommand( currentObject, 'displacementMap', displacementMap, currentMaterialSlot ) );
- }
- if ( material.displacementScale !== materialDisplacementScale.getValue() ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'displacementScale', materialDisplacementScale.getValue(), currentMaterialSlot ) );
- }
- } else {
- if ( displacementMapEnabled ) textureWarning = true;
- }
- }
- if ( material.roughnessMap !== undefined ) {
- var roughnessMapEnabled = materialRoughnessMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var roughnessMap = roughnessMapEnabled ? materialRoughnessMap.getValue() : null;
- if ( material.roughnessMap !== roughnessMap ) {
- editor.execute( new SetMaterialMapCommand( currentObject, 'roughnessMap', roughnessMap, currentMaterialSlot ) );
- }
- } else {
- if ( roughnessMapEnabled ) textureWarning = true;
- }
- }
- if ( material.metalnessMap !== undefined ) {
- var metalnessMapEnabled = materialMetalnessMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var metalnessMap = metalnessMapEnabled ? materialMetalnessMap.getValue() : null;
- if ( material.metalnessMap !== metalnessMap ) {
- editor.execute( new SetMaterialMapCommand( currentObject, 'metalnessMap', metalnessMap, currentMaterialSlot ) );
- }
- } else {
- if ( metalnessMapEnabled ) textureWarning = true;
- }
- }
- if ( material.specularMap !== undefined ) {
- var specularMapEnabled = materialSpecularMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var specularMap = specularMapEnabled ? materialSpecularMap.getValue() : null;
- if ( material.specularMap !== specularMap ) {
- editor.execute( new SetMaterialMapCommand( currentObject, 'specularMap', specularMap, currentMaterialSlot ) );
- }
- } else {
- if ( specularMapEnabled ) textureWarning = true;
- }
- }
- if ( material.envMap !== undefined ) {
- var envMapEnabled = materialEnvMapEnabled.getValue() === true;
- var envMap = envMapEnabled ? materialEnvMap.getValue() : null;
- if ( material.envMap !== envMap ) {
- editor.execute( new SetMaterialMapCommand( currentObject, 'envMap', envMap, currentMaterialSlot ) );
- }
- }
- if ( material.reflectivity !== undefined ) {
- var reflectivity = materialReflectivity.getValue();
- if ( material.reflectivity !== reflectivity ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'reflectivity', reflectivity, currentMaterialSlot ) );
- }
- }
- if ( material.lightMap !== undefined ) {
- var lightMapEnabled = materialLightMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var lightMap = lightMapEnabled ? materialLightMap.getValue() : null;
- if ( material.lightMap !== lightMap ) {
- editor.execute( new SetMaterialMapCommand( currentObject, 'lightMap', lightMap, currentMaterialSlot ) );
- }
- } else {
- if ( lightMapEnabled ) textureWarning = true;
- }
- }
- if ( material.aoMap !== undefined ) {
- var aoMapEnabled = materialAOMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var aoMap = aoMapEnabled ? materialAOMap.getValue() : null;
- if ( material.aoMap !== aoMap ) {
- editor.execute( new SetMaterialMapCommand( currentObject, 'aoMap', aoMap, currentMaterialSlot ) );
- }
- if ( material.aoMapIntensity !== materialAOScale.getValue() ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'aoMapIntensity', materialAOScale.getValue(), currentMaterialSlot ) );
- }
- } else {
- if ( aoMapEnabled ) textureWarning = true;
- }
- }
- if ( material.emissiveMap !== undefined ) {
- var emissiveMapEnabled = materialEmissiveMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var emissiveMap = emissiveMapEnabled ? materialEmissiveMap.getValue() : null;
- if ( material.emissiveMap !== emissiveMap ) {
- editor.execute( new SetMaterialMapCommand( currentObject, 'emissiveMap', emissiveMap, currentMaterialSlot ) );
- }
- } else {
- if ( emissiveMapEnabled ) textureWarning = true;
- }
- }
- if ( material.side !== undefined ) {
- var side = parseInt( materialSide.getValue() );
- if ( material.side !== side ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'side', side, currentMaterialSlot ) );
- }
- }
- if ( material.flatShading !== undefined ) {
- var flatShading = materialShading.getValue();
- if ( material.flatShading != flatShading ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'flatShading', flatShading, currentMaterialSlot ) );
- }
- }
- if ( material.blending !== undefined ) {
- var blending = parseInt( materialBlending.getValue() );
- if ( material.blending !== blending ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'blending', blending, currentMaterialSlot ) );
- }
- }
- if ( material.opacity !== undefined && Math.abs( material.opacity - materialOpacity.getValue() ) >= 0.01 ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'opacity', materialOpacity.getValue(), currentMaterialSlot ) );
- }
- if ( material.transparent !== undefined && material.transparent !== materialTransparent.getValue() ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'transparent', materialTransparent.getValue(), currentMaterialSlot ) );
- }
- if ( material.alphaTest !== undefined && Math.abs( material.alphaTest - materialAlphaTest.getValue() ) >= 0.01 ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'alphaTest', materialAlphaTest.getValue(), currentMaterialSlot ) );
- }
- if ( material.wireframe !== undefined && material.wireframe !== materialWireframe.getValue() ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'wireframe', materialWireframe.getValue(), currentMaterialSlot) );
- }
- if ( material.wireframeLinewidth !== undefined && Math.abs( material.wireframeLinewidth - materialWireframeLinewidth.getValue() ) >= 0.01 ) {
- editor.execute( new SetMaterialValueCommand( currentObject, 'wireframeLinewidth', materialWireframeLinewidth.getValue(), currentMaterialSlot ) );
- }
- refreshUI();
- }
- if ( textureWarning ) {
- console.warn( "Can't set texture, model doesn't have texture coordinates" );
- }
- }
- //
- function setRowVisibility() {
- var properties = {
- 'name': materialNameRow,
- 'color': materialColorRow,
- 'roughness': materialRoughnessRow,
- 'metalness': materialMetalnessRow,
- 'emissive': materialEmissiveRow,
- 'specular': materialSpecularRow,
- 'shininess': materialShininessRow,
- 'clearCoat': materialClearCoatRow,
- 'clearCoatRoughness': materialClearCoatRoughnessRow,
- 'vertexShader': materialProgramRow,
- 'vertexColors': materialVertexColorsRow,
- 'skinning': materialSkinningRow,
- 'map': materialMapRow,
- 'alphaMap': materialAlphaMapRow,
- 'bumpMap': materialBumpMapRow,
- 'normalMap': materialNormalMapRow,
- 'displacementMap': materialDisplacementMapRow,
- 'roughnessMap': materialRoughnessMapRow,
- 'metalnessMap': materialMetalnessMapRow,
- 'specularMap': materialSpecularMapRow,
- 'envMap': materialEnvMapRow,
- 'lightMap': materialLightMapRow,
- 'aoMap': materialAOMapRow,
- 'emissiveMap': materialEmissiveMapRow,
- 'side': materialSideRow,
- 'flatShading': materialShadingRow,
- 'blending': materialBlendingRow,
- 'opacity': materialOpacityRow,
- 'transparent': materialTransparentRow,
- 'alphaTest': materialAlphaTestRow,
- 'wireframe': materialWireframeRow
- };
- var material = currentObject.material;
- if ( Array.isArray( material ) ) {
- materialSlotRow.setDisplay( '' );
- if ( material.length === 0 ) return;
- material = material[ currentMaterialSlot ];
- } else {
- materialSlotRow.setDisplay( 'none' );
- }
- for ( var property in properties ) {
- properties[ property ].setDisplay( material[ property ] !== undefined ? '' : 'none' );
- }
- }
- function refreshUI( resetTextureSelectors ) {
- if ( ! currentObject ) return;
- var material = currentObject.material;
- if ( Array.isArray( material ) ) {
- var slotOptions = {};
- currentMaterialSlot = Math.max( 0, Math.min( material.length, currentMaterialSlot ) );
- for ( var i = 0; i < material.length; i ++ ) {
- slotOptions[ i ] = String( i + 1 ) + ': ' + material[ i ].name;
- }
- materialSlotSelect.setOptions( slotOptions ).setValue( currentMaterialSlot );
- }
- material = editor.getObjectMaterial( currentObject, currentMaterialSlot );
- if ( material.uuid !== undefined ) {
- materialUUID.setValue( material.uuid );
- }
- if ( material.name !== undefined ) {
- materialName.setValue( material.name );
- }
- materialClass.setValue( material.type );
- if ( material.color !== undefined ) {
- materialColor.setHexValue( material.color.getHexString() );
- }
- if ( material.roughness !== undefined ) {
- materialRoughness.setValue( material.roughness );
- }
- if ( material.metalness !== undefined ) {
- materialMetalness.setValue( material.metalness );
- }
- if ( material.emissive !== undefined ) {
- materialEmissive.setHexValue( material.emissive.getHexString() );
- }
- if ( material.specular !== undefined ) {
- materialSpecular.setHexValue( material.specular.getHexString() );
- }
- if ( material.shininess !== undefined ) {
- materialShininess.setValue( material.shininess );
- }
- if ( material.clearCoat !== undefined ) {
- materialClearCoat.setValue( material.clearCoat );
- }
- if ( material.clearCoatRoughness !== undefined ) {
- materialClearCoatRoughness.setValue( material.clearCoatRoughness );
- }
- if ( material.vertexColors !== undefined ) {
- materialVertexColors.setValue( material.vertexColors );
- }
- if ( material.skinning !== undefined ) {
- materialSkinning.setValue( material.skinning );
- }
- if ( material.map !== undefined ) {
- materialMapEnabled.setValue( material.map !== null );
- if ( material.map !== null || resetTextureSelectors ) {
- materialMap.setValue( material.map );
- }
- }
- if ( material.alphaMap !== undefined ) {
- materialAlphaMapEnabled.setValue( material.alphaMap !== null );
- if ( material.alphaMap !== null || resetTextureSelectors ) {
- materialAlphaMap.setValue( material.alphaMap );
- }
- }
- if ( material.bumpMap !== undefined ) {
- materialBumpMapEnabled.setValue( material.bumpMap !== null );
- if ( material.bumpMap !== null || resetTextureSelectors ) {
- materialBumpMap.setValue( material.bumpMap );
- }
- materialBumpScale.setValue( material.bumpScale );
- }
- if ( material.normalMap !== undefined ) {
- materialNormalMapEnabled.setValue( material.normalMap !== null );
- if ( material.normalMap !== null || resetTextureSelectors ) {
- materialNormalMap.setValue( material.normalMap );
- }
- }
- if ( material.displacementMap !== undefined ) {
- materialDisplacementMapEnabled.setValue( material.displacementMap !== null );
- if ( material.displacementMap !== null || resetTextureSelectors ) {
- materialDisplacementMap.setValue( material.displacementMap );
- }
- materialDisplacementScale.setValue( material.displacementScale );
- }
- if ( material.roughnessMap !== undefined ) {
- materialRoughnessMapEnabled.setValue( material.roughnessMap !== null );
- if ( material.roughnessMap !== null || resetTextureSelectors ) {
- materialRoughnessMap.setValue( material.roughnessMap );
- }
- }
- if ( material.metalnessMap !== undefined ) {
- materialMetalnessMapEnabled.setValue( material.metalnessMap !== null );
- if ( material.metalnessMap !== null || resetTextureSelectors ) {
- materialMetalnessMap.setValue( material.metalnessMap );
- }
- }
- if ( material.specularMap !== undefined ) {
- materialSpecularMapEnabled.setValue( material.specularMap !== null );
- if ( material.specularMap !== null || resetTextureSelectors ) {
- materialSpecularMap.setValue( material.specularMap );
- }
- }
- if ( material.envMap !== undefined ) {
- materialEnvMapEnabled.setValue( material.envMap !== null );
- if ( material.envMap !== null || resetTextureSelectors ) {
- materialEnvMap.setValue( material.envMap );
- }
- }
- if ( material.reflectivity !== undefined ) {
- materialReflectivity.setValue( material.reflectivity );
- }
- if ( material.lightMap !== undefined ) {
- materialLightMapEnabled.setValue( material.lightMap !== null );
- if ( material.lightMap !== null || resetTextureSelectors ) {
- materialLightMap.setValue( material.lightMap );
- }
- }
- if ( material.aoMap !== undefined ) {
- materialAOMapEnabled.setValue( material.aoMap !== null );
- if ( material.aoMap !== null || resetTextureSelectors ) {
- materialAOMap.setValue( material.aoMap );
- }
- materialAOScale.setValue( material.aoMapIntensity );
- }
- if ( material.emissiveMap !== undefined ) {
- materialEmissiveMapEnabled.setValue( material.emissiveMap !== null );
- if ( material.emissiveMap !== null || resetTextureSelectors ) {
- materialEmissiveMap.setValue( material.emissiveMap );
- }
- }
- if ( material.side !== undefined ) {
- materialSide.setValue( material.side );
- }
- if ( material.flatShading !== undefined ) {
- materialShading.setValue( material.flatShading );
- }
- if ( material.blending !== undefined ) {
- materialBlending.setValue( material.blending );
- }
- if ( material.opacity !== undefined ) {
- materialOpacity.setValue( material.opacity );
- }
- if ( material.transparent !== undefined ) {
- materialTransparent.setValue( material.transparent );
- }
- if ( material.alphaTest !== undefined ) {
- materialAlphaTest.setValue( material.alphaTest );
- }
- if ( material.wireframe !== undefined ) {
- materialWireframe.setValue( material.wireframe );
- }
- if ( material.wireframeLinewidth !== undefined ) {
- materialWireframeLinewidth.setValue( material.wireframeLinewidth );
- }
- setRowVisibility();
- }
- // events
- signals.objectSelected.add( function ( object ) {
- var hasMaterial = false;
- if ( object && object.material ) {
- hasMaterial = true;
- if ( Array.isArray( object.material ) && object.material.length === 0 ) {
- hasMaterial = false;
- }
- }
- if ( hasMaterial ) {
- var objectChanged = object !== currentObject;
- currentObject = object;
- refreshUI( objectChanged );
- container.setDisplay( '' );
- } else {
- currentObject = null;
- container.setDisplay( 'none' );
- }
- } );
- signals.materialChanged.add( function () {
- refreshUI();
- } );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Material', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Object = function ( editor ) {
- var signals = editor.signals;
- var container = new UI.Panel();
- container.setBorderTop( '0' );
- container.setPaddingTop( '20px' );
- container.setDisplay( 'none' );
- // Actions
- var objectActions = new UI.Select().setPosition( 'absolute' ).setRight( '8px' ).setFontSize( '11px' );
- objectActions.setOptions( {
- 'Actions': 'Actions',
- 'Reset Position': 'Reset Position',
- 'Reset Rotation': 'Reset Rotation',
- 'Reset Scale': 'Reset Scale'
- } );
- objectActions.onClick( function ( event ) {
- event.stopPropagation(); // Avoid panel collapsing
- } );
- objectActions.onChange( function ( event ) {
- var object = editor.selected;
- switch ( this.getValue() ) {
- case 'Reset Position':
- editor.execute( new SetPositionCommand( object, new THREE.Vector3( 0, 0, 0 ) ) );
- break;
- case 'Reset Rotation':
- editor.execute( new SetRotationCommand( object, new THREE.Euler( 0, 0, 0 ) ) );
- break;
- case 'Reset Scale':
- editor.execute( new SetScaleCommand( object, new THREE.Vector3( 1, 1, 1 ) ) );
- break;
- }
- this.setValue( 'Actions' );
- } );
- // container.addStatic( objectActions );
- // type
- var objectTypeRow = new UI.Row();
- var objectType = new UI.Text();
- objectTypeRow.add( new UI.Text( 'Type' ).setWidth( '90px' ) );
- objectTypeRow.add( objectType );
- container.add( objectTypeRow );
- // uuid
- var objectUUIDRow = new UI.Row();
- var objectUUID = new UI.Input().setWidth( '102px' ).setFontSize( '12px' ).setDisabled( true );
- var objectUUIDRenew = new UI.Button( 'New' ).setMarginLeft( '7px' ).onClick( function () {
- objectUUID.setValue( THREE.Math.generateUUID() );
- editor.execute( new SetUuidCommand( editor.selected, objectUUID.getValue() ) );
- } );
- objectUUIDRow.add( new UI.Text( 'UUID' ).setWidth( '90px' ) );
- objectUUIDRow.add( objectUUID );
- objectUUIDRow.add( objectUUIDRenew );
- container.add( objectUUIDRow );
- // name
- var objectNameRow = new UI.Row();
- var objectName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
- editor.execute( new SetValueCommand( editor.selected, 'name', objectName.getValue() ) );
- } );
- objectNameRow.add( new UI.Text( 'Name' ).setWidth( '90px' ) );
- objectNameRow.add( objectName );
- container.add( objectNameRow );
- // position
- var objectPositionRow = new UI.Row();
- var objectPositionX = new UI.Number().setWidth( '50px' ).onChange( update );
- var objectPositionY = new UI.Number().setWidth( '50px' ).onChange( update );
- var objectPositionZ = new UI.Number().setWidth( '50px' ).onChange( update );
- objectPositionRow.add( new UI.Text( 'Position' ).setWidth( '90px' ) );
- objectPositionRow.add( objectPositionX, objectPositionY, objectPositionZ );
- container.add( objectPositionRow );
- // rotation
- var objectRotationRow = new UI.Row();
- var objectRotationX = new UI.Number().setStep( 10 ).setUnit( '°' ).setWidth( '50px' ).onChange( update );
- var objectRotationY = new UI.Number().setStep( 10 ).setUnit( '°' ).setWidth( '50px' ).onChange( update );
- var objectRotationZ = new UI.Number().setStep( 10 ).setUnit( '°' ).setWidth( '50px' ).onChange( update );
- objectRotationRow.add( new UI.Text( 'Rotation' ).setWidth( '90px' ) );
- objectRotationRow.add( objectRotationX, objectRotationY, objectRotationZ );
- container.add( objectRotationRow );
- // scale
- var objectScaleRow = new UI.Row();
- var objectScaleLock = new UI.Checkbox( true ).setPosition( 'absolute' ).setLeft( '75px' );
- var objectScaleX = new UI.Number( 1 ).setRange( 0.01, Infinity ).setWidth( '50px' ).onChange( updateScaleX );
- var objectScaleY = new UI.Number( 1 ).setRange( 0.01, Infinity ).setWidth( '50px' ).onChange( updateScaleY );
- var objectScaleZ = new UI.Number( 1 ).setRange( 0.01, Infinity ).setWidth( '50px' ).onChange( updateScaleZ );
- objectScaleRow.add( new UI.Text( 'Scale' ).setWidth( '90px' ) );
- objectScaleRow.add( objectScaleLock );
- objectScaleRow.add( objectScaleX, objectScaleY, objectScaleZ );
- container.add( objectScaleRow );
- // fov
- var objectFovRow = new UI.Row();
- var objectFov = new UI.Number().onChange( update );
- objectFovRow.add( new UI.Text( 'Fov' ).setWidth( '90px' ) );
- objectFovRow.add( objectFov );
- container.add( objectFovRow );
- // near
- var objectNearRow = new UI.Row();
- var objectNear = new UI.Number().onChange( update );
- objectNearRow.add( new UI.Text( 'Near' ).setWidth( '90px' ) );
- objectNearRow.add( objectNear );
- container.add( objectNearRow );
- // far
- var objectFarRow = new UI.Row();
- var objectFar = new UI.Number().onChange( update );
- objectFarRow.add( new UI.Text( 'Far' ).setWidth( '90px' ) );
- objectFarRow.add( objectFar );
- container.add( objectFarRow );
- // intensity
- var objectIntensityRow = new UI.Row();
- var objectIntensity = new UI.Number().setRange( 0, Infinity ).onChange( update );
- objectIntensityRow.add( new UI.Text( 'Intensity' ).setWidth( '90px' ) );
- objectIntensityRow.add( objectIntensity );
- container.add( objectIntensityRow );
- // color
- var objectColorRow = new UI.Row();
- var objectColor = new UI.Color().onChange( update );
- objectColorRow.add( new UI.Text( 'Color' ).setWidth( '90px' ) );
- objectColorRow.add( objectColor );
- container.add( objectColorRow );
- // ground color
- var objectGroundColorRow = new UI.Row();
- var objectGroundColor = new UI.Color().onChange( update );
- objectGroundColorRow.add( new UI.Text( 'Ground color' ).setWidth( '90px' ) );
- objectGroundColorRow.add( objectGroundColor );
- container.add( objectGroundColorRow );
- // distance
- var objectDistanceRow = new UI.Row();
- var objectDistance = new UI.Number().setRange( 0, Infinity ).onChange( update );
- objectDistanceRow.add( new UI.Text( 'Distance' ).setWidth( '90px' ) );
- objectDistanceRow.add( objectDistance );
- container.add( objectDistanceRow );
- // angle
- var objectAngleRow = new UI.Row();
- var objectAngle = new UI.Number().setPrecision( 3 ).setRange( 0, Math.PI / 2 ).onChange( update );
- objectAngleRow.add( new UI.Text( 'Angle' ).setWidth( '90px' ) );
- objectAngleRow.add( objectAngle );
- container.add( objectAngleRow );
- // penumbra
- var objectPenumbraRow = new UI.Row();
- var objectPenumbra = new UI.Number().setRange( 0, 1 ).onChange( update );
- objectPenumbraRow.add( new UI.Text( 'Penumbra' ).setWidth( '90px' ) );
- objectPenumbraRow.add( objectPenumbra );
- container.add( objectPenumbraRow );
- // decay
- var objectDecayRow = new UI.Row();
- var objectDecay = new UI.Number().setRange( 0, Infinity ).onChange( update );
- objectDecayRow.add( new UI.Text( 'Decay' ).setWidth( '90px' ) );
- objectDecayRow.add( objectDecay );
- container.add( objectDecayRow );
- // shadow
- var objectShadowRow = new UI.Row();
- objectShadowRow.add( new UI.Text( 'Shadow' ).setWidth( '90px' ) );
- var objectCastShadow = new UI.THREE.Boolean( false, 'cast' ).onChange( update );
- objectShadowRow.add( objectCastShadow );
- var objectReceiveShadow = new UI.THREE.Boolean( false, 'receive' ).onChange( update );
- objectShadowRow.add( objectReceiveShadow );
- var objectShadowRadius = new UI.Number( 1 ).onChange( update );
- objectShadowRow.add( objectShadowRadius );
- container.add( objectShadowRow );
- // visible
- var objectVisibleRow = new UI.Row();
- var objectVisible = new UI.Checkbox().onChange( update );
- objectVisibleRow.add( new UI.Text( 'Visible' ).setWidth( '90px' ) );
- objectVisibleRow.add( objectVisible );
- container.add( objectVisibleRow );
- // user data
- var timeout;
- var objectUserDataRow = new UI.Row();
- var objectUserData = new UI.TextArea().setWidth( '150px' ).setHeight( '40px' ).setFontSize( '12px' ).onChange( update );
- objectUserData.onKeyUp( function () {
- try {
- JSON.parse( objectUserData.getValue() );
- objectUserData.dom.classList.add( 'success' );
- objectUserData.dom.classList.remove( 'fail' );
- } catch ( error ) {
- objectUserData.dom.classList.remove( 'success' );
- objectUserData.dom.classList.add( 'fail' );
- }
- } );
- objectUserDataRow.add( new UI.Text( 'User data' ).setWidth( '90px' ) );
- objectUserDataRow.add( objectUserData );
- container.add( objectUserDataRow );
- //
- function updateScaleX() {
- var object = editor.selected;
- if ( objectScaleLock.getValue() === true ) {
- var scale = objectScaleX.getValue() / object.scale.x;
- objectScaleY.setValue( objectScaleY.getValue() * scale );
- objectScaleZ.setValue( objectScaleZ.getValue() * scale );
- }
- update();
- }
- function updateScaleY() {
- var object = editor.selected;
- if ( objectScaleLock.getValue() === true ) {
- var scale = objectScaleY.getValue() / object.scale.y;
- objectScaleX.setValue( objectScaleX.getValue() * scale );
- objectScaleZ.setValue( objectScaleZ.getValue() * scale );
- }
- update();
- }
- function updateScaleZ() {
- var object = editor.selected;
- if ( objectScaleLock.getValue() === true ) {
- var scale = objectScaleZ.getValue() / object.scale.z;
- objectScaleX.setValue( objectScaleX.getValue() * scale );
- objectScaleY.setValue( objectScaleY.getValue() * scale );
- }
- update();
- }
- function update() {
- var object = editor.selected;
- if ( object !== null ) {
- var newPosition = new THREE.Vector3( objectPositionX.getValue(), objectPositionY.getValue(), objectPositionZ.getValue() );
- if ( object.position.distanceTo( newPosition ) >= 0.01 ) {
- editor.execute( new SetPositionCommand( object, newPosition ) );
- }
- var newRotation = new THREE.Euler( objectRotationX.getValue() * THREE.Math.DEG2RAD, objectRotationY.getValue() * THREE.Math.DEG2RAD, objectRotationZ.getValue() * THREE.Math.DEG2RAD );
- if ( object.rotation.toVector3().distanceTo( newRotation.toVector3() ) >= 0.01 ) {
- editor.execute( new SetRotationCommand( object, newRotation ) );
- }
- var newScale = new THREE.Vector3( objectScaleX.getValue(), objectScaleY.getValue(), objectScaleZ.getValue() );
- if ( object.scale.distanceTo( newScale ) >= 0.01 ) {
- editor.execute( new SetScaleCommand( object, newScale ) );
- }
- if ( object.fov !== undefined && Math.abs( object.fov - objectFov.getValue() ) >= 0.01 ) {
- editor.execute( new SetValueCommand( object, 'fov', objectFov.getValue() ) );
- object.updateProjectionMatrix();
- }
- if ( object.near !== undefined && Math.abs( object.near - objectNear.getValue() ) >= 0.01 ) {
- editor.execute( new SetValueCommand( object, 'near', objectNear.getValue() ) );
- }
- if ( object.far !== undefined && Math.abs( object.far - objectFar.getValue() ) >= 0.01 ) {
- editor.execute( new SetValueCommand( object, 'far', objectFar.getValue() ) );
- }
- if ( object.intensity !== undefined && Math.abs( object.intensity - objectIntensity.getValue() ) >= 0.01 ) {
- editor.execute( new SetValueCommand( object, 'intensity', objectIntensity.getValue() ) );
- }
- if ( object.color !== undefined && object.color.getHex() !== objectColor.getHexValue() ) {
- editor.execute( new SetColorCommand( object, 'color', objectColor.getHexValue() ) );
- }
- if ( object.groundColor !== undefined && object.groundColor.getHex() !== objectGroundColor.getHexValue() ) {
- editor.execute( new SetColorCommand( object, 'groundColor', objectGroundColor.getHexValue() ) );
- }
- if ( object.distance !== undefined && Math.abs( object.distance - objectDistance.getValue() ) >= 0.01 ) {
- editor.execute( new SetValueCommand( object, 'distance', objectDistance.getValue() ) );
- }
- if ( object.angle !== undefined && Math.abs( object.angle - objectAngle.getValue() ) >= 0.01 ) {
- editor.execute( new SetValueCommand( object, 'angle', objectAngle.getValue() ) );
- }
- if ( object.penumbra !== undefined && Math.abs( object.penumbra - objectPenumbra.getValue() ) >= 0.01 ) {
- editor.execute( new SetValueCommand( object, 'penumbra', objectPenumbra.getValue() ) );
- }
- if ( object.decay !== undefined && Math.abs( object.decay - objectDecay.getValue() ) >= 0.01 ) {
- editor.execute( new SetValueCommand( object, 'decay', objectDecay.getValue() ) );
- }
- if ( object.visible !== objectVisible.getValue() ) {
- editor.execute( new SetValueCommand( object, 'visible', objectVisible.getValue() ) );
- }
- if ( object.castShadow !== undefined && object.castShadow !== objectCastShadow.getValue() ) {
- editor.execute( new SetValueCommand( object, 'castShadow', objectCastShadow.getValue() ) );
- }
- if ( object.receiveShadow !== undefined && object.receiveShadow !== objectReceiveShadow.getValue() ) {
- editor.execute( new SetValueCommand( object, 'receiveShadow', objectReceiveShadow.getValue() ) );
- object.material.needsUpdate = true;
- }
- if ( object.shadow !== undefined ) {
- if ( object.shadow.radius !== objectShadowRadius.getValue() ) {
- editor.execute( new SetValueCommand( object.shadow, 'radius', objectShadowRadius.getValue() ) );
- }
- }
- try {
- var userData = JSON.parse( objectUserData.getValue() );
- if ( JSON.stringify( object.userData ) != JSON.stringify( userData ) ) {
- editor.execute( new SetValueCommand( object, 'userData', userData ) );
- }
- } catch ( exception ) {
- console.warn( exception );
- }
- }
- }
- function updateRows( object ) {
- var properties = {
- 'fov': objectFovRow,
- 'near': objectNearRow,
- 'far': objectFarRow,
- 'intensity': objectIntensityRow,
- 'color': objectColorRow,
- 'groundColor': objectGroundColorRow,
- 'distance' : objectDistanceRow,
- 'angle' : objectAngleRow,
- 'penumbra' : objectPenumbraRow,
- 'decay' : objectDecayRow,
- 'castShadow' : objectShadowRow,
- 'receiveShadow' : objectReceiveShadow,
- 'shadow': objectShadowRadius
- };
- for ( var property in properties ) {
- properties[ property ].setDisplay( object[ property ] !== undefined ? '' : 'none' );
- }
- }
- function updateTransformRows( object ) {
- if ( object instanceof THREE.Light ||
- ( object instanceof THREE.Object3D && object.userData.targetInverse ) ) {
- objectRotationRow.setDisplay( 'none' );
- objectScaleRow.setDisplay( 'none' );
- } else {
- objectRotationRow.setDisplay( '' );
- objectScaleRow.setDisplay( '' );
- }
- }
- // events
- signals.objectSelected.add( function ( object ) {
- if ( object !== null ) {
- container.setDisplay( 'block' );
- updateRows( object );
- updateUI( object );
- } else {
- container.setDisplay( 'none' );
- }
- } );
- signals.objectChanged.add( function ( object ) {
- if ( object !== editor.selected ) return;
- updateUI( object );
- } );
- signals.refreshSidebarObject3D.add( function ( object ) {
- if ( object !== editor.selected ) return;
- updateUI( object );
- } );
- function updateUI( object ) {
- objectType.setValue( object.type );
- objectUUID.setValue( object.uuid );
- objectName.setValue( object.name );
- objectPositionX.setValue( object.position.x );
- objectPositionY.setValue( object.position.y );
- objectPositionZ.setValue( object.position.z );
- objectRotationX.setValue( object.rotation.x * THREE.Math.RAD2DEG );
- objectRotationY.setValue( object.rotation.y * THREE.Math.RAD2DEG );
- objectRotationZ.setValue( object.rotation.z * THREE.Math.RAD2DEG );
- objectScaleX.setValue( object.scale.x );
- objectScaleY.setValue( object.scale.y );
- objectScaleZ.setValue( object.scale.z );
- if ( object.fov !== undefined ) {
- objectFov.setValue( object.fov );
- }
- if ( object.near !== undefined ) {
- objectNear.setValue( object.near );
- }
- if ( object.far !== undefined ) {
- objectFar.setValue( object.far );
- }
- if ( object.intensity !== undefined ) {
- objectIntensity.setValue( object.intensity );
- }
- if ( object.color !== undefined ) {
- objectColor.setHexValue( object.color.getHexString() );
- }
- if ( object.groundColor !== undefined ) {
- objectGroundColor.setHexValue( object.groundColor.getHexString() );
- }
- if ( object.distance !== undefined ) {
- objectDistance.setValue( object.distance );
- }
- if ( object.angle !== undefined ) {
- objectAngle.setValue( object.angle );
- }
- if ( object.penumbra !== undefined ) {
- objectPenumbra.setValue( object.penumbra );
- }
- if ( object.decay !== undefined ) {
- objectDecay.setValue( object.decay );
- }
- if ( object.castShadow !== undefined ) {
- objectCastShadow.setValue( object.castShadow );
- }
- if ( object.receiveShadow !== undefined ) {
- objectReceiveShadow.setValue( object.receiveShadow );
- }
- if ( object.shadow !== undefined ) {
- objectShadowRadius.setValue( object.shadow.radius );
- }
- objectVisible.setValue( object.visible );
- try {
- objectUserData.setValue( JSON.stringify( object.userData, null, ' ' ) );
- } catch ( error ) {
- console.log( error );
- }
- objectUserData.setBorderColor( 'transparent' );
- objectUserData.setBackgroundColor( '' );
- updateTransformRows( object );
- }
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Object', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Project = function ( editor ) {
- var config = editor.config;
- var signals = editor.signals;
- var rendererTypes = {
- 'WebGLRenderer': THREE.WebGLRenderer,
- 'CanvasRenderer': THREE.CanvasRenderer,
- 'SVGRenderer': THREE.SVGRenderer,
- 'SoftwareRenderer': THREE.SoftwareRenderer,
- 'RaytracingRenderer': THREE.RaytracingRenderer
- };
- var container = new UI.Panel();
- container.setBorderTop( '0' );
- container.setPaddingTop( '20px' );
- // class
- var options = {};
- for ( var key in rendererTypes ) {
- if ( key.indexOf( 'WebGL' ) >= 0 && System.support.webgl === false ) continue;
- options[ key ] = key;
- }
- var rendererTypeRow = new UI.Row();
- var rendererType = new UI.Select().setOptions( options ).setWidth( '150px' ).onChange( function () {
- var value = this.getValue();
- config.setKey( 'project/renderer', value );
- updateRenderer();
- } );
- rendererTypeRow.add( new UI.Text( 'Renderer' ).setWidth( '90px' ) );
- rendererTypeRow.add( rendererType );
- container.add( rendererTypeRow );
- if ( config.getKey( 'project/renderer' ) !== undefined ) {
- rendererType.setValue( config.getKey( 'project/renderer' ) );
- }
- // antialiasing
- var rendererPropertiesRow = new UI.Row().setMarginLeft( '90px' );
- var rendererAntialias = new UI.THREE.Boolean( config.getKey( 'project/renderer/antialias' ), 'antialias' ).onChange( function () {
- config.setKey( 'project/renderer/antialias', this.getValue() );
- updateRenderer();
- } );
- rendererPropertiesRow.add( rendererAntialias );
- // shadow
- var rendererShadows = new UI.THREE.Boolean( config.getKey( 'project/renderer/shadows' ), 'shadows' ).onChange( function () {
- config.setKey( 'project/renderer/shadows', this.getValue() );
- updateRenderer();
- } );
- rendererPropertiesRow.add( rendererShadows );
- rendererPropertiesRow.add( new UI.Break() );
- // gamma input
- var rendererGammaInput = new UI.THREE.Boolean( config.getKey( 'project/renderer/gammaInput' ), 'γ input' ).onChange( function () {
- config.setKey( 'project/renderer/gammaInput', this.getValue() );
- updateRenderer();
- } );
- rendererPropertiesRow.add( rendererGammaInput );
- // gamma output
- var rendererGammaOutput = new UI.THREE.Boolean( config.getKey( 'project/renderer/gammaOutput' ), 'γ output' ).onChange( function () {
- config.setKey( 'project/renderer/gammaOutput', this.getValue() );
- updateRenderer();
- } );
- rendererPropertiesRow.add( rendererGammaOutput );
- container.add( rendererPropertiesRow );
- // Editable
- var editableRow = new UI.Row();
- var editable = new UI.Checkbox( config.getKey( 'project/editable' ) ).setLeft( '100px' ).onChange( function () {
- config.setKey( 'project/editable', this.getValue() );
- } );
- editableRow.add( new UI.Text( 'Editable' ).setWidth( '90px' ) );
- editableRow.add( editable );
- container.add( editableRow );
- // VR
- var vrRow = new UI.Row();
- var vr = new UI.Checkbox( config.getKey( 'project/vr' ) ).setLeft( '100px' ).onChange( function () {
- config.setKey( 'project/vr', this.getValue() );
- } );
- vrRow.add( new UI.Text( 'VR' ).setWidth( '90px' ) );
- vrRow.add( vr );
- container.add( vrRow );
- //
- function updateRenderer() {
- createRenderer( rendererType.getValue(), rendererAntialias.getValue(), rendererShadows.getValue(), rendererGammaInput.getValue(), rendererGammaOutput.getValue() );
- }
- function createRenderer( type, antialias, shadows, gammaIn, gammaOut ) {
- if ( type === 'WebGLRenderer' && System.support.webgl === false ) {
- type = 'CanvasRenderer';
- }
- rendererPropertiesRow.setDisplay( type === 'WebGLRenderer' ? '' : 'none' );
- var renderer = new rendererTypes[ type ]( { antialias: antialias} );
- renderer.gammaInput = gammaIn;
- renderer.gammaOutput = gammaOut;
- if ( shadows && renderer.shadowMap ) {
- renderer.shadowMap.enabled = true;
- // renderer.shadowMap.type = THREE.PCFSoftShadowMap;
- }
- signals.rendererChanged.dispatch( renderer );
- }
- createRenderer( config.getKey( 'project/renderer' ), config.getKey( 'project/renderer/antialias' ), config.getKey( 'project/renderer/shadows' ), config.getKey( 'project/renderer/gammaInput' ), config.getKey( 'project/renderer/gammaOutput' ) );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Project', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Properties = function ( editor ) {
- var signals = editor.signals;
- var container = new UI.Span();
- var objectTab = new UI.Text( 'OBJECT' ).onClick( onClick );
- var geometryTab = new UI.Text( 'GEOMETRY' ).onClick( onClick );
- var materialTab = new UI.Text( 'MATERIAL' ).onClick( onClick );
- var tabs = new UI.Div();
- tabs.setId( 'tabs' );
- tabs.add( objectTab, geometryTab, materialTab );
- container.add( tabs );
- function onClick( event ) {
- select( event.target.textContent );
- }
- //
- var object = new UI.Span().add(
- new Sidebar.Object( editor )
- );
- container.add( object );
- var geometry = new UI.Span().add(
- new Sidebar.Geometry( editor )
- );
- container.add( geometry );
- var material = new UI.Span().add(
- new Sidebar.Material( editor )
- );
- container.add( material );
- //
- function select( section ) {
- objectTab.setClass( '' );
- geometryTab.setClass( '' );
- materialTab.setClass( '' );
- object.setDisplay( 'none' );
- geometry.setDisplay( 'none' );
- material.setDisplay( 'none' );
- switch ( section ) {
- case 'OBJECT':
- objectTab.setClass( 'selected' );
- object.setDisplay( '' );
- break;
- case 'GEOMETRY':
- geometryTab.setClass( 'selected' );
- geometry.setDisplay( '' );
- break;
- case 'MATERIAL':
- materialTab.setClass( 'selected' );
- material.setDisplay( '' );
- break;
- }
- }
- select( 'OBJECT' );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Properties', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Scene = function ( editor ) {
- var signals = editor.signals;
- var container = new UI.Panel();
- container.setBorderTop( '0' );
- container.setPaddingTop( '20px' );
- // outliner
- function buildOption( object, draggable ) {
- var option = document.createElement( 'div' );
- option.draggable = draggable;
- option.innerHTML = buildHTML( object );
- option.value = object.id;
- return option;
- }
- function getMaterialName( material ) {
- if ( Array.isArray( material ) ) {
- var array = [];
- for ( var i = 0; i < material.length; i ++ ) {
- array.push( material[ i ].name );
- }
- return array.join( ',' );
- }
- return material.name;
- }
- function buildHTML( object ) {
- var html = '<span class="type ' + object.type + '"></span> ' + object.name;
- if ( object instanceof THREE.Mesh ) {
- var geometry = object.geometry;
- var material = object.material;
- html += ' <span class="type ' + geometry.type + '"></span> ' + geometry.name;
- html += ' <span class="type ' + material.type + '"></span> ' + getMaterialName( material );
- }
- html += getScript( object.uuid );
- return html;
- }
- function getScript( uuid ) {
- if ( editor.scripts[ uuid ] !== undefined ) {
- return ' <span class="type Script"></span>';
- }
- return '';
- }
- var ignoreObjectSelectedSignal = false;
- var outliner = new UI.Outliner( editor );
- outliner.setId( 'outliner' );
- outliner.onChange( function () {
- ignoreObjectSelectedSignal = true;
- editor.selectById( parseInt( outliner.getValue() ) );
- ignoreObjectSelectedSignal = false;
- } );
- outliner.onDblClick( function () {
- editor.focusById( parseInt( outliner.getValue() ) );
- } );
- container.add( outliner );
- container.add( new UI.Break() );
- // background
- function onBackgroundChanged() {
- signals.sceneBackgroundChanged.dispatch( backgroundColor.getHexValue() );
- }
- var backgroundRow = new UI.Row();
- var backgroundColor = new UI.Color().setValue( '#aaaaaa' ).onChange( onBackgroundChanged );
- backgroundRow.add( new UI.Text( 'Background' ).setWidth( '90px' ) );
- backgroundRow.add( backgroundColor );
- container.add( backgroundRow );
- // fog
- function onFogChanged() {
- signals.sceneFogChanged.dispatch(
- fogType.getValue(),
- fogColor.getHexValue(),
- fogNear.getValue(),
- fogFar.getValue(),
- fogDensity.getValue()
- );
- }
- var fogTypeRow = new UI.Row();
- var fogType = new UI.Select().setOptions( {
- 'None': 'None',
- 'Fog': 'Linear',
- 'FogExp2': 'Exponential'
- } ).setWidth( '150px' );
- fogType.onChange( function () {
- onFogChanged();
- refreshFogUI();
- } );
- fogTypeRow.add( new UI.Text( 'Fog' ).setWidth( '90px' ) );
- fogTypeRow.add( fogType );
- container.add( fogTypeRow );
- // fog color
- var fogPropertiesRow = new UI.Row();
- fogPropertiesRow.setDisplay( 'none' );
- fogPropertiesRow.setMarginLeft( '90px' );
- container.add( fogPropertiesRow );
- var fogColor = new UI.Color().setValue( '#aaaaaa' );
- fogColor.onChange( onFogChanged );
- fogPropertiesRow.add( fogColor );
- // fog near
- var fogNear = new UI.Number( 0.1 ).setWidth( '40px' ).setRange( 0, Infinity ).onChange( onFogChanged );
- fogPropertiesRow.add( fogNear );
- // fog far
- var fogFar = new UI.Number( 50 ).setWidth( '40px' ).setRange( 0, Infinity ).onChange( onFogChanged );
- fogPropertiesRow.add( fogFar );
- // fog density
- var fogDensity = new UI.Number( 0.05 ).setWidth( '40px' ).setRange( 0, 0.1 ).setPrecision( 3 ).onChange( onFogChanged );
- fogPropertiesRow.add( fogDensity );
- //
- function refreshUI() {
- var camera = editor.camera;
- var scene = editor.scene;
- var options = [];
- options.push( buildOption( camera, false ) );
- options.push( buildOption( scene, false ) );
- ( function addObjects( objects, pad ) {
- for ( var i = 0, l = objects.length; i < l; i ++ ) {
- var object = objects[ i ];
- var option = buildOption( object, true );
- option.style.paddingLeft = ( pad * 10 ) + 'px';
- options.push( option );
- addObjects( object.children, pad + 1 );
- }
- } )( scene.children, 1 );
- outliner.setOptions( options );
- if ( editor.selected !== null ) {
- outliner.setValue( editor.selected.id );
- }
- if ( scene.background ) {
- backgroundColor.setHexValue( scene.background.getHex() );
- }
- if ( scene.fog ) {
- fogColor.setHexValue( scene.fog.color.getHex() );
- if ( scene.fog instanceof THREE.Fog ) {
- fogType.setValue( "Fog" );
- fogNear.setValue( scene.fog.near );
- fogFar.setValue( scene.fog.far );
- } else if ( scene.fog instanceof THREE.FogExp2 ) {
- fogType.setValue( "FogExp2" );
- fogDensity.setValue( scene.fog.density );
- }
- } else {
- fogType.setValue( "None" );
- }
- refreshFogUI();
- }
- function refreshFogUI() {
- var type = fogType.getValue();
- fogPropertiesRow.setDisplay( type === 'None' ? 'none' : '' );
- fogNear.setDisplay( type === 'Fog' ? '' : 'none' );
- fogFar.setDisplay( type === 'Fog' ? '' : 'none' );
- fogDensity.setDisplay( type === 'FogExp2' ? '' : 'none' );
- }
- refreshUI();
- // events
- signals.editorCleared.add( refreshUI );
- signals.sceneGraphChanged.add( refreshUI );
- signals.objectChanged.add( function ( object ) {
- var options = outliner.options;
- for ( var i = 0; i < options.length; i ++ ) {
- var option = options[ i ];
- if ( option.value === object.id ) {
- option.innerHTML = buildHTML( object );
- return;
- }
- }
- } );
- signals.objectSelected.add( function ( object ) {
- if ( ignoreObjectSelectedSignal === true ) return;
- outliner.setValue( object !== null ? object.id : null );
- } );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Scene', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Script = function ( editor ) {
- var signals = editor.signals;
- var container = new UI.Panel();
- container.setDisplay( 'none' );
- container.add( new UI.Text( 'Script' ).setTextTransform( 'uppercase' ) );
- container.add( new UI.Break() );
- container.add( new UI.Break() );
- //
- var scriptsContainer = new UI.Row();
- container.add( scriptsContainer );
- var newScript = new UI.Button( 'New' );
- newScript.onClick( function () {
- var script = { name: '', source: 'function update( event ) {}' };
- editor.execute( new AddScriptCommand( editor.selected, script ) );
- } );
- container.add( newScript );
- /*
- var loadScript = new UI.Button( 'Load' );
- loadScript.setMarginLeft( '4px' );
- container.add( loadScript );
- */
- //
- function update() {
- scriptsContainer.clear();
- scriptsContainer.setDisplay( 'none' );
- var object = editor.selected;
- if ( object === null ) {
- return;
- }
- var scripts = editor.scripts[ object.uuid ];
- if ( scripts !== undefined ) {
- scriptsContainer.setDisplay( 'block' );
- for ( var i = 0; i < scripts.length; i ++ ) {
- ( function ( object, script ) {
- var name = new UI.Input( script.name ).setWidth( '130px' ).setFontSize( '12px' );
- name.onChange( function () {
- editor.execute( new SetScriptValueCommand( editor.selected, script, 'name', this.getValue() ) );
- } );
- scriptsContainer.add( name );
- var edit = new UI.Button( 'Edit' );
- edit.setMarginLeft( '4px' );
- edit.onClick( function () {
- signals.editScript.dispatch( object, script );
- } );
- scriptsContainer.add( edit );
- var remove = new UI.Button( 'Remove' );
- remove.setMarginLeft( '4px' );
- remove.onClick( function () {
- if ( confirm( 'Are you sure?' ) ) {
- editor.execute( new RemoveScriptCommand( editor.selected, script ) );
- }
- } );
- scriptsContainer.add( remove );
- scriptsContainer.add( new UI.Break() );
- } )( object, scripts[ i ] );
- }
- }
- }
- // signals
- signals.objectSelected.add( function ( object ) {
- if ( object !== null && editor.camera !== object ) {
- container.setDisplay( 'block' );
- update();
- } else {
- container.setDisplay( 'none' );
- }
- } );
- signals.scriptAdded.add( update );
- signals.scriptRemoved.add( update );
- signals.scriptChanged.add( update );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Script', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Sidebar.Settings = function ( editor ) {
- var config = editor.config;
- var signals = editor.signals;
- var container = new UI.Panel();
- container.setBorderTop( '0' );
- container.setPaddingTop( '20px' );
- // class
- var options = {
- 'css/light.css': 'light',
- 'css/dark.css': 'dark'
- };
- var themeRow = new UI.Row();
- var theme = new UI.Select().setWidth( '150px' );
- theme.setOptions( options );
- if ( config.getKey( 'theme' ) !== undefined ) {
- theme.setValue( config.getKey( 'theme' ) );
- }
- theme.onChange( function () {
- var value = this.getValue();
- editor.setTheme( value );
- editor.config.setKey( 'theme', value );
- } );
- themeRow.add( new UI.Text( 'Theme' ).setWidth( '90px' ) );
- themeRow.add( theme );
- container.add( themeRow );
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Sidebar.Settings', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Storage', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Toolbar', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Viewport', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- Viewport.Info = function ( editor ) {
- var signals = editor.signals;
- var container = new UI.Panel();
- container.setId( 'info' );
- container.setPosition( 'absolute' );
- container.setLeft( '10px' );
- container.setBottom( '10px' );
- container.setFontSize( '12px' );
- container.setColor( '#fff' );
- var objectsText = new UI.Text( '0' ).setMarginLeft( '6px' );
- var verticesText = new UI.Text( '0' ).setMarginLeft( '6px' );
- var trianglesText = new UI.Text( '0' ).setMarginLeft( '6px' );
- container.add( new UI.Text( 'objects' ), objectsText, new UI.Break() );
- container.add( new UI.Text( 'vertices' ), verticesText, new UI.Break() );
- container.add( new UI.Text( 'triangles' ), trianglesText, new UI.Break() );
- signals.objectAdded.add( update );
- signals.objectRemoved.add( update );
- signals.geometryChanged.add( update );
- //
- function update() {
- var scene = editor.scene;
- var objects = 0, vertices = 0, triangles = 0;
- for ( var i = 0, l = scene.children.length; i < l; i ++ ) {
- var object = scene.children[ i ];
- object.traverseVisible( function ( object ) {
- objects ++;
- if ( object instanceof THREE.Mesh ) {
- var geometry = object.geometry;
- if ( geometry instanceof THREE.Geometry ) {
- vertices += geometry.vertices.length;
- triangles += geometry.faces.length;
- } else if ( geometry instanceof THREE.BufferGeometry ) {
- if ( geometry.index !== null ) {
- vertices += geometry.index.count * 3;
- triangles += geometry.index.count;
- } else {
- vertices += geometry.attributes.position.count;
- triangles += geometry.attributes.position.count / 3;
- }
- }
- }
- } );
- }
- objectsText.setValue( objects.format() );
- verticesText.setValue( vertices.format() );
- trianglesText.setValue( triangles.format() );
- }
- return container;
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module.todo( 'Viewport.Info', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @constructor
- */
- var AddObjectCommand$1 = function ( object ) {
- Command.call( this );
- this.type = 'AddObjectCommand';
- this.object = object;
- if ( object !== undefined ) {
- this.name = 'Add Object: ' + object.name;
- }
- };
- AddObjectCommand$1.prototype = {
- execute: function () {
- this.editor.addObject( this.object );
- this.editor.select( this.object );
- },
- undo: function () {
- this.editor.removeObject( this.object );
- this.editor.deselect();
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.object = this.object.toJSON();
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.object.object.uuid );
- if ( this.object === undefined ) {
- var loader = new THREE.ObjectLoader();
- this.object = loader.parse( json.object );
- }
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'AddObjectCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param script javascript object
- * @constructor
- */
- var AddScriptCommand$1 = function ( object, script ) {
- Command.call( this );
- this.type = 'AddScriptCommand';
- this.name = 'Add Script';
- this.object = object;
- this.script = script;
- };
- AddScriptCommand$1.prototype = {
- execute: function () {
- if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
- this.editor.scripts[ this.object.uuid ] = [];
- }
- this.editor.scripts[ this.object.uuid ].push( this.script );
- this.editor.signals.scriptAdded.dispatch( this.script );
- },
- undo: function () {
- if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
- var index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
- if ( index !== - 1 ) {
- this.editor.scripts[ this.object.uuid ].splice( index, 1 );
- }
- this.editor.signals.scriptRemoved.dispatch( this.script );
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.script = this.script;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.script = json.script;
- this.object = this.editor.objectByUuid( json.objectUuid );
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'AddScriptCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param newParent THREE.Object3D
- * @param newBefore THREE.Object3D
- * @constructor
- */
- var MoveObjectCommand = function ( object, newParent, newBefore ) {
- Command.call( this );
- this.type = 'MoveObjectCommand';
- this.name = 'Move Object';
- this.object = object;
- this.oldParent = ( object !== undefined ) ? object.parent : undefined;
- this.oldIndex = ( this.oldParent !== undefined ) ? this.oldParent.children.indexOf( this.object ) : undefined;
- this.newParent = newParent;
- if ( newBefore !== undefined ) {
- this.newIndex = ( newParent !== undefined ) ? newParent.children.indexOf( newBefore ) : undefined;
- } else {
- this.newIndex = ( newParent !== undefined ) ? newParent.children.length : undefined;
- }
- if ( this.oldParent === this.newParent && this.newIndex > this.oldIndex ) {
- this.newIndex --;
- }
- this.newBefore = newBefore;
- };
- MoveObjectCommand.prototype = {
- execute: function () {
- this.oldParent.remove( this.object );
- var children = this.newParent.children;
- children.splice( this.newIndex, 0, this.object );
- this.object.parent = this.newParent;
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- undo: function () {
- this.newParent.remove( this.object );
- var children = this.oldParent.children;
- children.splice( this.oldIndex, 0, this.object );
- this.object.parent = this.oldParent;
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.newParentUuid = this.newParent.uuid;
- output.oldParentUuid = this.oldParent.uuid;
- output.newIndex = this.newIndex;
- output.oldIndex = this.oldIndex;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.oldParent = this.editor.objectByUuid( json.oldParentUuid );
- if ( this.oldParent === undefined ) {
- this.oldParent = this.editor.scene;
- }
- this.newParent = this.editor.objectByUuid( json.newParentUuid );
- if ( this.newParent === undefined ) {
- this.newParent = this.editor.scene;
- }
- this.newIndex = json.newIndex;
- this.oldIndex = json.oldIndex;
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'MoveObjectCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param cmdArray array containing command objects
- * @constructor
- */
- var MultiCmdsCommand$1 = function ( cmdArray ) {
- Command.call( this );
- this.type = 'MultiCmdsCommand';
- this.name = 'Multiple Changes';
- this.cmdArray = ( cmdArray !== undefined ) ? cmdArray : [];
- };
- MultiCmdsCommand$1.prototype = {
- execute: function () {
- this.editor.signals.sceneGraphChanged.active = false;
- for ( var i = 0; i < this.cmdArray.length; i ++ ) {
- this.cmdArray[ i ].execute();
- }
- this.editor.signals.sceneGraphChanged.active = true;
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- undo: function () {
- this.editor.signals.sceneGraphChanged.active = false;
- for ( var i = this.cmdArray.length - 1; i >= 0; i -- ) {
- this.cmdArray[ i ].undo();
- }
- this.editor.signals.sceneGraphChanged.active = true;
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- var cmds = [];
- for ( var i = 0; i < this.cmdArray.length; i ++ ) {
- cmds.push( this.cmdArray[ i ].toJSON() );
- }
- output.cmds = cmds;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- var cmds = json.cmds;
- for ( var i = 0; i < cmds.length; i ++ ) {
- var cmd = new window[ cmds[ i ].type ](); // creates a new object of type "json.type"
- cmd.fromJSON( cmds[ i ] );
- this.cmdArray.push( cmd );
- }
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'MultiCmdsCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @constructor
- */
- var RemoveObjectCommand$1 = function ( object ) {
- Command.call( this );
- this.type = 'RemoveObjectCommand';
- this.name = 'Remove Object';
- this.object = object;
- this.parent = ( object !== undefined ) ? object.parent : undefined;
- if ( this.parent !== undefined ) {
- this.index = this.parent.children.indexOf( this.object );
- }
- };
- RemoveObjectCommand$1.prototype = {
- execute: function () {
- var scope = this.editor;
- this.object.traverse( function ( child ) {
- scope.removeHelper( child );
- } );
- this.parent.remove( this.object );
- this.editor.select( this.parent );
- this.editor.signals.objectRemoved.dispatch( this.object );
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- undo: function () {
- var scope = this.editor;
- this.object.traverse( function ( child ) {
- if ( child.geometry !== undefined ) scope.addGeometry( child.geometry );
- if ( child.material !== undefined ) scope.addMaterial( child.material );
- scope.addHelper( child );
- } );
- this.parent.children.splice( this.index, 0, this.object );
- this.object.parent = this.parent;
- this.editor.select( this.object );
- this.editor.signals.objectAdded.dispatch( this.object );
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.object = this.object.toJSON();
- output.index = this.index;
- output.parentUuid = this.parent.uuid;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.parent = this.editor.objectByUuid( json.parentUuid );
- if ( this.parent === undefined ) {
- this.parent = this.editor.scene;
- }
- this.index = json.index;
- this.object = this.editor.objectByUuid( json.object.object.uuid );
- if ( this.object === undefined ) {
- var loader = new THREE.ObjectLoader();
- this.object = loader.parse( json.object );
- }
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'RemoveObjectCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param script javascript object
- * @constructor
- */
- var RemoveScriptCommand$1 = function ( object, script ) {
- Command.call( this );
- this.type = 'RemoveScriptCommand';
- this.name = 'Remove Script';
- this.object = object;
- this.script = script;
- if ( this.object && this.script ) {
- this.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
- }
- };
- RemoveScriptCommand$1.prototype = {
- execute: function () {
- if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
- if ( this.index !== - 1 ) {
- this.editor.scripts[ this.object.uuid ].splice( this.index, 1 );
- }
- this.editor.signals.scriptRemoved.dispatch( this.script );
- },
- undo: function () {
- if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
- this.editor.scripts[ this.object.uuid ] = [];
- }
- this.editor.scripts[ this.object.uuid ].splice( this.index, 0, this.script );
- this.editor.signals.scriptAdded.dispatch( this.script );
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.script = this.script;
- output.index = this.index;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.script = json.script;
- this.index = json.index;
- this.object = this.editor.objectByUuid( json.objectUuid );
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'RemoveScriptCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param attributeName string
- * @param newValue integer representing a hex color value
- * @constructor
- */
- var SetColorCommand$1 = function ( object, attributeName, newValue ) {
- Command.call( this );
- this.type = 'SetColorCommand';
- this.name = 'Set ' + attributeName;
- this.updatable = true;
- this.object = object;
- this.attributeName = attributeName;
- this.oldValue = ( object !== undefined ) ? this.object[ this.attributeName ].getHex() : undefined;
- this.newValue = newValue;
- };
- SetColorCommand$1.prototype = {
- execute: function () {
- this.object[ this.attributeName ].setHex( this.newValue );
- this.editor.signals.objectChanged.dispatch( this.object );
- },
- undo: function () {
- this.object[ this.attributeName ].setHex( this.oldValue );
- this.editor.signals.objectChanged.dispatch( this.object );
- },
- update: function ( cmd ) {
- this.newValue = cmd.newValue;
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.attributeName = this.attributeName;
- output.oldValue = this.oldValue;
- output.newValue = this.newValue;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.attributeName = json.attributeName;
- this.oldValue = json.oldValue;
- this.newValue = json.newValue;
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetColorCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param newGeometry THREE.Geometry
- * @constructor
- */
- var SetGeometryCommand$1 = function ( object, newGeometry ) {
- Command.call( this );
- this.type = 'SetGeometryCommand';
- this.name = 'Set Geometry';
- this.updatable = true;
- this.object = object;
- this.oldGeometry = ( object !== undefined ) ? object.geometry : undefined;
- this.newGeometry = newGeometry;
- };
- SetGeometryCommand$1.prototype = {
- execute: function () {
- this.object.geometry.dispose();
- this.object.geometry = this.newGeometry;
- this.object.geometry.computeBoundingSphere();
- this.editor.signals.geometryChanged.dispatch( this.object );
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- undo: function () {
- this.object.geometry.dispose();
- this.object.geometry = this.oldGeometry;
- this.object.geometry.computeBoundingSphere();
- this.editor.signals.geometryChanged.dispatch( this.object );
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- update: function ( cmd ) {
- this.newGeometry = cmd.newGeometry;
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.oldGeometry = this.object.geometry.toJSON();
- output.newGeometry = this.newGeometry.toJSON();
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.oldGeometry = parseGeometry( json.oldGeometry );
- this.newGeometry = parseGeometry( json.newGeometry );
- function parseGeometry ( data ) {
- var loader = new THREE.ObjectLoader();
- return loader.parseGeometries( [ data ] )[ data.uuid ];
- }
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetGeometryCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param attributeName string
- * @param newValue number, string, boolean or object
- * @constructor
- */
- var SetGeometryValueCommand$1 = function ( object, attributeName, newValue ) {
- Command.call( this );
- this.type = 'SetGeometryValueCommand';
- this.name = 'Set Geometry.' + attributeName;
- this.object = object;
- this.attributeName = attributeName;
- this.oldValue = ( object !== undefined ) ? object.geometry[ attributeName ] : undefined;
- this.newValue = newValue;
- };
- SetGeometryValueCommand$1.prototype = {
- execute: function () {
- this.object.geometry[ this.attributeName ] = this.newValue;
- this.editor.signals.objectChanged.dispatch( this.object );
- this.editor.signals.geometryChanged.dispatch();
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- undo: function () {
- this.object.geometry[ this.attributeName ] = this.oldValue;
- this.editor.signals.objectChanged.dispatch( this.object );
- this.editor.signals.geometryChanged.dispatch();
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.attributeName = this.attributeName;
- output.oldValue = this.oldValue;
- output.newValue = this.newValue;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.attributeName = json.attributeName;
- this.oldValue = json.oldValue;
- this.newValue = json.newValue;
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetGeometryValueCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param attributeName string
- * @param newValue integer representing a hex color value
- * @constructor
- */
- var SetMaterialColorCommand$1 = function ( object, attributeName, newValue, materialSlot ) {
- Command.call( this );
- this.type = 'SetMaterialColorCommand';
- this.name = 'Set Material.' + attributeName;
- this.updatable = true;
- this.object = object;
- this.material = this.editor.getObjectMaterial( object, materialSlot );
- this.oldValue = ( this.material !== undefined ) ? this.material[ attributeName ].getHex() : undefined;
- this.newValue = newValue;
- this.attributeName = attributeName;
- };
- SetMaterialColorCommand$1.prototype = {
- execute: function () {
- this.material[ this.attributeName ].setHex( this.newValue );
- this.editor.signals.materialChanged.dispatch( this.material );
- },
- undo: function () {
- this.material[ this.attributeName ].setHex( this.oldValue );
- this.editor.signals.materialChanged.dispatch( this.material );
- },
- update: function ( cmd ) {
- this.newValue = cmd.newValue;
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.attributeName = this.attributeName;
- output.oldValue = this.oldValue;
- output.newValue = this.newValue;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.attributeName = json.attributeName;
- this.oldValue = json.oldValue;
- this.newValue = json.newValue;
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetMaterialColorCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param newMaterial THREE.Material
- * @constructor
- */
- var SetMaterialCommand$1 = function ( object, newMaterial, materialSlot ) {
- Command.call( this );
- this.type = 'SetMaterialCommand';
- this.name = 'New Material';
- this.object = object;
- this.materialSlot = materialSlot;
- this.oldMaterial = this.editor.getObjectMaterial( object, materialSlot );
- this.newMaterial = newMaterial;
- };
- SetMaterialCommand$1.prototype = {
- execute: function () {
- this.editor.setObjectMaterial( this.object, this.materialSlot, this.newMaterial );
- this.editor.signals.materialChanged.dispatch( this.newMaterial );
- },
- undo: function () {
- this.editor.setObjectMaterial( this.object, this.materialSlot, this.oldMaterial );
- this.editor.signals.materialChanged.dispatch( this.oldMaterial );
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.oldMaterial = this.oldMaterial.toJSON();
- output.newMaterial = this.newMaterial.toJSON();
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.oldMaterial = parseMaterial( json.oldMaterial );
- this.newMaterial = parseMaterial( json.newMaterial );
- function parseMaterial ( json ) {
- var loader = new THREE.ObjectLoader();
- var images = loader.parseImages( json.images );
- var textures = loader.parseTextures( json.textures, images );
- var materials = loader.parseMaterials( [ json ], textures );
- return materials[ json.uuid ];
- }
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetMaterialCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param mapName string
- * @param newMap THREE.Texture
- * @constructor
- */
- var SetMaterialMapCommand$1 = function ( object, mapName, newMap, materialSlot ) {
- Command.call( this );
- this.type = 'SetMaterialMapCommand';
- this.name = 'Set Material.' + mapName;
- this.object = object;
- this.material = this.editor.getObjectMaterial( object, materialSlot );
- this.oldMap = ( object !== undefined ) ? this.material[ mapName ] : undefined;
- this.newMap = newMap;
- this.mapName = mapName;
- };
- SetMaterialMapCommand$1.prototype = {
- execute: function () {
- this.material[ this.mapName ] = this.newMap;
- this.material.needsUpdate = true;
- this.editor.signals.materialChanged.dispatch( this.material );
- },
- undo: function () {
- this.material[ this.mapName ] = this.oldMap;
- this.material.needsUpdate = true;
- this.editor.signals.materialChanged.dispatch( this.material );
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.mapName = this.mapName;
- output.newMap = serializeMap( this.newMap );
- output.oldMap = serializeMap( this.oldMap );
- return output;
- // serializes a map (THREE.Texture)
- function serializeMap ( map ) {
- if ( map === null || map === undefined ) return null;
- var meta = {
- geometries: {},
- materials: {},
- textures: {},
- images: {}
- };
- var json = map.toJSON( meta );
- var images = extractFromCache( meta.images );
- if ( images.length > 0 ) json.images = images;
- json.sourceFile = map.sourceFile;
- return json;
- }
- // Note: The function 'extractFromCache' is copied from Object3D.toJSON()
- // extract data from the cache hash
- // remove metadata on each item
- // and return as array
- function extractFromCache ( cache ) {
- var values = [];
- for ( var key in cache ) {
- var data = cache[ key ];
- delete data.metadata;
- values.push( data );
- }
- return values;
- }
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.mapName = json.mapName;
- this.oldMap = parseTexture( json.oldMap );
- this.newMap = parseTexture( json.newMap );
- function parseTexture ( json ) {
- var map = null;
- if ( json !== null ) {
- var loader = new THREE.ObjectLoader();
- var images = loader.parseImages( json.images );
- var textures = loader.parseTextures( [ json ], images );
- map = textures[ json.uuid ];
- map.sourceFile = json.sourceFile;
- }
- return map;
- }
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetMaterialMapCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param attributeName string
- * @param newValue number, string, boolean or object
- * @constructor
- */
- var SetMaterialValueCommand$1 = function ( object, attributeName, newValue, materialSlot ) {
- Command.call( this );
- this.type = 'SetMaterialValueCommand';
- this.name = 'Set Material.' + attributeName;
- this.updatable = true;
- this.object = object;
- this.material = this.editor.getObjectMaterial( object, materialSlot );
- this.oldValue = ( this.material !== undefined ) ? this.material[ attributeName ] : undefined;
- this.newValue = newValue;
- this.attributeName = attributeName;
- };
- SetMaterialValueCommand$1.prototype = {
- execute: function () {
- this.material[ this.attributeName ] = this.newValue;
- this.material.needsUpdate = true;
- this.editor.signals.objectChanged.dispatch( this.object );
- this.editor.signals.materialChanged.dispatch( this.material );
- },
- undo: function () {
- this.material[ this.attributeName ] = this.oldValue;
- this.material.needsUpdate = true;
- this.editor.signals.objectChanged.dispatch( this.object );
- this.editor.signals.materialChanged.dispatch( this.material );
- },
- update: function ( cmd ) {
- this.newValue = cmd.newValue;
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.attributeName = this.attributeName;
- output.oldValue = this.oldValue;
- output.newValue = this.newValue;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.attributeName = json.attributeName;
- this.oldValue = json.oldValue;
- this.newValue = json.newValue;
- this.object = this.editor.objectByUuid( json.objectUuid );
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetMaterialValueCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param newPosition THREE.Vector3
- * @param optionalOldPosition THREE.Vector3
- * @constructor
- */
- var SetPositionCommand$1 = function ( object, newPosition, optionalOldPosition ) {
- Command.call( this );
- this.type = 'SetPositionCommand';
- this.name = 'Set Position';
- this.updatable = true;
- this.object = object;
- if ( object !== undefined && newPosition !== undefined ) {
- this.oldPosition = object.position.clone();
- this.newPosition = newPosition.clone();
- }
- if ( optionalOldPosition !== undefined ) {
- this.oldPosition = optionalOldPosition.clone();
- }
- };
- SetPositionCommand$1.prototype = {
- execute: function () {
- this.object.position.copy( this.newPosition );
- this.object.updateMatrixWorld( true );
- this.editor.signals.objectChanged.dispatch( this.object );
- },
- undo: function () {
- this.object.position.copy( this.oldPosition );
- this.object.updateMatrixWorld( true );
- this.editor.signals.objectChanged.dispatch( this.object );
- },
- update: function ( command ) {
- this.newPosition.copy( command.newPosition );
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.oldPosition = this.oldPosition.toArray();
- output.newPosition = this.newPosition.toArray();
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.oldPosition = new THREE.Vector3().fromArray( json.oldPosition );
- this.newPosition = new THREE.Vector3().fromArray( json.newPosition );
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetPositionCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param newRotation THREE.Euler
- * @param optionalOldRotation THREE.Euler
- * @constructor
- */
- var SetRotationCommand$1 = function ( object, newRotation, optionalOldRotation ) {
- Command.call( this );
- this.type = 'SetRotationCommand';
- this.name = 'Set Rotation';
- this.updatable = true;
- this.object = object;
- if ( object !== undefined && newRotation !== undefined ) {
- this.oldRotation = object.rotation.clone();
- this.newRotation = newRotation.clone();
- }
- if ( optionalOldRotation !== undefined ) {
- this.oldRotation = optionalOldRotation.clone();
- }
- };
- SetRotationCommand$1.prototype = {
- execute: function () {
- this.object.rotation.copy( this.newRotation );
- this.object.updateMatrixWorld( true );
- this.editor.signals.objectChanged.dispatch( this.object );
- },
- undo: function () {
- this.object.rotation.copy( this.oldRotation );
- this.object.updateMatrixWorld( true );
- this.editor.signals.objectChanged.dispatch( this.object );
- },
- update: function ( command ) {
- this.newRotation.copy( command.newRotation );
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.oldRotation = this.oldRotation.toArray();
- output.newRotation = this.newRotation.toArray();
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.oldRotation = new THREE.Euler().fromArray( json.oldRotation );
- this.newRotation = new THREE.Euler().fromArray( json.newRotation );
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetRotationCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param newScale THREE.Vector3
- * @param optionalOldScale THREE.Vector3
- * @constructor
- */
- var SetScaleCommand$1 = function ( object, newScale, optionalOldScale ) {
- Command.call( this );
- this.type = 'SetScaleCommand';
- this.name = 'Set Scale';
- this.updatable = true;
- this.object = object;
- if ( object !== undefined && newScale !== undefined ) {
- this.oldScale = object.scale.clone();
- this.newScale = newScale.clone();
- }
- if ( optionalOldScale !== undefined ) {
- this.oldScale = optionalOldScale.clone();
- }
- };
- SetScaleCommand$1.prototype = {
- execute: function () {
- this.object.scale.copy( this.newScale );
- this.object.updateMatrixWorld( true );
- this.editor.signals.objectChanged.dispatch( this.object );
- },
- undo: function () {
- this.object.scale.copy( this.oldScale );
- this.object.updateMatrixWorld( true );
- this.editor.signals.objectChanged.dispatch( this.object );
- },
- update: function ( command ) {
- this.newScale.copy( command.newScale );
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.oldScale = this.oldScale.toArray();
- output.newScale = this.newScale.toArray();
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.oldScale = new THREE.Vector3().fromArray( json.oldScale );
- this.newScale = new THREE.Vector3().fromArray( json.newScale );
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetScaleCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param scene containing children to import
- * @constructor
- */
- var SetSceneCommand$1 = function ( scene ) {
- Command.call( this );
- this.type = 'SetSceneCommand';
- this.name = 'Set Scene';
- this.cmdArray = [];
- if ( scene !== undefined ) {
- this.cmdArray.push( new SetUuidCommand( this.editor.scene, scene.uuid ) );
- this.cmdArray.push( new SetValueCommand( this.editor.scene, 'name', scene.name ) );
- this.cmdArray.push( new SetValueCommand( this.editor.scene, 'userData', JSON.parse( JSON.stringify( scene.userData ) ) ) );
- while ( scene.children.length > 0 ) {
- var child = scene.children.pop();
- this.cmdArray.push( new AddObjectCommand( child ) );
- }
- }
- };
- SetSceneCommand$1.prototype = {
- execute: function () {
- this.editor.signals.sceneGraphChanged.active = false;
- for ( var i = 0; i < this.cmdArray.length; i ++ ) {
- this.cmdArray[ i ].execute();
- }
- this.editor.signals.sceneGraphChanged.active = true;
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- undo: function () {
- this.editor.signals.sceneGraphChanged.active = false;
- for ( var i = this.cmdArray.length - 1; i >= 0; i -- ) {
- this.cmdArray[ i ].undo();
- }
- this.editor.signals.sceneGraphChanged.active = true;
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- var cmds = [];
- for ( var i = 0; i < this.cmdArray.length; i ++ ) {
- cmds.push( this.cmdArray[ i ].toJSON() );
- }
- output.cmds = cmds;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- var cmds = json.cmds;
- for ( var i = 0; i < cmds.length; i ++ ) {
- var cmd = new window[ cmds[ i ].type ](); // creates a new object of type "json.type"
- cmd.fromJSON( cmds[ i ] );
- this.cmdArray.push( cmd );
- }
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetSceneCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param script javascript object
- * @param attributeName string
- * @param newValue string, object
- * @constructor
- */
- var SetScriptValueCommand$1 = function ( object, script, attributeName, newValue ) {
- Command.call( this );
- this.type = 'SetScriptValueCommand';
- this.name = 'Set Script.' + attributeName;
- this.updatable = true;
- this.object = object;
- this.script = script;
- this.attributeName = attributeName;
- this.oldValue = ( script !== undefined ) ? script[ this.attributeName ] : undefined;
- this.newValue = newValue;
- };
- SetScriptValueCommand$1.prototype = {
- execute: function () {
- this.script[ this.attributeName ] = this.newValue;
- this.editor.signals.scriptChanged.dispatch();
- },
- undo: function () {
- this.script[ this.attributeName ] = this.oldValue;
- this.editor.signals.scriptChanged.dispatch();
- },
- update: function ( cmd ) {
- this.newValue = cmd.newValue;
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
- output.attributeName = this.attributeName;
- output.oldValue = this.oldValue;
- output.newValue = this.newValue;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.oldValue = json.oldValue;
- this.newValue = json.newValue;
- this.attributeName = json.attributeName;
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.script = this.editor.scripts[ json.objectUuid ][ json.index ];
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetScriptValueCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param newUuid string
- * @constructor
- */
- var SetUuidCommand$1 = function ( object, newUuid ) {
- Command.call( this );
- this.type = 'SetUuidCommand';
- this.name = 'Update UUID';
- this.object = object;
- this.oldUuid = ( object !== undefined ) ? object.uuid : undefined;
- this.newUuid = newUuid;
- };
- SetUuidCommand$1.prototype = {
- execute: function () {
- this.object.uuid = this.newUuid;
- this.editor.signals.objectChanged.dispatch( this.object );
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- undo: function () {
- this.object.uuid = this.oldUuid;
- this.editor.signals.objectChanged.dispatch( this.object );
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.oldUuid = this.oldUuid;
- output.newUuid = this.newUuid;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.oldUuid = json.oldUuid;
- this.newUuid = json.newUuid;
- this.object = this.editor.objectByUuid( json.oldUuid );
- if ( this.object === undefined ) {
- this.object = this.editor.objectByUuid( json.newUuid );
- }
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetUuidCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- /**
- * @param object THREE.Object3D
- * @param attributeName string
- * @param newValue number, string, boolean or object
- * @constructor
- */
- var SetValueCommand$1 = function ( object, attributeName, newValue ) {
- Command.call( this );
- this.type = 'SetValueCommand';
- this.name = 'Set ' + attributeName;
- this.updatable = true;
- this.object = object;
- this.attributeName = attributeName;
- this.oldValue = ( object !== undefined ) ? object[ attributeName ] : undefined;
- this.newValue = newValue;
- };
- SetValueCommand$1.prototype = {
- execute: function () {
- this.object[ this.attributeName ] = this.newValue;
- this.editor.signals.objectChanged.dispatch( this.object );
- // this.editor.signals.sceneGraphChanged.dispatch();
- },
- undo: function () {
- this.object[ this.attributeName ] = this.oldValue;
- this.editor.signals.objectChanged.dispatch( this.object );
- // this.editor.signals.sceneGraphChanged.dispatch();
- },
- update: function ( cmd ) {
- this.newValue = cmd.newValue;
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.attributeName = this.attributeName;
- output.oldValue = this.oldValue;
- output.newValue = this.newValue;
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.attributeName = json.attributeName;
- this.oldValue = json.oldValue;
- this.newValue = json.newValue;
- this.object = this.editor.objectByUuid( json.objectUuid );
- }
- };
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- /* global QUnit */
- QUnit.module( 'Editor', () => {
- QUnit.module( 'Commands', () => {
- QUnit.module.todo( 'SetValueCommand', () => {
- QUnit.test( 'write me !', ( assert ) => {
- assert.ok( false, "everything's gonna be alright" );
- } );
- } );
- } );
- } );
- /**
- * @author TristanVALCKE / https://github.com/Itee
- */
- // TODO (Itee) Editor is not es6 module so care to include order !!!
- // TODO: all views could not be testable, waiting modular code before implement units tests on them
- //editor
- //editor/commands
- //editor/others
- } );
- })));
|