| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442 |
- (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( 2, 2 );
- 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 );
- 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 radius = 1;
- var segments = 32;
- var geometry = new THREE.CircleBufferGeometry( radius, segments );
- 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 radiusTop = 1;
- var radiusBottom = 1;
- var height = 2;
- var radiusSegments = 32;
- var heightSegments = 1;
- var openEnded = false;
- var geometry = new THREE.CylinderBufferGeometry( radiusTop, radiusBottom, height, radiusSegments, heightSegments, openEnded );
- 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 radius = 1;
- var widthSegments = 32;
- var heightSegments = 16;
- var phiStart = 0;
- var phiLength = Math.PI * 2;
- var thetaStart = 0;
- var thetaLength = Math.PI;
- var geometry = new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength );
- 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 radius = 1;
- var detail = 2;
- var geometry = new THREE.IcosahedronGeometry( radius, detail );
- 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 radius = 2;
- var tube = 1;
- var radialSegments = 32;
- var tubularSegments = 12;
- var arc = Math.PI * 2;
- var geometry = new THREE.TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc );
- 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 radius = 2;
- var tube = 0.8;
- var tubularSegments = 64;
- var radialSegments = 12;
- var p = 2;
- var q = 3;
- var geometry = new THREE.TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q );
- 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( 4, 0 ),
- new THREE.Vector2( 3.5, 0.5 ),
- new THREE.Vector2( 1, 0.75 ),
- new THREE.Vector2( 0.8, 1 ),
- new THREE.Vector2( 0.8, 4 ),
- new THREE.Vector2( 1, 4.2 ),
- new THREE.Vector2( 1.4, 4.8 ),
- new THREE.Vector2( 2, 5 ),
- new THREE.Vector2( 2.5, 5.4 ),
- new THREE.Vector2( 3, 12 )
- ];
- var segments = 20;
- var phiStart = 0;
- var phiLength = 2 * Math.PI;
- var geometry = new THREE.LatheBufferGeometry( points, segments, phiStart, phiLength );
- 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' ) );
- 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 );
- // 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() );
- // updateRenderer();
- } );
- 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
- } );
- })));
|