three.editor.unit.js 198 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (factory());
  5. }(this, (function () { 'use strict';
  6. QUnit.module( "Editor", () => {
  7. /**
  8. * @author dforrer / https://github.com/dforrer
  9. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  10. */
  11. /**
  12. * @param editorRef pointer to main editor object used to initialize
  13. * each command object with a reference to the editor
  14. * @constructor
  15. */
  16. var Command$1 = function ( editorRef ) {
  17. this.id = - 1;
  18. this.inMemory = false;
  19. this.updatable = false;
  20. this.type = '';
  21. this.name = '';
  22. if ( editorRef !== undefined ) {
  23. Command$1.editor = editorRef;
  24. }
  25. this.editor = Command$1.editor;
  26. };
  27. Command$1.prototype.toJSON = function () {
  28. var output = {};
  29. output.type = this.type;
  30. output.id = this.id;
  31. output.name = this.name;
  32. return output;
  33. };
  34. Command$1.prototype.fromJSON = function ( json ) {
  35. this.inMemory = true;
  36. this.type = json.type;
  37. this.id = json.id;
  38. this.name = json.name;
  39. };
  40. /**
  41. * @author TristanVALCKE / https://github.com/Itee
  42. */
  43. /* global QUnit */
  44. QUnit.module( 'Editor', () => {
  45. QUnit.module.todo( 'Command', () => {
  46. QUnit.test( 'write me !', ( assert ) => {
  47. assert.ok( false, "everything's gonna be alright" );
  48. } );
  49. } );
  50. } );
  51. /**
  52. * @author mrdoob / http://mrdoob.com/
  53. */
  54. /**
  55. * @author TristanVALCKE / https://github.com/Itee
  56. */
  57. /* global QUnit */
  58. QUnit.module( 'Editor', () => {
  59. QUnit.module.todo( 'Config', () => {
  60. QUnit.test( 'write me !', ( assert ) => {
  61. assert.ok( false, "everything's gonna be alright" );
  62. } );
  63. } );
  64. } );
  65. /**
  66. * @author mrdoob / http://mrdoob.com/
  67. */
  68. var Editor = function () {
  69. this.DEFAULT_CAMERA = new THREE.PerspectiveCamera( 50, 1, 0.1, 10000 );
  70. this.DEFAULT_CAMERA.name = 'Camera';
  71. this.DEFAULT_CAMERA.position.set( 20, 10, 20 );
  72. this.DEFAULT_CAMERA.lookAt( new THREE.Vector3() );
  73. var Signal = signals.Signal;
  74. this.signals = {
  75. // script
  76. editScript: new Signal(),
  77. // player
  78. startPlayer: new Signal(),
  79. stopPlayer: new Signal(),
  80. // actions
  81. showModal: new Signal(),
  82. // notifications
  83. editorCleared: new Signal(),
  84. savingStarted: new Signal(),
  85. savingFinished: new Signal(),
  86. themeChanged: new Signal(),
  87. transformModeChanged: new Signal(),
  88. snapChanged: new Signal(),
  89. spaceChanged: new Signal(),
  90. rendererChanged: new Signal(),
  91. sceneBackgroundChanged: new Signal(),
  92. sceneFogChanged: new Signal(),
  93. sceneGraphChanged: new Signal(),
  94. cameraChanged: new Signal(),
  95. geometryChanged: new Signal(),
  96. objectSelected: new Signal(),
  97. objectFocused: new Signal(),
  98. objectAdded: new Signal(),
  99. objectChanged: new Signal(),
  100. objectRemoved: new Signal(),
  101. helperAdded: new Signal(),
  102. helperRemoved: new Signal(),
  103. materialChanged: new Signal(),
  104. scriptAdded: new Signal(),
  105. scriptChanged: new Signal(),
  106. scriptRemoved: new Signal(),
  107. windowResize: new Signal(),
  108. showGridChanged: new Signal(),
  109. refreshSidebarObject3D: new Signal(),
  110. historyChanged: new Signal()
  111. };
  112. this.config = new Config( 'threejs-editor' );
  113. this.history = new History( this );
  114. this.storage = new Storage();
  115. this.loader = new Loader( this );
  116. this.camera = this.DEFAULT_CAMERA.clone();
  117. this.scene = new THREE.Scene();
  118. this.scene.name = 'Scene';
  119. this.scene.background = new THREE.Color( 0xaaaaaa );
  120. this.sceneHelpers = new THREE.Scene();
  121. this.object = {};
  122. this.geometries = {};
  123. this.materials = {};
  124. this.textures = {};
  125. this.scripts = {};
  126. this.selected = null;
  127. this.helpers = {};
  128. };
  129. Editor.prototype = {
  130. setTheme: function ( value ) {
  131. document.getElementById( 'theme' ).href = value;
  132. this.signals.themeChanged.dispatch( value );
  133. },
  134. //
  135. setScene: function ( scene ) {
  136. this.scene.uuid = scene.uuid;
  137. this.scene.name = scene.name;
  138. if ( scene.background !== null ) this.scene.background = scene.background.clone();
  139. if ( scene.fog !== null ) this.scene.fog = scene.fog.clone();
  140. this.scene.userData = JSON.parse( JSON.stringify( scene.userData ) );
  141. // avoid render per object
  142. this.signals.sceneGraphChanged.active = false;
  143. while ( scene.children.length > 0 ) {
  144. this.addObject( scene.children[ 0 ] );
  145. }
  146. this.signals.sceneGraphChanged.active = true;
  147. this.signals.sceneGraphChanged.dispatch();
  148. },
  149. //
  150. addObject: function ( object ) {
  151. var scope = this;
  152. object.traverse( function ( child ) {
  153. if ( child.geometry !== undefined ) scope.addGeometry( child.geometry );
  154. if ( child.material !== undefined ) scope.addMaterial( child.material );
  155. scope.addHelper( child );
  156. } );
  157. this.scene.add( object );
  158. this.signals.objectAdded.dispatch( object );
  159. this.signals.sceneGraphChanged.dispatch();
  160. },
  161. moveObject: function ( object, parent, before ) {
  162. if ( parent === undefined ) {
  163. parent = this.scene;
  164. }
  165. parent.add( object );
  166. // sort children array
  167. if ( before !== undefined ) {
  168. var index = parent.children.indexOf( before );
  169. parent.children.splice( index, 0, object );
  170. parent.children.pop();
  171. }
  172. this.signals.sceneGraphChanged.dispatch();
  173. },
  174. nameObject: function ( object, name ) {
  175. object.name = name;
  176. this.signals.sceneGraphChanged.dispatch();
  177. },
  178. removeObject: function ( object ) {
  179. if ( object.parent === null ) return; // avoid deleting the camera or scene
  180. var scope = this;
  181. object.traverse( function ( child ) {
  182. scope.removeHelper( child );
  183. } );
  184. object.parent.remove( object );
  185. this.signals.objectRemoved.dispatch( object );
  186. this.signals.sceneGraphChanged.dispatch();
  187. },
  188. addGeometry: function ( geometry ) {
  189. this.geometries[ geometry.uuid ] = geometry;
  190. },
  191. setGeometryName: function ( geometry, name ) {
  192. geometry.name = name;
  193. this.signals.sceneGraphChanged.dispatch();
  194. },
  195. addMaterial: function ( material ) {
  196. this.materials[ material.uuid ] = material;
  197. },
  198. setMaterialName: function ( material, name ) {
  199. material.name = name;
  200. this.signals.sceneGraphChanged.dispatch();
  201. },
  202. addTexture: function ( texture ) {
  203. this.textures[ texture.uuid ] = texture;
  204. },
  205. //
  206. addHelper: function () {
  207. var geometry = new THREE.SphereBufferGeometry( 2, 4, 2 );
  208. var material = new THREE.MeshBasicMaterial( { color: 0xff0000, visible: false } );
  209. return function ( object ) {
  210. var helper;
  211. if ( object instanceof THREE.Camera ) {
  212. helper = new THREE.CameraHelper( object, 1 );
  213. } else if ( object instanceof THREE.PointLight ) {
  214. helper = new THREE.PointLightHelper( object, 1 );
  215. } else if ( object instanceof THREE.DirectionalLight ) {
  216. helper = new THREE.DirectionalLightHelper( object, 1 );
  217. } else if ( object instanceof THREE.SpotLight ) {
  218. helper = new THREE.SpotLightHelper( object, 1 );
  219. } else if ( object instanceof THREE.HemisphereLight ) {
  220. helper = new THREE.HemisphereLightHelper( object, 1 );
  221. } else if ( object instanceof THREE.SkinnedMesh ) {
  222. helper = new THREE.SkeletonHelper( object );
  223. } else {
  224. // no helper for this object type
  225. return;
  226. }
  227. var picker = new THREE.Mesh( geometry, material );
  228. picker.name = 'picker';
  229. picker.userData.object = object;
  230. helper.add( picker );
  231. this.sceneHelpers.add( helper );
  232. this.helpers[ object.id ] = helper;
  233. this.signals.helperAdded.dispatch( helper );
  234. };
  235. }(),
  236. removeHelper: function ( object ) {
  237. if ( this.helpers[ object.id ] !== undefined ) {
  238. var helper = this.helpers[ object.id ];
  239. helper.parent.remove( helper );
  240. delete this.helpers[ object.id ];
  241. this.signals.helperRemoved.dispatch( helper );
  242. }
  243. },
  244. //
  245. addScript: function ( object, script ) {
  246. if ( this.scripts[ object.uuid ] === undefined ) {
  247. this.scripts[ object.uuid ] = [];
  248. }
  249. this.scripts[ object.uuid ].push( script );
  250. this.signals.scriptAdded.dispatch( script );
  251. },
  252. removeScript: function ( object, script ) {
  253. if ( this.scripts[ object.uuid ] === undefined ) return;
  254. var index = this.scripts[ object.uuid ].indexOf( script );
  255. if ( index !== - 1 ) {
  256. this.scripts[ object.uuid ].splice( index, 1 );
  257. }
  258. this.signals.scriptRemoved.dispatch( script );
  259. },
  260. getObjectMaterial: function ( object, slot ) {
  261. var material = object.material;
  262. if ( Array.isArray( material ) ) {
  263. material = material[ slot ];
  264. }
  265. return material;
  266. },
  267. setObjectMaterial: function ( object, slot, newMaterial ) {
  268. if ( Array.isArray( object.material ) ) {
  269. object.material[ slot ] = newMaterial;
  270. } else {
  271. object.material = newMaterial;
  272. }
  273. },
  274. //
  275. select: function ( object ) {
  276. if ( this.selected === object ) return;
  277. var uuid = null;
  278. if ( object !== null ) {
  279. uuid = object.uuid;
  280. }
  281. this.selected = object;
  282. this.config.setKey( 'selected', uuid );
  283. this.signals.objectSelected.dispatch( object );
  284. },
  285. selectById: function ( id ) {
  286. if ( id === this.camera.id ) {
  287. this.select( this.camera );
  288. return;
  289. }
  290. this.select( this.scene.getObjectById( id, true ) );
  291. },
  292. selectByUuid: function ( uuid ) {
  293. var scope = this;
  294. this.scene.traverse( function ( child ) {
  295. if ( child.uuid === uuid ) {
  296. scope.select( child );
  297. }
  298. } );
  299. },
  300. deselect: function () {
  301. this.select( null );
  302. },
  303. focus: function ( object ) {
  304. this.signals.objectFocused.dispatch( object );
  305. },
  306. focusById: function ( id ) {
  307. this.focus( this.scene.getObjectById( id, true ) );
  308. },
  309. clear: function () {
  310. this.history.clear();
  311. this.storage.clear();
  312. this.camera.copy( this.DEFAULT_CAMERA );
  313. this.scene.background.setHex( 0xaaaaaa );
  314. this.scene.fog = null;
  315. var objects = this.scene.children;
  316. while ( objects.length > 0 ) {
  317. this.removeObject( objects[ 0 ] );
  318. }
  319. this.geometries = {};
  320. this.materials = {};
  321. this.textures = {};
  322. this.scripts = {};
  323. this.deselect();
  324. this.signals.editorCleared.dispatch();
  325. },
  326. //
  327. fromJSON: function ( json ) {
  328. var loader = new THREE.ObjectLoader();
  329. // backwards
  330. if ( json.scene === undefined ) {
  331. this.setScene( loader.parse( json ) );
  332. return;
  333. }
  334. var camera = loader.parse( json.camera );
  335. this.camera.copy( camera );
  336. this.camera.aspect = this.DEFAULT_CAMERA.aspect;
  337. this.camera.updateProjectionMatrix();
  338. this.history.fromJSON( json.history );
  339. this.scripts = json.scripts;
  340. this.setScene( loader.parse( json.scene ) );
  341. },
  342. toJSON: function () {
  343. // scripts clean up
  344. var scene = this.scene;
  345. var scripts = this.scripts;
  346. for ( var key in scripts ) {
  347. var script = scripts[ key ];
  348. if ( script.length === 0 || scene.getObjectByProperty( 'uuid', key ) === undefined ) {
  349. delete scripts[ key ];
  350. }
  351. }
  352. //
  353. return {
  354. metadata: {},
  355. project: {
  356. gammaInput: this.config.getKey( 'project/renderer/gammaInput' ),
  357. gammaOutput: this.config.getKey( 'project/renderer/gammaOutput' ),
  358. shadows: this.config.getKey( 'project/renderer/shadows' ),
  359. vr: this.config.getKey( 'project/vr' )
  360. },
  361. camera: this.camera.toJSON(),
  362. scene: this.scene.toJSON(),
  363. scripts: this.scripts,
  364. history: this.history.toJSON()
  365. };
  366. },
  367. objectByUuid: function ( uuid ) {
  368. return this.scene.getObjectByProperty( 'uuid', uuid, true );
  369. },
  370. execute: function ( cmd, optionalName ) {
  371. this.history.execute( cmd, optionalName );
  372. },
  373. undo: function () {
  374. this.history.undo();
  375. },
  376. redo: function () {
  377. this.history.redo();
  378. }
  379. };
  380. /**
  381. * @author TristanVALCKE / https://github.com/Itee
  382. */
  383. /* global QUnit */
  384. QUnit.module( 'Editor', () => {
  385. QUnit.module.todo( 'Editor', () => {
  386. QUnit.test( 'write me !', ( assert ) => {
  387. assert.ok( false, "everything's gonna be alright" );
  388. } );
  389. } );
  390. } );
  391. /**
  392. * @author dforrer / https://github.com/dforrer
  393. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  394. */
  395. History = function ( editor ) {
  396. this.editor = editor;
  397. this.undos = [];
  398. this.redos = [];
  399. this.lastCmdTime = new Date();
  400. this.idCounter = 0;
  401. this.historyDisabled = false;
  402. this.config = editor.config;
  403. //Set editor-reference in Command
  404. Command( editor );
  405. // signals
  406. var scope = this;
  407. this.editor.signals.startPlayer.add( function () {
  408. scope.historyDisabled = true;
  409. } );
  410. this.editor.signals.stopPlayer.add( function () {
  411. scope.historyDisabled = false;
  412. } );
  413. };
  414. History.prototype = {
  415. execute: function ( cmd, optionalName ) {
  416. var lastCmd = this.undos[ this.undos.length - 1 ];
  417. var timeDifference = new Date().getTime() - this.lastCmdTime.getTime();
  418. var isUpdatableCmd = lastCmd &&
  419. lastCmd.updatable &&
  420. cmd.updatable &&
  421. lastCmd.object === cmd.object &&
  422. lastCmd.type === cmd.type &&
  423. lastCmd.script === cmd.script &&
  424. lastCmd.attributeName === cmd.attributeName;
  425. if ( isUpdatableCmd && cmd.type === "SetScriptValueCommand" ) {
  426. // When the cmd.type is "SetScriptValueCommand" the timeDifference is ignored
  427. lastCmd.update( cmd );
  428. cmd = lastCmd;
  429. } else if ( isUpdatableCmd && timeDifference < 500 ) {
  430. lastCmd.update( cmd );
  431. cmd = lastCmd;
  432. } else {
  433. // the command is not updatable and is added as a new part of the history
  434. this.undos.push( cmd );
  435. cmd.id = ++ this.idCounter;
  436. }
  437. cmd.name = ( optionalName !== undefined ) ? optionalName : cmd.name;
  438. cmd.execute();
  439. cmd.inMemory = true;
  440. if ( this.config.getKey( 'settings/history' ) ) {
  441. cmd.json = cmd.toJSON(); // serialize the cmd immediately after execution and append the json to the cmd
  442. }
  443. this.lastCmdTime = new Date();
  444. // clearing all the redo-commands
  445. this.redos = [];
  446. this.editor.signals.historyChanged.dispatch( cmd );
  447. },
  448. undo: function () {
  449. if ( this.historyDisabled ) {
  450. alert( "Undo/Redo disabled while scene is playing." );
  451. return;
  452. }
  453. var cmd = undefined;
  454. if ( this.undos.length > 0 ) {
  455. cmd = this.undos.pop();
  456. if ( cmd.inMemory === false ) {
  457. cmd.fromJSON( cmd.json );
  458. }
  459. }
  460. if ( cmd !== undefined ) {
  461. cmd.undo();
  462. this.redos.push( cmd );
  463. this.editor.signals.historyChanged.dispatch( cmd );
  464. }
  465. return cmd;
  466. },
  467. redo: function () {
  468. if ( this.historyDisabled ) {
  469. alert( "Undo/Redo disabled while scene is playing." );
  470. return;
  471. }
  472. var cmd = undefined;
  473. if ( this.redos.length > 0 ) {
  474. cmd = this.redos.pop();
  475. if ( cmd.inMemory === false ) {
  476. cmd.fromJSON( cmd.json );
  477. }
  478. }
  479. if ( cmd !== undefined ) {
  480. cmd.execute();
  481. this.undos.push( cmd );
  482. this.editor.signals.historyChanged.dispatch( cmd );
  483. }
  484. return cmd;
  485. },
  486. toJSON: function () {
  487. var history = {};
  488. history.undos = [];
  489. history.redos = [];
  490. if ( ! this.config.getKey( 'settings/history' ) ) {
  491. return history;
  492. }
  493. // Append Undos to History
  494. for ( var i = 0 ; i < this.undos.length; i ++ ) {
  495. if ( this.undos[ i ].hasOwnProperty( "json" ) ) {
  496. history.undos.push( this.undos[ i ].json );
  497. }
  498. }
  499. // Append Redos to History
  500. for ( var i = 0 ; i < this.redos.length; i ++ ) {
  501. if ( this.redos[ i ].hasOwnProperty( "json" ) ) {
  502. history.redos.push( this.redos[ i ].json );
  503. }
  504. }
  505. return history;
  506. },
  507. fromJSON: function ( json ) {
  508. if ( json === undefined ) return;
  509. for ( var i = 0; i < json.undos.length; i ++ ) {
  510. var cmdJSON = json.undos[ i ];
  511. var cmd = new window[ cmdJSON.type ](); // creates a new object of type "json.type"
  512. cmd.json = cmdJSON;
  513. cmd.id = cmdJSON.id;
  514. cmd.name = cmdJSON.name;
  515. this.undos.push( cmd );
  516. this.idCounter = ( cmdJSON.id > this.idCounter ) ? cmdJSON.id : this.idCounter; // set last used idCounter
  517. }
  518. for ( var i = 0; i < json.redos.length; i ++ ) {
  519. var cmdJSON = json.redos[ i ];
  520. var cmd = new window[ cmdJSON.type ](); // creates a new object of type "json.type"
  521. cmd.json = cmdJSON;
  522. cmd.id = cmdJSON.id;
  523. cmd.name = cmdJSON.name;
  524. this.redos.push( cmd );
  525. this.idCounter = ( cmdJSON.id > this.idCounter ) ? cmdJSON.id : this.idCounter; // set last used idCounter
  526. }
  527. // Select the last executed undo-command
  528. this.editor.signals.historyChanged.dispatch( this.undos[ this.undos.length - 1 ] );
  529. },
  530. clear: function () {
  531. this.undos = [];
  532. this.redos = [];
  533. this.idCounter = 0;
  534. this.editor.signals.historyChanged.dispatch();
  535. },
  536. goToState: function ( id ) {
  537. if ( this.historyDisabled ) {
  538. alert( "Undo/Redo disabled while scene is playing." );
  539. return;
  540. }
  541. this.editor.signals.sceneGraphChanged.active = false;
  542. this.editor.signals.historyChanged.active = false;
  543. var cmd = this.undos.length > 0 ? this.undos[ this.undos.length - 1 ] : undefined; // next cmd to pop
  544. if ( cmd === undefined || id > cmd.id ) {
  545. cmd = this.redo();
  546. while ( cmd !== undefined && id > cmd.id ) {
  547. cmd = this.redo();
  548. }
  549. } else {
  550. while ( true ) {
  551. cmd = this.undos[ this.undos.length - 1 ]; // next cmd to pop
  552. if ( cmd === undefined || id === cmd.id ) break;
  553. this.undo();
  554. }
  555. }
  556. this.editor.signals.sceneGraphChanged.active = true;
  557. this.editor.signals.historyChanged.active = true;
  558. this.editor.signals.sceneGraphChanged.dispatch();
  559. this.editor.signals.historyChanged.dispatch( cmd );
  560. },
  561. enableSerialization: function ( id ) {
  562. /**
  563. * because there might be commands in this.undos and this.redos
  564. * which have not been serialized with .toJSON() we go back
  565. * to the oldest command and redo one command after the other
  566. * while also calling .toJSON() on them.
  567. */
  568. this.goToState( - 1 );
  569. this.editor.signals.sceneGraphChanged.active = false;
  570. this.editor.signals.historyChanged.active = false;
  571. var cmd = this.redo();
  572. while ( cmd !== undefined ) {
  573. if ( ! cmd.hasOwnProperty( "json" ) ) {
  574. cmd.json = cmd.toJSON();
  575. }
  576. cmd = this.redo();
  577. }
  578. this.editor.signals.sceneGraphChanged.active = true;
  579. this.editor.signals.historyChanged.active = true;
  580. this.goToState( id );
  581. }
  582. };
  583. /**
  584. * @author TristanVALCKE / https://github.com/Itee
  585. */
  586. /* global QUnit */
  587. QUnit.module( 'Editor', () => {
  588. QUnit.module.todo( 'History', () => {
  589. QUnit.test( 'write me !', ( assert ) => {
  590. assert.ok( false, "everything's gonna be alright" );
  591. } );
  592. } );
  593. } );
  594. /**
  595. * @author mrdoob / http://mrdoob.com/
  596. */
  597. /**
  598. * @author TristanVALCKE / https://github.com/Itee
  599. */
  600. /* global QUnit */
  601. QUnit.module( 'Editor', () => {
  602. QUnit.module.todo( 'Loader', () => {
  603. QUnit.test( 'write me !', ( assert ) => {
  604. assert.ok( false, "everything's gonna be alright" );
  605. } );
  606. } );
  607. } );
  608. /**
  609. * @author mrdoob / http://mrdoob.com/
  610. */
  611. /**
  612. * @author TristanVALCKE / https://github.com/Itee
  613. */
  614. /* global QUnit */
  615. QUnit.module( 'Editor', () => {
  616. QUnit.module.todo( 'Player', () => {
  617. QUnit.test( 'write me !', ( assert ) => {
  618. assert.ok( false, "everything's gonna be alright" );
  619. } );
  620. } );
  621. } );
  622. /**
  623. * @author mrdoob / http://mrdoob.com/
  624. */
  625. /**
  626. * @author TristanVALCKE / https://github.com/Itee
  627. */
  628. /* global QUnit */
  629. QUnit.module( 'Editor', () => {
  630. QUnit.module.todo( 'Script', () => {
  631. QUnit.test( 'write me !', ( assert ) => {
  632. assert.ok( false, "everything's gonna be alright" );
  633. } );
  634. } );
  635. } );
  636. /**
  637. * @author mrdoob / http://mrdoob.com/
  638. */
  639. /**
  640. * @author TristanVALCKE / https://github.com/Itee
  641. */
  642. /* global QUnit */
  643. QUnit.module( 'Editor', () => {
  644. QUnit.module.todo( 'Menubar', () => {
  645. QUnit.test( 'write me !', ( assert ) => {
  646. assert.ok( false, "everything's gonna be alright" );
  647. } );
  648. } );
  649. } );
  650. /**
  651. * @author mrdoob / http://mrdoob.com/
  652. */
  653. Menubar.Add = function ( editor ) {
  654. var container = new UI.Panel();
  655. container.setClass( 'menu' );
  656. var title = new UI.Panel();
  657. title.setClass( 'title' );
  658. title.setTextContent( 'Add' );
  659. container.add( title );
  660. var options = new UI.Panel();
  661. options.setClass( 'options' );
  662. container.add( options );
  663. //
  664. var meshCount = 0;
  665. var lightCount = 0;
  666. var cameraCount = 0;
  667. editor.signals.editorCleared.add( function () {
  668. meshCount = 0;
  669. lightCount = 0;
  670. cameraCount = 0;
  671. } );
  672. // Group
  673. var option = new UI.Row();
  674. option.setClass( 'option' );
  675. option.setTextContent( 'Group' );
  676. option.onClick( function () {
  677. var mesh = new THREE.Group();
  678. mesh.name = 'Group ' + ( ++ meshCount );
  679. editor.execute( new AddObjectCommand( mesh ) );
  680. } );
  681. options.add( option );
  682. //
  683. options.add( new UI.HorizontalRule() );
  684. // Plane
  685. var option = new UI.Row();
  686. option.setClass( 'option' );
  687. option.setTextContent( 'Plane' );
  688. option.onClick( function () {
  689. var geometry = new THREE.PlaneBufferGeometry( 2, 2 );
  690. var material = new THREE.MeshStandardMaterial();
  691. var mesh = new THREE.Mesh( geometry, material );
  692. mesh.name = 'Plane ' + ( ++ meshCount );
  693. editor.execute( new AddObjectCommand( mesh ) );
  694. } );
  695. options.add( option );
  696. // Box
  697. var option = new UI.Row();
  698. option.setClass( 'option' );
  699. option.setTextContent( 'Box' );
  700. option.onClick( function () {
  701. var geometry = new THREE.BoxBufferGeometry( 1, 1, 1 );
  702. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  703. mesh.name = 'Box ' + ( ++ meshCount );
  704. editor.execute( new AddObjectCommand( mesh ) );
  705. } );
  706. options.add( option );
  707. // Circle
  708. var option = new UI.Row();
  709. option.setClass( 'option' );
  710. option.setTextContent( 'Circle' );
  711. option.onClick( function () {
  712. var radius = 1;
  713. var segments = 32;
  714. var geometry = new THREE.CircleBufferGeometry( radius, segments );
  715. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  716. mesh.name = 'Circle ' + ( ++ meshCount );
  717. editor.execute( new AddObjectCommand( mesh ) );
  718. } );
  719. options.add( option );
  720. // Cylinder
  721. var option = new UI.Row();
  722. option.setClass( 'option' );
  723. option.setTextContent( 'Cylinder' );
  724. option.onClick( function () {
  725. var radiusTop = 1;
  726. var radiusBottom = 1;
  727. var height = 2;
  728. var radiusSegments = 32;
  729. var heightSegments = 1;
  730. var openEnded = false;
  731. var geometry = new THREE.CylinderBufferGeometry( radiusTop, radiusBottom, height, radiusSegments, heightSegments, openEnded );
  732. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  733. mesh.name = 'Cylinder ' + ( ++ meshCount );
  734. editor.execute( new AddObjectCommand( mesh ) );
  735. } );
  736. options.add( option );
  737. // Sphere
  738. var option = new UI.Row();
  739. option.setClass( 'option' );
  740. option.setTextContent( 'Sphere' );
  741. option.onClick( function () {
  742. var radius = 1;
  743. var widthSegments = 32;
  744. var heightSegments = 16;
  745. var phiStart = 0;
  746. var phiLength = Math.PI * 2;
  747. var thetaStart = 0;
  748. var thetaLength = Math.PI;
  749. var geometry = new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength );
  750. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  751. mesh.name = 'Sphere ' + ( ++ meshCount );
  752. editor.execute( new AddObjectCommand( mesh ) );
  753. } );
  754. options.add( option );
  755. // Icosahedron
  756. var option = new UI.Row();
  757. option.setClass( 'option' );
  758. option.setTextContent( 'Icosahedron' );
  759. option.onClick( function () {
  760. var radius = 1;
  761. var detail = 2;
  762. var geometry = new THREE.IcosahedronGeometry( radius, detail );
  763. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  764. mesh.name = 'Icosahedron ' + ( ++ meshCount );
  765. editor.execute( new AddObjectCommand( mesh ) );
  766. } );
  767. options.add( option );
  768. // Torus
  769. var option = new UI.Row();
  770. option.setClass( 'option' );
  771. option.setTextContent( 'Torus' );
  772. option.onClick( function () {
  773. var radius = 2;
  774. var tube = 1;
  775. var radialSegments = 32;
  776. var tubularSegments = 12;
  777. var arc = Math.PI * 2;
  778. var geometry = new THREE.TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc );
  779. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  780. mesh.name = 'Torus ' + ( ++ meshCount );
  781. editor.execute( new AddObjectCommand( mesh ) );
  782. } );
  783. options.add( option );
  784. // TorusKnot
  785. var option = new UI.Row();
  786. option.setClass( 'option' );
  787. option.setTextContent( 'TorusKnot' );
  788. option.onClick( function () {
  789. var radius = 2;
  790. var tube = 0.8;
  791. var tubularSegments = 64;
  792. var radialSegments = 12;
  793. var p = 2;
  794. var q = 3;
  795. var geometry = new THREE.TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q );
  796. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  797. mesh.name = 'TorusKnot ' + ( ++ meshCount );
  798. editor.execute( new AddObjectCommand( mesh ) );
  799. } );
  800. options.add( option );
  801. /*
  802. // Teapot
  803. var option = new UI.Row();
  804. option.setClass( 'option' );
  805. option.setTextContent( 'Teapot' );
  806. option.onClick( function () {
  807. var size = 50;
  808. var segments = 10;
  809. var bottom = true;
  810. var lid = true;
  811. var body = true;
  812. var fitLid = false;
  813. var blinnScale = true;
  814. var material = new THREE.MeshStandardMaterial();
  815. var geometry = new THREE.TeapotBufferGeometry( size, segments, bottom, lid, body, fitLid, blinnScale );
  816. var mesh = new THREE.Mesh( geometry, material );
  817. mesh.name = 'Teapot ' + ( ++ meshCount );
  818. editor.addObject( mesh );
  819. editor.select( mesh );
  820. } );
  821. options.add( option );
  822. */
  823. // Lathe
  824. var option = new UI.Row();
  825. option.setClass( 'option' );
  826. option.setTextContent( 'Lathe' );
  827. option.onClick( function() {
  828. var points = [
  829. new THREE.Vector2( 0, 0 ),
  830. new THREE.Vector2( 4, 0 ),
  831. new THREE.Vector2( 3.5, 0.5 ),
  832. new THREE.Vector2( 1, 0.75 ),
  833. new THREE.Vector2( 0.8, 1 ),
  834. new THREE.Vector2( 0.8, 4 ),
  835. new THREE.Vector2( 1, 4.2 ),
  836. new THREE.Vector2( 1.4, 4.8 ),
  837. new THREE.Vector2( 2, 5 ),
  838. new THREE.Vector2( 2.5, 5.4 ),
  839. new THREE.Vector2( 3, 12 )
  840. ];
  841. var segments = 20;
  842. var phiStart = 0;
  843. var phiLength = 2 * Math.PI;
  844. var geometry = new THREE.LatheBufferGeometry( points, segments, phiStart, phiLength );
  845. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial( { side: THREE.DoubleSide } ) );
  846. mesh.name = 'Lathe ' + ( ++ meshCount );
  847. editor.execute( new AddObjectCommand( mesh ) );
  848. } );
  849. options.add( option );
  850. // Sprite
  851. var option = new UI.Row();
  852. option.setClass( 'option' );
  853. option.setTextContent( 'Sprite' );
  854. option.onClick( function () {
  855. var sprite = new THREE.Sprite( new THREE.SpriteMaterial() );
  856. sprite.name = 'Sprite ' + ( ++ meshCount );
  857. editor.execute( new AddObjectCommand( sprite ) );
  858. } );
  859. options.add( option );
  860. //
  861. options.add( new UI.HorizontalRule() );
  862. // PointLight
  863. var option = new UI.Row();
  864. option.setClass( 'option' );
  865. option.setTextContent( 'PointLight' );
  866. option.onClick( function () {
  867. var color = 0xffffff;
  868. var intensity = 1;
  869. var distance = 0;
  870. var light = new THREE.PointLight( color, intensity, distance );
  871. light.name = 'PointLight ' + ( ++ lightCount );
  872. editor.execute( new AddObjectCommand( light ) );
  873. } );
  874. options.add( option );
  875. // SpotLight
  876. var option = new UI.Row();
  877. option.setClass( 'option' );
  878. option.setTextContent( 'SpotLight' );
  879. option.onClick( function () {
  880. var color = 0xffffff;
  881. var intensity = 1;
  882. var distance = 0;
  883. var angle = Math.PI * 0.1;
  884. var penumbra = 0;
  885. var light = new THREE.SpotLight( color, intensity, distance, angle, penumbra );
  886. light.name = 'SpotLight ' + ( ++ lightCount );
  887. light.target.name = 'SpotLight ' + ( lightCount ) + ' Target';
  888. light.position.set( 5, 10, 7.5 );
  889. editor.execute( new AddObjectCommand( light ) );
  890. } );
  891. options.add( option );
  892. // DirectionalLight
  893. var option = new UI.Row();
  894. option.setClass( 'option' );
  895. option.setTextContent( 'DirectionalLight' );
  896. option.onClick( function () {
  897. var color = 0xffffff;
  898. var intensity = 1;
  899. var light = new THREE.DirectionalLight( color, intensity );
  900. light.name = 'DirectionalLight ' + ( ++ lightCount );
  901. light.target.name = 'DirectionalLight ' + ( lightCount ) + ' Target';
  902. light.position.set( 5, 10, 7.5 );
  903. editor.execute( new AddObjectCommand( light ) );
  904. } );
  905. options.add( option );
  906. // HemisphereLight
  907. var option = new UI.Row();
  908. option.setClass( 'option' );
  909. option.setTextContent( 'HemisphereLight' );
  910. option.onClick( function () {
  911. var skyColor = 0x00aaff;
  912. var groundColor = 0xffaa00;
  913. var intensity = 1;
  914. var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
  915. light.name = 'HemisphereLight ' + ( ++ lightCount );
  916. light.position.set( 0, 10, 0 );
  917. editor.execute( new AddObjectCommand( light ) );
  918. } );
  919. options.add( option );
  920. // AmbientLight
  921. var option = new UI.Row();
  922. option.setClass( 'option' );
  923. option.setTextContent( 'AmbientLight' );
  924. option.onClick( function() {
  925. var color = 0x222222;
  926. var light = new THREE.AmbientLight( color );
  927. light.name = 'AmbientLight ' + ( ++ lightCount );
  928. editor.execute( new AddObjectCommand( light ) );
  929. } );
  930. options.add( option );
  931. //
  932. options.add( new UI.HorizontalRule() );
  933. // PerspectiveCamera
  934. var option = new UI.Row();
  935. option.setClass( 'option' );
  936. option.setTextContent( 'PerspectiveCamera' );
  937. option.onClick( function() {
  938. var camera = new THREE.PerspectiveCamera( 50, 1, 1, 10000 );
  939. camera.name = 'PerspectiveCamera ' + ( ++ cameraCount );
  940. editor.execute( new AddObjectCommand( camera ) );
  941. } );
  942. options.add( option );
  943. return container;
  944. };
  945. /**
  946. * @author TristanVALCKE / https://github.com/Itee
  947. */
  948. /* global QUnit */
  949. QUnit.module( 'Editor', () => {
  950. QUnit.module.todo( 'Menubar.Add', () => {
  951. QUnit.test( 'write me !', ( assert ) => {
  952. assert.ok( false, "everything's gonna be alright" );
  953. } );
  954. } );
  955. } );
  956. /**
  957. * @author mrdoob / http://mrdoob.com/
  958. */
  959. Menubar.Edit = function ( editor ) {
  960. var container = new UI.Panel();
  961. container.setClass( 'menu' );
  962. var title = new UI.Panel();
  963. title.setClass( 'title' );
  964. title.setTextContent( 'Edit' );
  965. container.add( title );
  966. var options = new UI.Panel();
  967. options.setClass( 'options' );
  968. container.add( options );
  969. // Undo
  970. var undo = new UI.Row();
  971. undo.setClass( 'option' );
  972. undo.setTextContent( 'Undo (Ctrl+Z)' );
  973. undo.onClick( function () {
  974. editor.undo();
  975. } );
  976. options.add( undo );
  977. // Redo
  978. var redo = new UI.Row();
  979. redo.setClass( 'option' );
  980. redo.setTextContent( 'Redo (Ctrl+Shift+Z)' );
  981. redo.onClick( function () {
  982. editor.redo();
  983. } );
  984. options.add( redo );
  985. // Clear History
  986. var option = new UI.Row();
  987. option.setClass( 'option' );
  988. option.setTextContent( 'Clear History' );
  989. option.onClick( function () {
  990. if ( confirm( 'The Undo/Redo History will be cleared. Are you sure?' ) ) {
  991. editor.history.clear();
  992. }
  993. } );
  994. options.add( option );
  995. editor.signals.historyChanged.add( function () {
  996. var history = editor.history;
  997. undo.setClass( 'option' );
  998. redo.setClass( 'option' );
  999. if ( history.undos.length == 0 ) {
  1000. undo.setClass( 'inactive' );
  1001. }
  1002. if ( history.redos.length == 0 ) {
  1003. redo.setClass( 'inactive' );
  1004. }
  1005. } );
  1006. // ---
  1007. options.add( new UI.HorizontalRule() );
  1008. // Clone
  1009. var option = new UI.Row();
  1010. option.setClass( 'option' );
  1011. option.setTextContent( 'Clone' );
  1012. option.onClick( function () {
  1013. var object = editor.selected;
  1014. if ( object.parent === null ) return; // avoid cloning the camera or scene
  1015. object = object.clone();
  1016. editor.execute( new AddObjectCommand( object ) );
  1017. } );
  1018. options.add( option );
  1019. // Delete
  1020. var option = new UI.Row();
  1021. option.setClass( 'option' );
  1022. option.setTextContent( 'Delete (Del)' );
  1023. option.onClick( function () {
  1024. var object = editor.selected;
  1025. if ( confirm( 'Delete ' + object.name + '?' ) === false ) return;
  1026. var parent = object.parent;
  1027. if ( parent === undefined ) return; // avoid deleting the camera or scene
  1028. editor.execute( new RemoveObjectCommand( object ) );
  1029. } );
  1030. options.add( option );
  1031. // Minify shaders
  1032. var option = new UI.Row();
  1033. option.setClass( 'option' );
  1034. option.setTextContent( 'Minify Shaders' );
  1035. option.onClick( function() {
  1036. var root = editor.selected || editor.scene;
  1037. var errors = [];
  1038. var nMaterialsChanged = 0;
  1039. var path = [];
  1040. function getPath ( object ) {
  1041. path.length = 0;
  1042. var parent = object.parent;
  1043. if ( parent !== undefined ) getPath( parent );
  1044. path.push( object.name || object.uuid );
  1045. return path;
  1046. }
  1047. var cmds = [];
  1048. root.traverse( function ( object ) {
  1049. var material = object.material;
  1050. if ( material instanceof THREE.ShaderMaterial ) {
  1051. try {
  1052. var shader = glslprep.minifyGlsl( [
  1053. material.vertexShader, material.fragmentShader ] );
  1054. cmds.push( new SetMaterialValueCommand( object, 'vertexShader', shader[ 0 ] ) );
  1055. cmds.push( new SetMaterialValueCommand( object, 'fragmentShader', shader[ 1 ] ) );
  1056. ++nMaterialsChanged;
  1057. } catch ( e ) {
  1058. var path = getPath( object ).join( "/" );
  1059. if ( e instanceof glslprep.SyntaxError )
  1060. errors.push( path + ":" +
  1061. e.line + ":" + e.column + ": " + e.message );
  1062. else {
  1063. errors.push( path +
  1064. ": Unexpected error (see console for details)." );
  1065. console.error( e.stack || e );
  1066. }
  1067. }
  1068. }
  1069. } );
  1070. if ( nMaterialsChanged > 0 ) {
  1071. editor.execute( new MultiCmdsCommand( cmds ), 'Minify Shaders' );
  1072. }
  1073. window.alert( nMaterialsChanged +
  1074. " material(s) were changed.\n" + errors.join( "\n" ) );
  1075. } );
  1076. options.add( option );
  1077. return container;
  1078. };
  1079. /**
  1080. * @author TristanVALCKE / https://github.com/Itee
  1081. */
  1082. /* global QUnit */
  1083. QUnit.module( 'Editor', () => {
  1084. QUnit.module.todo( 'Menubar.Edit', () => {
  1085. QUnit.test( 'write me !', ( assert ) => {
  1086. assert.ok( false, "everything's gonna be alright" );
  1087. } );
  1088. } );
  1089. } );
  1090. /**
  1091. * @author mrdoob / http://mrdoob.com/
  1092. */
  1093. Menubar.Examples = function ( editor ) {
  1094. var container = new UI.Panel();
  1095. container.setClass( 'menu' );
  1096. var title = new UI.Panel();
  1097. title.setClass( 'title' );
  1098. title.setTextContent( 'Examples' );
  1099. container.add( title );
  1100. var options = new UI.Panel();
  1101. options.setClass( 'options' );
  1102. container.add( options );
  1103. // Examples
  1104. var items = [
  1105. { title: 'Arkanoid', file: 'arkanoid.app.json' },
  1106. { title: 'Camera', file: 'camera.app.json' },
  1107. { title: 'Particles', file: 'particles.app.json' },
  1108. { title: 'Pong', file: 'pong.app.json' },
  1109. { title: 'Shaders', file: 'shaders.app.json' }
  1110. ];
  1111. var loader = new THREE.FileLoader();
  1112. for ( var i = 0; i < items.length; i ++ ) {
  1113. ( function ( i ) {
  1114. var item = items[ i ];
  1115. var option = new UI.Row();
  1116. option.setClass( 'option' );
  1117. option.setTextContent( item.title );
  1118. option.onClick( function () {
  1119. if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
  1120. loader.load( 'examples/' + item.file, function ( text ) {
  1121. editor.clear();
  1122. editor.fromJSON( JSON.parse( text ) );
  1123. } );
  1124. }
  1125. } );
  1126. options.add( option );
  1127. } )( i );
  1128. }
  1129. return container;
  1130. };
  1131. /**
  1132. * @author TristanVALCKE / https://github.com/Itee
  1133. */
  1134. /* global QUnit */
  1135. QUnit.module( 'Editor', () => {
  1136. QUnit.module.todo( 'Menubar.Examples', () => {
  1137. QUnit.test( 'write me !', ( assert ) => {
  1138. assert.ok( false, "everything's gonna be alright" );
  1139. } );
  1140. } );
  1141. } );
  1142. /**
  1143. * @author mrdoob / http://mrdoob.com/
  1144. */
  1145. Menubar.File = function ( editor ) {
  1146. var NUMBER_PRECISION = 6;
  1147. function parseNumber( key, value ) {
  1148. return typeof value === 'number' ? parseFloat( value.toFixed( NUMBER_PRECISION ) ) : value;
  1149. }
  1150. //
  1151. var container = new UI.Panel();
  1152. container.setClass( 'menu' );
  1153. var title = new UI.Panel();
  1154. title.setClass( 'title' );
  1155. title.setTextContent( 'File' );
  1156. container.add( title );
  1157. var options = new UI.Panel();
  1158. options.setClass( 'options' );
  1159. container.add( options );
  1160. // New
  1161. var option = new UI.Row();
  1162. option.setClass( 'option' );
  1163. option.setTextContent( 'New' );
  1164. option.onClick( function () {
  1165. if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
  1166. editor.clear();
  1167. }
  1168. } );
  1169. options.add( option );
  1170. //
  1171. options.add( new UI.HorizontalRule() );
  1172. // Import
  1173. var form = document.createElement( 'form' );
  1174. form.style.display = 'none';
  1175. document.body.appendChild( form );
  1176. var fileInput = document.createElement( 'input' );
  1177. fileInput.type = 'file';
  1178. fileInput.addEventListener( 'change', function ( event ) {
  1179. editor.loader.loadFile( fileInput.files[ 0 ] );
  1180. form.reset();
  1181. } );
  1182. form.appendChild( fileInput );
  1183. var option = new UI.Row();
  1184. option.setClass( 'option' );
  1185. option.setTextContent( 'Import' );
  1186. option.onClick( function () {
  1187. fileInput.click();
  1188. } );
  1189. options.add( option );
  1190. //
  1191. options.add( new UI.HorizontalRule() );
  1192. // Export Geometry
  1193. var option = new UI.Row();
  1194. option.setClass( 'option' );
  1195. option.setTextContent( 'Export Geometry' );
  1196. option.onClick( function () {
  1197. var object = editor.selected;
  1198. if ( object === null ) {
  1199. alert( 'No object selected.' );
  1200. return;
  1201. }
  1202. var geometry = object.geometry;
  1203. if ( geometry === undefined ) {
  1204. alert( 'The selected object doesn\'t have geometry.' );
  1205. return;
  1206. }
  1207. var output = geometry.toJSON();
  1208. try {
  1209. output = JSON.stringify( output, parseNumber, '\t' );
  1210. output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
  1211. } catch ( e ) {
  1212. output = JSON.stringify( output );
  1213. }
  1214. saveString( output, 'geometry.json' );
  1215. } );
  1216. options.add( option );
  1217. // Export Object
  1218. var option = new UI.Row();
  1219. option.setClass( 'option' );
  1220. option.setTextContent( 'Export Object' );
  1221. option.onClick( function () {
  1222. var object = editor.selected;
  1223. if ( object === null ) {
  1224. alert( 'No object selected' );
  1225. return;
  1226. }
  1227. var output = object.toJSON();
  1228. try {
  1229. output = JSON.stringify( output, parseNumber, '\t' );
  1230. output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
  1231. } catch ( e ) {
  1232. output = JSON.stringify( output );
  1233. }
  1234. saveString( output, 'model.json' );
  1235. } );
  1236. options.add( option );
  1237. // Export Scene
  1238. var option = new UI.Row();
  1239. option.setClass( 'option' );
  1240. option.setTextContent( 'Export Scene' );
  1241. option.onClick( function () {
  1242. var output = editor.scene.toJSON();
  1243. try {
  1244. output = JSON.stringify( output, parseNumber, '\t' );
  1245. output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
  1246. } catch ( e ) {
  1247. output = JSON.stringify( output );
  1248. }
  1249. saveString( output, 'scene.json' );
  1250. } );
  1251. options.add( option );
  1252. //
  1253. options.add( new UI.HorizontalRule() );
  1254. // Export GLTF
  1255. var option = new UI.Row();
  1256. option.setClass( 'option' );
  1257. option.setTextContent( 'Export GLTF' );
  1258. option.onClick( function () {
  1259. var exporter = new THREE.GLTFExporter();
  1260. exporter.parse( editor.scene, function ( result ) {
  1261. saveString( JSON.stringify( result, null, 2 ), 'scene.gltf' );
  1262. } );
  1263. } );
  1264. options.add( option );
  1265. // Export OBJ
  1266. var option = new UI.Row();
  1267. option.setClass( 'option' );
  1268. option.setTextContent( 'Export OBJ' );
  1269. option.onClick( function () {
  1270. var object = editor.selected;
  1271. if ( object === null ) {
  1272. alert( 'No object selected.' );
  1273. return;
  1274. }
  1275. var exporter = new THREE.OBJExporter();
  1276. saveString( exporter.parse( object ), 'model.obj' );
  1277. } );
  1278. options.add( option );
  1279. // Export STL
  1280. var option = new UI.Row();
  1281. option.setClass( 'option' );
  1282. option.setTextContent( 'Export STL' );
  1283. option.onClick( function () {
  1284. var exporter = new THREE.STLExporter();
  1285. saveString( exporter.parse( editor.scene ), 'model.stl' );
  1286. } );
  1287. options.add( option );
  1288. //
  1289. options.add( new UI.HorizontalRule() );
  1290. // Publish
  1291. var option = new UI.Row();
  1292. option.setClass( 'option' );
  1293. option.setTextContent( 'Publish' );
  1294. option.onClick( function () {
  1295. var zip = new JSZip();
  1296. //
  1297. var output = editor.toJSON();
  1298. output.metadata.type = 'App';
  1299. delete output.history;
  1300. var vr = output.project.vr;
  1301. output = JSON.stringify( output, parseNumber, '\t' );
  1302. output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
  1303. zip.file( 'app.json', output );
  1304. //
  1305. var manager = new THREE.LoadingManager( function () {
  1306. save( zip.generate( { type: 'blob' } ), 'download.zip' );
  1307. } );
  1308. var loader = new THREE.FileLoader( manager );
  1309. loader.load( 'js/libs/app/index.html', function ( content ) {
  1310. var includes = [];
  1311. if ( vr ) {
  1312. includes.push( '<script src="js/WebVR.js"></script>' );
  1313. }
  1314. content = content.replace( '<!-- includes -->', includes.join( '\n\t\t' ) );
  1315. zip.file( 'index.html', content );
  1316. } );
  1317. loader.load( 'js/libs/app.js', function ( content ) {
  1318. zip.file( 'js/app.js', content );
  1319. } );
  1320. loader.load( '../build/three.min.js', function ( content ) {
  1321. zip.file( 'js/three.min.js', content );
  1322. } );
  1323. if ( vr ) {
  1324. loader.load( '../examples/js/vr/WebVR.js', function ( content ) {
  1325. zip.file( 'js/WebVR.js', content );
  1326. } );
  1327. }
  1328. } );
  1329. options.add( option );
  1330. /*
  1331. // Publish (Dropbox)
  1332. var option = new UI.Row();
  1333. option.setClass( 'option' );
  1334. option.setTextContent( 'Publish (Dropbox)' );
  1335. option.onClick( function () {
  1336. var parameters = {
  1337. files: [
  1338. { 'url': 'data:text/plain;base64,' + window.btoa( "Hello, World" ), 'filename': 'app/test.txt' }
  1339. ]
  1340. };
  1341. Dropbox.save( parameters );
  1342. } );
  1343. options.add( option );
  1344. */
  1345. //
  1346. var link = document.createElement( 'a' );
  1347. link.style.display = 'none';
  1348. document.body.appendChild( link ); // Firefox workaround, see #6594
  1349. function save( blob, filename ) {
  1350. link.href = URL.createObjectURL( blob );
  1351. link.download = filename || 'data.json';
  1352. link.click();
  1353. // URL.revokeObjectURL( url ); breaks Firefox...
  1354. }
  1355. function saveString( text, filename ) {
  1356. save( new Blob( [ text ], { type: 'text/plain' } ), filename );
  1357. }
  1358. return container;
  1359. };
  1360. /**
  1361. * @author TristanVALCKE / https://github.com/Itee
  1362. */
  1363. /* global QUnit */
  1364. QUnit.module( 'Editor', () => {
  1365. QUnit.module.todo( 'Menubar.File', () => {
  1366. QUnit.test( 'write me !', ( assert ) => {
  1367. assert.ok( false, "everything's gonna be alright" );
  1368. } );
  1369. } );
  1370. } );
  1371. /**
  1372. * @author mrdoob / http://mrdoob.com/
  1373. */
  1374. Menubar.Help = function ( editor ) {
  1375. var container = new UI.Panel();
  1376. container.setClass( 'menu' );
  1377. var title = new UI.Panel();
  1378. title.setClass( 'title' );
  1379. title.setTextContent( 'Help' );
  1380. container.add( title );
  1381. var options = new UI.Panel();
  1382. options.setClass( 'options' );
  1383. container.add( options );
  1384. // Source code
  1385. var option = new UI.Row();
  1386. option.setClass( 'option' );
  1387. option.setTextContent( 'Source code' );
  1388. option.onClick( function () {
  1389. window.open( 'https://github.com/mrdoob/three.js/tree/master/editor', '_blank' );
  1390. } );
  1391. options.add( option );
  1392. // About
  1393. var option = new UI.Row();
  1394. option.setClass( 'option' );
  1395. option.setTextContent( 'About' );
  1396. option.onClick( function () {
  1397. window.open( 'http://threejs.org', '_blank' );
  1398. } );
  1399. options.add( option );
  1400. return container;
  1401. };
  1402. /**
  1403. * @author TristanVALCKE / https://github.com/Itee
  1404. */
  1405. /* global QUnit */
  1406. QUnit.module( 'Editor', () => {
  1407. QUnit.module.todo( 'Menubar.Help', () => {
  1408. QUnit.test( 'write me !', ( assert ) => {
  1409. assert.ok( false, "everything's gonna be alright" );
  1410. } );
  1411. } );
  1412. } );
  1413. /**
  1414. * @author mrdoob / http://mrdoob.com/
  1415. */
  1416. Menubar.Play = function ( editor ) {
  1417. var signals = editor.signals;
  1418. var container = new UI.Panel();
  1419. container.setClass( 'menu' );
  1420. var isPlaying = false;
  1421. var title = new UI.Panel();
  1422. title.setClass( 'title' );
  1423. title.setTextContent( 'Play' );
  1424. title.onClick( function () {
  1425. if ( isPlaying === false ) {
  1426. isPlaying = true;
  1427. title.setTextContent( 'Stop' );
  1428. signals.startPlayer.dispatch();
  1429. } else {
  1430. isPlaying = false;
  1431. title.setTextContent( 'Play' );
  1432. signals.stopPlayer.dispatch();
  1433. }
  1434. } );
  1435. container.add( title );
  1436. return container;
  1437. };
  1438. /**
  1439. * @author TristanVALCKE / https://github.com/Itee
  1440. */
  1441. /* global QUnit */
  1442. QUnit.module( 'Editor', () => {
  1443. QUnit.module.todo( 'Menubar.Play', () => {
  1444. QUnit.test( 'write me !', ( assert ) => {
  1445. assert.ok( false, "everything's gonna be alright" );
  1446. } );
  1447. } );
  1448. } );
  1449. /**
  1450. * @author mrdoob / http://mrdoob.com/
  1451. */
  1452. Menubar.Status = function ( editor ) {
  1453. var container = new UI.Panel();
  1454. container.setClass( 'menu right' );
  1455. var autosave = new UI.THREE.Boolean( editor.config.getKey( 'autosave' ), 'autosave' );
  1456. autosave.text.setColor( '#888' );
  1457. autosave.onChange( function () {
  1458. var value = this.getValue();
  1459. editor.config.setKey( 'autosave', value );
  1460. if ( value === true ) {
  1461. editor.signals.sceneGraphChanged.dispatch();
  1462. }
  1463. } );
  1464. container.add( autosave );
  1465. editor.signals.savingStarted.add( function () {
  1466. autosave.text.setTextDecoration( 'underline' );
  1467. } );
  1468. editor.signals.savingFinished.add( function () {
  1469. autosave.text.setTextDecoration( 'none' );
  1470. } );
  1471. var version = new UI.Text( 'r' + THREE.REVISION );
  1472. version.setClass( 'title' );
  1473. version.setOpacity( 0.5 );
  1474. container.add( version );
  1475. return container;
  1476. };
  1477. /**
  1478. * @author TristanVALCKE / https://github.com/Itee
  1479. */
  1480. /* global QUnit */
  1481. QUnit.module( 'Editor', () => {
  1482. QUnit.module.todo( 'Menubar.Status', () => {
  1483. QUnit.test( 'write me !', ( assert ) => {
  1484. assert.ok( false, "everything's gonna be alright" );
  1485. } );
  1486. } );
  1487. } );
  1488. /**
  1489. * @author mrdoob / http://mrdoob.com/
  1490. */
  1491. Menubar.View = function ( editor ) {
  1492. var container = new UI.Panel();
  1493. container.setClass( 'menu' );
  1494. var title = new UI.Panel();
  1495. title.setClass( 'title' );
  1496. title.setTextContent( 'View' );
  1497. container.add( title );
  1498. var options = new UI.Panel();
  1499. options.setClass( 'options' );
  1500. container.add( options );
  1501. // VR mode
  1502. var option = new UI.Row();
  1503. option.setClass( 'option' );
  1504. option.setTextContent( 'VR mode' );
  1505. option.onClick( function () {
  1506. if ( WEBVR.isAvailable() === true ) {
  1507. editor.signals.enterVR.dispatch();
  1508. } else {
  1509. alert( 'WebVR not available' );
  1510. }
  1511. } );
  1512. options.add( option );
  1513. return container;
  1514. };
  1515. /**
  1516. * @author TristanVALCKE / https://github.com/Itee
  1517. */
  1518. /* global QUnit */
  1519. QUnit.module( 'Editor', () => {
  1520. QUnit.module.todo( 'Menubar.View', () => {
  1521. QUnit.test( 'write me !', ( assert ) => {
  1522. assert.ok( false, "everything's gonna be alright" );
  1523. } );
  1524. } );
  1525. } );
  1526. /**
  1527. * @author mrdoob / http://mrdoob.com/
  1528. */
  1529. /**
  1530. * @author TristanVALCKE / https://github.com/Itee
  1531. */
  1532. /* global QUnit */
  1533. QUnit.module( 'Editor', () => {
  1534. QUnit.module.todo( 'Sidebar', () => {
  1535. QUnit.test( 'write me !', ( assert ) => {
  1536. assert.ok( false, "everything's gonna be alright" );
  1537. } );
  1538. } );
  1539. } );
  1540. /**
  1541. * @author mrdoob / http://mrdoob.com/
  1542. */
  1543. Sidebar.Animation = function ( editor ) {
  1544. var signals = editor.signals;
  1545. var options = {};
  1546. var possibleAnimations = {};
  1547. var container = new UI.Panel();
  1548. container.setDisplay( 'none' );
  1549. container.add( new UI.Text( 'Animation' ).setTextTransform( 'uppercase' ) );
  1550. container.add( new UI.Break() );
  1551. container.add( new UI.Break() );
  1552. var animationsRow = new UI.Row();
  1553. container.add( animationsRow );
  1554. return container;
  1555. };
  1556. /**
  1557. * @author TristanVALCKE / https://github.com/Itee
  1558. */
  1559. /* global QUnit */
  1560. QUnit.module( 'Editor', () => {
  1561. QUnit.module.todo( 'Sidebar.Animation', () => {
  1562. QUnit.test( 'write me !', ( assert ) => {
  1563. assert.ok( false, "everything's gonna be alright" );
  1564. } );
  1565. } );
  1566. } );
  1567. /**
  1568. * @author mrdoob / http://mrdoob.com/
  1569. */
  1570. Sidebar.Geometry = function ( editor ) {
  1571. var signals = editor.signals;
  1572. var container = new UI.Panel();
  1573. container.setBorderTop( '0' );
  1574. container.setPaddingTop( '20px' );
  1575. // Actions
  1576. /*
  1577. var objectActions = new UI.Select().setPosition( 'absolute' ).setRight( '8px' ).setFontSize( '11px' );
  1578. objectActions.setOptions( {
  1579. 'Actions': 'Actions',
  1580. 'Center': 'Center',
  1581. 'Convert': 'Convert',
  1582. 'Flatten': 'Flatten'
  1583. } );
  1584. objectActions.onClick( function ( event ) {
  1585. event.stopPropagation(); // Avoid panel collapsing
  1586. } );
  1587. objectActions.onChange( function ( event ) {
  1588. var action = this.getValue();
  1589. var object = editor.selected;
  1590. var geometry = object.geometry;
  1591. if ( confirm( action + ' ' + object.name + '?' ) === false ) return;
  1592. switch ( action ) {
  1593. case 'Center':
  1594. var offset = geometry.center();
  1595. var newPosition = object.position.clone();
  1596. newPosition.sub( offset );
  1597. editor.execute( new SetPositionCommand( object, newPosition ) );
  1598. editor.signals.geometryChanged.dispatch( object );
  1599. break;
  1600. case 'Convert':
  1601. if ( geometry instanceof THREE.Geometry ) {
  1602. editor.execute( new SetGeometryCommand( object, new THREE.BufferGeometry().fromGeometry( geometry ) ) );
  1603. }
  1604. break;
  1605. case 'Flatten':
  1606. var newGeometry = geometry.clone();
  1607. newGeometry.uuid = geometry.uuid;
  1608. newGeometry.applyMatrix( object.matrix );
  1609. var cmds = [ new SetGeometryCommand( object, newGeometry ),
  1610. new SetPositionCommand( object, new THREE.Vector3( 0, 0, 0 ) ),
  1611. new SetRotationCommand( object, new THREE.Euler( 0, 0, 0 ) ),
  1612. new SetScaleCommand( object, new THREE.Vector3( 1, 1, 1 ) ) ];
  1613. editor.execute( new MultiCmdsCommand( cmds ), 'Flatten Geometry' );
  1614. break;
  1615. }
  1616. this.setValue( 'Actions' );
  1617. } );
  1618. container.addStatic( objectActions );
  1619. */
  1620. // type
  1621. var geometryTypeRow = new UI.Row();
  1622. var geometryType = new UI.Text();
  1623. geometryTypeRow.add( new UI.Text( 'Type' ).setWidth( '90px' ) );
  1624. geometryTypeRow.add( geometryType );
  1625. container.add( geometryTypeRow );
  1626. // uuid
  1627. var geometryUUIDRow = new UI.Row();
  1628. var geometryUUID = new UI.Input().setWidth( '102px' ).setFontSize( '12px' ).setDisabled( true );
  1629. var geometryUUIDRenew = new UI.Button( 'New' ).setMarginLeft( '7px' ).onClick( function () {
  1630. geometryUUID.setValue( THREE.Math.generateUUID() );
  1631. editor.execute( new SetGeometryValueCommand( editor.selected, 'uuid', geometryUUID.getValue() ) );
  1632. } );
  1633. geometryUUIDRow.add( new UI.Text( 'UUID' ).setWidth( '90px' ) );
  1634. geometryUUIDRow.add( geometryUUID );
  1635. geometryUUIDRow.add( geometryUUIDRenew );
  1636. container.add( geometryUUIDRow );
  1637. // name
  1638. var geometryNameRow = new UI.Row();
  1639. var geometryName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
  1640. editor.execute( new SetGeometryValueCommand( editor.selected, 'name', geometryName.getValue() ) );
  1641. } );
  1642. geometryNameRow.add( new UI.Text( 'Name' ).setWidth( '90px' ) );
  1643. geometryNameRow.add( geometryName );
  1644. container.add( geometryNameRow );
  1645. // geometry
  1646. container.add( new Sidebar.Geometry.Geometry( editor ) );
  1647. // buffergeometry
  1648. container.add( new Sidebar.Geometry.BufferGeometry( editor ) );
  1649. // parameters
  1650. var parameters = new UI.Span();
  1651. container.add( parameters );
  1652. //
  1653. function build() {
  1654. var object = editor.selected;
  1655. if ( object && object.geometry ) {
  1656. var geometry = object.geometry;
  1657. container.setDisplay( 'block' );
  1658. geometryType.setValue( geometry.type );
  1659. geometryUUID.setValue( geometry.uuid );
  1660. geometryName.setValue( geometry.name );
  1661. //
  1662. parameters.clear();
  1663. if ( geometry.type === 'BufferGeometry' || geometry.type === 'Geometry' ) {
  1664. parameters.add( new Sidebar.Geometry.Modifiers( editor, object ) );
  1665. } else if ( Sidebar.Geometry[ geometry.type ] !== undefined ) {
  1666. parameters.add( new Sidebar.Geometry[ geometry.type ]( editor, object ) );
  1667. }
  1668. } else {
  1669. container.setDisplay( 'none' );
  1670. }
  1671. }
  1672. signals.objectSelected.add( build );
  1673. signals.geometryChanged.add( build );
  1674. return container;
  1675. };
  1676. /**
  1677. * @author TristanVALCKE / https://github.com/Itee
  1678. */
  1679. /* global QUnit */
  1680. QUnit.module( 'Editor', () => {
  1681. QUnit.module.todo( 'Sidebar.Geometry', () => {
  1682. QUnit.test( 'write me !', ( assert ) => {
  1683. assert.ok( false, "everything's gonna be alright" );
  1684. } );
  1685. } );
  1686. } );
  1687. /**
  1688. * @author mrdoob / http://mrdoob.com/
  1689. */
  1690. Sidebar.Geometry.BoxGeometry = function ( editor, object ) {
  1691. var signals = editor.signals;
  1692. var container = new UI.Row();
  1693. var geometry = object.geometry;
  1694. var parameters = geometry.parameters;
  1695. // width
  1696. var widthRow = new UI.Row();
  1697. var width = new UI.Number( parameters.width ).onChange( update );
  1698. widthRow.add( new UI.Text( 'Width' ).setWidth( '90px' ) );
  1699. widthRow.add( width );
  1700. container.add( widthRow );
  1701. // height
  1702. var heightRow = new UI.Row();
  1703. var height = new UI.Number( parameters.height ).onChange( update );
  1704. heightRow.add( new UI.Text( 'Height' ).setWidth( '90px' ) );
  1705. heightRow.add( height );
  1706. container.add( heightRow );
  1707. // depth
  1708. var depthRow = new UI.Row();
  1709. var depth = new UI.Number( parameters.depth ).onChange( update );
  1710. depthRow.add( new UI.Text( 'Depth' ).setWidth( '90px' ) );
  1711. depthRow.add( depth );
  1712. container.add( depthRow );
  1713. // widthSegments
  1714. var widthSegmentsRow = new UI.Row();
  1715. var widthSegments = new UI.Integer( parameters.widthSegments ).setRange( 1, Infinity ).onChange( update );
  1716. widthSegmentsRow.add( new UI.Text( 'Width segments' ).setWidth( '90px' ) );
  1717. widthSegmentsRow.add( widthSegments );
  1718. container.add( widthSegmentsRow );
  1719. // heightSegments
  1720. var heightSegmentsRow = new UI.Row();
  1721. var heightSegments = new UI.Integer( parameters.heightSegments ).setRange( 1, Infinity ).onChange( update );
  1722. heightSegmentsRow.add( new UI.Text( 'Height segments' ).setWidth( '90px' ) );
  1723. heightSegmentsRow.add( heightSegments );
  1724. container.add( heightSegmentsRow );
  1725. // depthSegments
  1726. var depthSegmentsRow = new UI.Row();
  1727. var depthSegments = new UI.Integer( parameters.depthSegments ).setRange( 1, Infinity ).onChange( update );
  1728. depthSegmentsRow.add( new UI.Text( 'Depth segments' ).setWidth( '90px' ) );
  1729. depthSegmentsRow.add( depthSegments );
  1730. container.add( depthSegmentsRow );
  1731. //
  1732. function update() {
  1733. editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
  1734. width.getValue(),
  1735. height.getValue(),
  1736. depth.getValue(),
  1737. widthSegments.getValue(),
  1738. heightSegments.getValue(),
  1739. depthSegments.getValue()
  1740. ) ) );
  1741. }
  1742. return container;
  1743. };
  1744. Sidebar.Geometry.BoxBufferGeometry = Sidebar.Geometry.BoxGeometry;
  1745. /**
  1746. * @author TristanVALCKE / https://github.com/Itee
  1747. */
  1748. /* global QUnit */
  1749. QUnit.module( 'Editor', () => {
  1750. QUnit.module.todo( 'Sidebar.Geometry.BoxGeometry', () => {
  1751. QUnit.test( 'write me !', ( assert ) => {
  1752. assert.ok( false, "everything's gonna be alright" );
  1753. } );
  1754. } );
  1755. } );
  1756. /**
  1757. * @author mrdoob / http://mrdoob.com/
  1758. */
  1759. Sidebar.Geometry.BufferGeometry = function ( editor ) {
  1760. var signals = editor.signals;
  1761. var container = new UI.Row();
  1762. function update( object ) {
  1763. if ( object === null ) return; // objectSelected.dispatch( null )
  1764. if ( object === undefined ) return;
  1765. var geometry = object.geometry;
  1766. if ( geometry instanceof THREE.BufferGeometry ) {
  1767. container.clear();
  1768. container.setDisplay( 'block' );
  1769. var index = geometry.index;
  1770. if ( index !== null ) {
  1771. var panel = new UI.Row();
  1772. panel.add( new UI.Text( 'index' ).setWidth( '90px' ) );
  1773. panel.add( new UI.Text( ( index.count ).format() ).setFontSize( '12px' ) );
  1774. container.add( panel );
  1775. }
  1776. var attributes = geometry.attributes;
  1777. for ( var name in attributes ) {
  1778. var attribute = attributes[ name ];
  1779. var panel = new UI.Row();
  1780. panel.add( new UI.Text( name ).setWidth( '90px' ) );
  1781. panel.add( new UI.Text( ( attribute.count ).format() + ' (' + attribute.itemSize + ')' ).setFontSize( '12px' ) );
  1782. container.add( panel );
  1783. }
  1784. } else {
  1785. container.setDisplay( 'none' );
  1786. }
  1787. }
  1788. signals.objectSelected.add( update );
  1789. signals.geometryChanged.add( update );
  1790. return container;
  1791. };
  1792. /**
  1793. * @author TristanVALCKE / https://github.com/Itee
  1794. */
  1795. /* global QUnit */
  1796. QUnit.module( 'Editor', () => {
  1797. QUnit.module.todo( 'Sidebar.Geometry.BufferGeometry', () => {
  1798. QUnit.test( 'write me !', ( assert ) => {
  1799. assert.ok( false, "everything's gonna be alright" );
  1800. } );
  1801. } );
  1802. } );
  1803. /**
  1804. * @author mrdoob / http://mrdoob.com/
  1805. */
  1806. Sidebar.Geometry.CircleGeometry = function ( editor, object ) {
  1807. var signals = editor.signals;
  1808. var container = new UI.Row();
  1809. var geometry = object.geometry;
  1810. var parameters = geometry.parameters;
  1811. // radius
  1812. var radiusRow = new UI.Row();
  1813. var radius = new UI.Number( parameters.radius ).onChange( update );
  1814. radiusRow.add( new UI.Text( 'Radius' ).setWidth( '90px' ) );
  1815. radiusRow.add( radius );
  1816. container.add( radiusRow );
  1817. // segments
  1818. var segmentsRow = new UI.Row();
  1819. var segments = new UI.Integer( parameters.segments ).setRange( 3, Infinity ).onChange( update );
  1820. segmentsRow.add( new UI.Text( 'Segments' ).setWidth( '90px' ) );
  1821. segmentsRow.add( segments );
  1822. container.add( segmentsRow );
  1823. // thetaStart
  1824. var thetaStartRow = new UI.Row();
  1825. var thetaStart = new UI.Number( parameters.thetaStart ).onChange( update );
  1826. thetaStartRow.add( new UI.Text( 'Theta start' ).setWidth( '90px' ) );
  1827. thetaStartRow.add( thetaStart );
  1828. container.add( thetaStartRow );
  1829. // thetaLength
  1830. var thetaLengthRow = new UI.Row();
  1831. var thetaLength = new UI.Number( parameters.thetaLength ).onChange( update );
  1832. thetaLengthRow.add( new UI.Text( 'Theta length' ).setWidth( '90px' ) );
  1833. thetaLengthRow.add( thetaLength );
  1834. container.add( thetaLengthRow );
  1835. //
  1836. function update() {
  1837. editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
  1838. radius.getValue(),
  1839. segments.getValue(),
  1840. thetaStart.getValue(),
  1841. thetaLength.getValue()
  1842. ) ) );
  1843. }
  1844. return container;
  1845. };
  1846. Sidebar.Geometry.CircleBufferGeometry = Sidebar.Geometry.CircleGeometry;
  1847. /**
  1848. * @author TristanVALCKE / https://github.com/Itee
  1849. */
  1850. /* global QUnit */
  1851. QUnit.module( 'Editor', () => {
  1852. QUnit.module.todo( 'Sidebar.Geometry.CircleGeometry', () => {
  1853. QUnit.test( 'write me !', ( assert ) => {
  1854. assert.ok( false, "everything's gonna be alright" );
  1855. } );
  1856. } );
  1857. } );
  1858. /**
  1859. * @author mrdoob / http://mrdoob.com/
  1860. */
  1861. Sidebar.Geometry.CylinderGeometry = function ( editor, object ) {
  1862. var signals = editor.signals;
  1863. var container = new UI.Row();
  1864. var geometry = object.geometry;
  1865. var parameters = geometry.parameters;
  1866. // radiusTop
  1867. var radiusTopRow = new UI.Row();
  1868. var radiusTop = new UI.Number( parameters.radiusTop ).onChange( update );
  1869. radiusTopRow.add( new UI.Text( 'Radius top' ).setWidth( '90px' ) );
  1870. radiusTopRow.add( radiusTop );
  1871. container.add( radiusTopRow );
  1872. // radiusBottom
  1873. var radiusBottomRow = new UI.Row();
  1874. var radiusBottom = new UI.Number( parameters.radiusBottom ).onChange( update );
  1875. radiusBottomRow.add( new UI.Text( 'Radius bottom' ).setWidth( '90px' ) );
  1876. radiusBottomRow.add( radiusBottom );
  1877. container.add( radiusBottomRow );
  1878. // height
  1879. var heightRow = new UI.Row();
  1880. var height = new UI.Number( parameters.height ).onChange( update );
  1881. heightRow.add( new UI.Text( 'Height' ).setWidth( '90px' ) );
  1882. heightRow.add( height );
  1883. container.add( heightRow );
  1884. // radialSegments
  1885. var radialSegmentsRow = new UI.Row();
  1886. var radialSegments = new UI.Integer( parameters.radialSegments ).setRange( 1, Infinity ).onChange( update );
  1887. radialSegmentsRow.add( new UI.Text( 'Radial segments' ).setWidth( '90px' ) );
  1888. radialSegmentsRow.add( radialSegments );
  1889. container.add( radialSegmentsRow );
  1890. // heightSegments
  1891. var heightSegmentsRow = new UI.Row();
  1892. var heightSegments = new UI.Integer( parameters.heightSegments ).setRange( 1, Infinity ).onChange( update );
  1893. heightSegmentsRow.add( new UI.Text( 'Height segments' ).setWidth( '90px' ) );
  1894. heightSegmentsRow.add( heightSegments );
  1895. container.add( heightSegmentsRow );
  1896. // openEnded
  1897. var openEndedRow = new UI.Row();
  1898. var openEnded = new UI.Checkbox( parameters.openEnded ).onChange( update );
  1899. openEndedRow.add( new UI.Text( 'Open ended' ).setWidth( '90px' ) );
  1900. openEndedRow.add( openEnded );
  1901. container.add( openEndedRow );
  1902. //
  1903. function update() {
  1904. editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
  1905. radiusTop.getValue(),
  1906. radiusBottom.getValue(),
  1907. height.getValue(),
  1908. radialSegments.getValue(),
  1909. heightSegments.getValue(),
  1910. openEnded.getValue()
  1911. ) ) );
  1912. }
  1913. return container;
  1914. };
  1915. Sidebar.Geometry.CylinderBufferGeometry = Sidebar.Geometry.CylinderGeometry;
  1916. /**
  1917. * @author TristanVALCKE / https://github.com/Itee
  1918. */
  1919. /* global QUnit */
  1920. QUnit.module( 'Editor', () => {
  1921. QUnit.module.todo( 'Sidebar.Geometry.CylinderGeometry', () => {
  1922. QUnit.test( 'write me !', ( assert ) => {
  1923. assert.ok( false, "everything's gonna be alright" );
  1924. } );
  1925. } );
  1926. } );
  1927. /**
  1928. * @author TristanVALCKE / https://github.com/Itee
  1929. */
  1930. /* global QUnit */
  1931. QUnit.module( 'Editor', () => {
  1932. QUnit.module.todo( 'Sidebar.Geometry', () => {
  1933. QUnit.test( 'write me !', ( assert ) => {
  1934. assert.ok( false, "everything's gonna be alright" );
  1935. } );
  1936. } );
  1937. } );
  1938. /**
  1939. * @author mrdoob / http://mrdoob.com/
  1940. */
  1941. Sidebar.Geometry.IcosahedronGeometry = function ( editor, object ) {
  1942. var signals = editor.signals;
  1943. var container = new UI.Row();
  1944. var geometry = object.geometry;
  1945. var parameters = geometry.parameters;
  1946. // radius
  1947. var radiusRow = new UI.Row();
  1948. var radius = new UI.Number( parameters.radius ).onChange( update );
  1949. radiusRow.add( new UI.Text( 'Radius' ).setWidth( '90px' ) );
  1950. radiusRow.add( radius );
  1951. container.add( radiusRow );
  1952. // detail
  1953. var detailRow = new UI.Row();
  1954. var detail = new UI.Integer( parameters.detail ).setRange( 0, Infinity ).onChange( update );
  1955. detailRow.add( new UI.Text( 'Detail' ).setWidth( '90px' ) );
  1956. detailRow.add( detail );
  1957. container.add( detailRow );
  1958. //
  1959. function update() {
  1960. editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
  1961. radius.getValue(),
  1962. detail.getValue()
  1963. ) ) );
  1964. signals.objectChanged.dispatch( object );
  1965. }
  1966. return container;
  1967. };
  1968. Sidebar.Geometry.IcosahedronBufferGeometry = Sidebar.Geometry.IcosahedronGeometry;
  1969. /**
  1970. * @author TristanVALCKE / https://github.com/Itee
  1971. */
  1972. /* global QUnit */
  1973. QUnit.module( 'Editor', () => {
  1974. QUnit.module.todo( 'Sidebar.Geometry.IcosahedronGeometry', () => {
  1975. QUnit.test( 'write me !', ( assert ) => {
  1976. assert.ok( false, "everything's gonna be alright" );
  1977. } );
  1978. } );
  1979. } );
  1980. /**
  1981. * @author rfm1201
  1982. */
  1983. Sidebar.Geometry.LatheGeometry = function( editor, object ) {
  1984. var signals = editor.signals;
  1985. var container = new UI.Row();
  1986. var geometry = object.geometry;
  1987. var parameters = geometry.parameters;
  1988. // segments
  1989. var segmentsRow = new UI.Row();
  1990. var segments = new UI.Integer( parameters.segments ).onChange( update );
  1991. segmentsRow.add( new UI.Text( 'Segments' ).setWidth( '90px' ) );
  1992. segmentsRow.add( segments );
  1993. container.add( segmentsRow );
  1994. // phiStart
  1995. var phiStartRow = new UI.Row();
  1996. var phiStart = new UI.Number( parameters.phiStart * 180 / Math.PI ).onChange( update );
  1997. phiStartRow.add( new UI.Text( 'Phi start (°)' ).setWidth( '90px' ) );
  1998. phiStartRow.add( phiStart );
  1999. container.add( phiStartRow );
  2000. // phiLength
  2001. var phiLengthRow = new UI.Row();
  2002. var phiLength = new UI.Number( parameters.phiLength * 180 / Math.PI ).onChange( update );
  2003. phiLengthRow.add( new UI.Text( 'Phi length (°)' ).setWidth( '90px' ) );
  2004. phiLengthRow.add( phiLength );
  2005. container.add( phiLengthRow );
  2006. // points
  2007. var lastPointIdx = 0;
  2008. var pointsUI = [];
  2009. var pointsRow = new UI.Row();
  2010. pointsRow.add( new UI.Text( 'Points' ).setWidth( '90px' ) );
  2011. var points = new UI.Span().setDisplay( 'inline-block' );
  2012. pointsRow.add( points );
  2013. var pointsList = new UI.Div();
  2014. points.add( pointsList );
  2015. for ( var i = 0; i < parameters.points.length; i ++ ) {
  2016. var point = parameters.points[ i ];
  2017. pointsList.add( createPointRow( point.x, point.y ) );
  2018. }
  2019. var addPointButton = new UI.Button( '+' ).onClick( function() {
  2020. if( pointsUI.length === 0 ){
  2021. pointsList.add( createPointRow( 0, 0 ) );
  2022. } else {
  2023. var point = pointsUI[ pointsUI.length - 1 ];
  2024. pointsList.add( createPointRow( point.x.getValue(), point.y.getValue() ) );
  2025. }
  2026. update();
  2027. } );
  2028. points.add( addPointButton );
  2029. container.add( pointsRow );
  2030. //
  2031. function createPointRow( x, y ) {
  2032. var pointRow = new UI.Div();
  2033. var lbl = new UI.Text( lastPointIdx + 1 ).setWidth( '20px' );
  2034. var txtX = new UI.Number( x ).setRange( 0, Infinity ).setWidth( '40px' ).onChange( update );
  2035. var txtY = new UI.Number( y ).setWidth( '40px' ).onChange( update );
  2036. var idx = lastPointIdx;
  2037. var btn = new UI.Button( '-' ).onClick( function() {
  2038. deletePointRow( idx );
  2039. } );
  2040. pointsUI.push( { row: pointRow, lbl: lbl, x: txtX, y: txtY } );
  2041. lastPointIdx ++;
  2042. pointRow.add( lbl, txtX, txtY, btn );
  2043. return pointRow;
  2044. }
  2045. function deletePointRow( idx ) {
  2046. if ( ! pointsUI[ idx ] ) return;
  2047. pointsList.remove( pointsUI[ idx ].row );
  2048. pointsUI[ idx ] = null;
  2049. update();
  2050. }
  2051. function update() {
  2052. var points = [];
  2053. var count = 0;
  2054. for ( var i = 0; i < pointsUI.length; i ++ ) {
  2055. var pointUI = pointsUI[ i ];
  2056. if ( ! pointUI ) continue;
  2057. points.push( new THREE.Vector2( pointUI.x.getValue(), pointUI.y.getValue() ) );
  2058. count ++;
  2059. pointUI.lbl.setValue( count );
  2060. }
  2061. editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
  2062. points,
  2063. segments.getValue(),
  2064. phiStart.getValue() / 180 * Math.PI,
  2065. phiLength.getValue() / 180 * Math.PI
  2066. ) ) );
  2067. }
  2068. return container;
  2069. };
  2070. Sidebar.Geometry.LatheBufferGeometry = Sidebar.Geometry.LatheGeometry;
  2071. /**
  2072. * @author TristanVALCKE / https://github.com/Itee
  2073. */
  2074. /* global QUnit */
  2075. QUnit.module( 'Editor', () => {
  2076. QUnit.module.todo( 'Sidebar.Geometry.LatheGeometry', () => {
  2077. QUnit.test( 'write me !', ( assert ) => {
  2078. assert.ok( false, "everything's gonna be alright" );
  2079. } );
  2080. } );
  2081. } );
  2082. /**
  2083. * @author mrdoob / http://mrdoob.com/
  2084. */
  2085. Sidebar.Geometry.Modifiers = function ( editor, object ) {
  2086. var signals = editor.signals;
  2087. var container = new UI.Row().setPaddingLeft( '90px' );
  2088. var geometry = object.geometry;
  2089. // Compute Vertex Normals
  2090. var button = new UI.Button( 'Compute Vertex Normals' );
  2091. button.onClick( function () {
  2092. geometry.computeVertexNormals();
  2093. if ( geometry instanceof THREE.BufferGeometry ) {
  2094. geometry.attributes.normal.needsUpdate = true;
  2095. } else {
  2096. geometry.normalsNeedUpdate = true;
  2097. }
  2098. signals.geometryChanged.dispatch( object );
  2099. } );
  2100. container.add( button );
  2101. //
  2102. return container;
  2103. };
  2104. /**
  2105. * @author TristanVALCKE / https://github.com/Itee
  2106. */
  2107. /* global QUnit */
  2108. QUnit.module( 'Editor', () => {
  2109. QUnit.module.todo( 'Sidebar.Geometry.Modifiers', () => {
  2110. QUnit.test( 'write me !', ( assert ) => {
  2111. assert.ok( false, "everything's gonna be alright" );
  2112. } );
  2113. } );
  2114. } );
  2115. /**
  2116. * @author mrdoob / http://mrdoob.com/
  2117. */
  2118. Sidebar.Geometry.PlaneGeometry = function ( editor, object ) {
  2119. var signals = editor.signals;
  2120. var container = new UI.Row();
  2121. var geometry = object.geometry;
  2122. var parameters = geometry.parameters;
  2123. // width
  2124. var widthRow = new UI.Row();
  2125. var width = new UI.Number( parameters.width ).onChange( update );
  2126. widthRow.add( new UI.Text( 'Width' ).setWidth( '90px' ) );
  2127. widthRow.add( width );
  2128. container.add( widthRow );
  2129. // height
  2130. var heightRow = new UI.Row();
  2131. var height = new UI.Number( parameters.height ).onChange( update );
  2132. heightRow.add( new UI.Text( 'Height' ).setWidth( '90px' ) );
  2133. heightRow.add( height );
  2134. container.add( heightRow );
  2135. // widthSegments
  2136. var widthSegmentsRow = new UI.Row();
  2137. var widthSegments = new UI.Integer( parameters.widthSegments ).setRange( 1, Infinity ).onChange( update );
  2138. widthSegmentsRow.add( new UI.Text( 'Width segments' ).setWidth( '90px' ) );
  2139. widthSegmentsRow.add( widthSegments );
  2140. container.add( widthSegmentsRow );
  2141. // heightSegments
  2142. var heightSegmentsRow = new UI.Row();
  2143. var heightSegments = new UI.Integer( parameters.heightSegments ).setRange( 1, Infinity ).onChange( update );
  2144. heightSegmentsRow.add( new UI.Text( 'Height segments' ).setWidth( '90px' ) );
  2145. heightSegmentsRow.add( heightSegments );
  2146. container.add( heightSegmentsRow );
  2147. //
  2148. function update() {
  2149. editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
  2150. width.getValue(),
  2151. height.getValue(),
  2152. widthSegments.getValue(),
  2153. heightSegments.getValue()
  2154. ) ) );
  2155. }
  2156. return container;
  2157. };
  2158. Sidebar.Geometry.PlaneBufferGeometry = Sidebar.Geometry.PlaneGeometry;
  2159. /**
  2160. * @author TristanVALCKE / https://github.com/Itee
  2161. */
  2162. /* global QUnit */
  2163. QUnit.module( 'Editor', () => {
  2164. QUnit.module.todo( 'Sidebar.Geometry.PlaneGeometry', () => {
  2165. QUnit.test( 'write me !', ( assert ) => {
  2166. assert.ok( false, "everything's gonna be alright" );
  2167. } );
  2168. } );
  2169. } );
  2170. /**
  2171. * @author mrdoob / http://mrdoob.com/
  2172. */
  2173. Sidebar.Geometry.SphereGeometry = function ( editor, object ) {
  2174. var signals = editor.signals;
  2175. var container = new UI.Row();
  2176. var geometry = object.geometry;
  2177. var parameters = geometry.parameters;
  2178. // radius
  2179. var radiusRow = new UI.Row();
  2180. var radius = new UI.Number( parameters.radius ).onChange( update );
  2181. radiusRow.add( new UI.Text( 'Radius' ).setWidth( '90px' ) );
  2182. radiusRow.add( radius );
  2183. container.add( radiusRow );
  2184. // widthSegments
  2185. var widthSegmentsRow = new UI.Row();
  2186. var widthSegments = new UI.Integer( parameters.widthSegments ).setRange( 1, Infinity ).onChange( update );
  2187. widthSegmentsRow.add( new UI.Text( 'Width segments' ).setWidth( '90px' ) );
  2188. widthSegmentsRow.add( widthSegments );
  2189. container.add( widthSegmentsRow );
  2190. // heightSegments
  2191. var heightSegmentsRow = new UI.Row();
  2192. var heightSegments = new UI.Integer( parameters.heightSegments ).setRange( 1, Infinity ).onChange( update );
  2193. heightSegmentsRow.add( new UI.Text( 'Height segments' ).setWidth( '90px' ) );
  2194. heightSegmentsRow.add( heightSegments );
  2195. container.add( heightSegmentsRow );
  2196. // phiStart
  2197. var phiStartRow = new UI.Row();
  2198. var phiStart = new UI.Number( parameters.phiStart ).onChange( update );
  2199. phiStartRow.add( new UI.Text( 'Phi start' ).setWidth( '90px' ) );
  2200. phiStartRow.add( phiStart );
  2201. container.add( phiStartRow );
  2202. // phiLength
  2203. var phiLengthRow = new UI.Row();
  2204. var phiLength = new UI.Number( parameters.phiLength ).onChange( update );
  2205. phiLengthRow.add( new UI.Text( 'Phi length' ).setWidth( '90px' ) );
  2206. phiLengthRow.add( phiLength );
  2207. container.add( phiLengthRow );
  2208. // thetaStart
  2209. var thetaStartRow = new UI.Row();
  2210. var thetaStart = new UI.Number( parameters.thetaStart ).onChange( update );
  2211. thetaStartRow.add( new UI.Text( 'Theta start' ).setWidth( '90px' ) );
  2212. thetaStartRow.add( thetaStart );
  2213. container.add( thetaStartRow );
  2214. // thetaLength
  2215. var thetaLengthRow = new UI.Row();
  2216. var thetaLength = new UI.Number( parameters.thetaLength ).onChange( update );
  2217. thetaLengthRow.add( new UI.Text( 'Theta length' ).setWidth( '90px' ) );
  2218. thetaLengthRow.add( thetaLength );
  2219. container.add( thetaLengthRow );
  2220. //
  2221. function update() {
  2222. editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
  2223. radius.getValue(),
  2224. widthSegments.getValue(),
  2225. heightSegments.getValue(),
  2226. phiStart.getValue(),
  2227. phiLength.getValue(),
  2228. thetaStart.getValue(),
  2229. thetaLength.getValue()
  2230. ) ) );
  2231. }
  2232. return container;
  2233. };
  2234. Sidebar.Geometry.SphereBufferGeometry = Sidebar.Geometry.SphereGeometry;
  2235. /**
  2236. * @author TristanVALCKE / https://github.com/Itee
  2237. */
  2238. /* global QUnit */
  2239. QUnit.module( 'Editor', () => {
  2240. QUnit.module.todo( 'Sidebar.Geometry.SphereGeometry', () => {
  2241. QUnit.test( 'write me !', ( assert ) => {
  2242. assert.ok( false, "everything's gonna be alright" );
  2243. } );
  2244. } );
  2245. } );
  2246. /**
  2247. * @author tschw
  2248. */
  2249. Sidebar.Geometry.TeapotBufferGeometry = function ( signals, object ) {
  2250. var container = new UI.Row();
  2251. var parameters = object.geometry.parameters;
  2252. // size
  2253. var sizeRow = new UI.Row();
  2254. var size = new UI.Number( parameters.size ).onChange( update );
  2255. sizeRow.add( new UI.Text( 'Size' ).setWidth( '90px' ) );
  2256. sizeRow.add( size );
  2257. container.add( sizeRow );
  2258. // segments
  2259. var segmentsRow = new UI.Row();
  2260. var segments = new UI.Integer( parameters.segments ).setRange( 1, Infinity ).onChange( update );
  2261. segmentsRow.add( new UI.Text( 'Segments' ).setWidth( '90px' ) );
  2262. segmentsRow.add( segments );
  2263. container.add( segmentsRow );
  2264. // bottom
  2265. var bottomRow = new UI.Row();
  2266. var bottom = new UI.Checkbox( parameters.bottom ).onChange( update );
  2267. bottomRow.add( new UI.Text( 'Bottom' ).setWidth( '90px' ) );
  2268. bottomRow.add( bottom );
  2269. container.add( bottomRow );
  2270. // lid
  2271. var lidRow = new UI.Row();
  2272. var lid = new UI.Checkbox( parameters.lid ).onChange( update );
  2273. lidRow.add( new UI.Text( 'Lid' ).setWidth( '90px' ) );
  2274. lidRow.add( lid );
  2275. container.add( lidRow );
  2276. // body
  2277. var bodyRow = new UI.Row();
  2278. var body = new UI.Checkbox( parameters.body ).onChange( update );
  2279. bodyRow.add( new UI.Text( 'Body' ).setWidth( '90px' ) );
  2280. bodyRow.add( body );
  2281. container.add( bodyRow );
  2282. // fitted lid
  2283. var fitLidRow = new UI.Row();
  2284. var fitLid = new UI.Checkbox( parameters.fitLid ).onChange( update );
  2285. fitLidRow.add( new UI.Text( 'Fitted Lid' ).setWidth( '90px' ) );
  2286. fitLidRow.add( fitLid );
  2287. container.add( fitLidRow );
  2288. // blinn-sized
  2289. var blinnRow = new UI.Row();
  2290. var blinn = new UI.Checkbox( parameters.blinn ).onChange( update );
  2291. blinnRow.add( new UI.Text( 'Blinn-scaled' ).setWidth( '90px' ) );
  2292. blinnRow.add( blinn );
  2293. container.add( blinnRow );
  2294. function update() {
  2295. object.geometry.dispose();
  2296. object.geometry = new THREE.TeapotBufferGeometry(
  2297. size.getValue(),
  2298. segments.getValue(),
  2299. bottom.getValue(),
  2300. lid.getValue(),
  2301. body.getValue(),
  2302. fitLid.getValue(),
  2303. blinn.getValue()
  2304. );
  2305. object.geometry.computeBoundingSphere();
  2306. signals.geometryChanged.dispatch( object );
  2307. }
  2308. return container;
  2309. };
  2310. /**
  2311. * @author TristanVALCKE / https://github.com/Itee
  2312. */
  2313. /* global QUnit */
  2314. QUnit.module( 'Editor', () => {
  2315. QUnit.module.todo( 'Sidebar.Geometry.TeapotBufferGeometry', () => {
  2316. QUnit.test( 'write me !', ( assert ) => {
  2317. assert.ok( false, "everything's gonna be alright" );
  2318. } );
  2319. } );
  2320. } );
  2321. /**
  2322. * @author mrdoob / http://mrdoob.com/
  2323. */
  2324. Sidebar.Geometry.TorusGeometry = function ( editor, object ) {
  2325. var signals = editor.signals;
  2326. var container = new UI.Row();
  2327. var geometry = object.geometry;
  2328. var parameters = geometry.parameters;
  2329. // radius
  2330. var radiusRow = new UI.Row();
  2331. var radius = new UI.Number( parameters.radius ).onChange( update );
  2332. radiusRow.add( new UI.Text( 'Radius' ).setWidth( '90px' ) );
  2333. radiusRow.add( radius );
  2334. container.add( radiusRow );
  2335. // tube
  2336. var tubeRow = new UI.Row();
  2337. var tube = new UI.Number( parameters.tube ).onChange( update );
  2338. tubeRow.add( new UI.Text( 'Tube' ).setWidth( '90px' ) );
  2339. tubeRow.add( tube );
  2340. container.add( tubeRow );
  2341. // radialSegments
  2342. var radialSegmentsRow = new UI.Row();
  2343. var radialSegments = new UI.Integer( parameters.radialSegments ).setRange( 1, Infinity ).onChange( update );
  2344. radialSegmentsRow.add( new UI.Text( 'Radial segments' ).setWidth( '90px' ) );
  2345. radialSegmentsRow.add( radialSegments );
  2346. container.add( radialSegmentsRow );
  2347. // tubularSegments
  2348. var tubularSegmentsRow = new UI.Row();
  2349. var tubularSegments = new UI.Integer( parameters.tubularSegments ).setRange( 1, Infinity ).onChange( update );
  2350. tubularSegmentsRow.add( new UI.Text( 'Tubular segments' ).setWidth( '90px' ) );
  2351. tubularSegmentsRow.add( tubularSegments );
  2352. container.add( tubularSegmentsRow );
  2353. // arc
  2354. var arcRow = new UI.Row();
  2355. var arc = new UI.Number( parameters.arc ).onChange( update );
  2356. arcRow.add( new UI.Text( 'Arc' ).setWidth( '90px' ) );
  2357. arcRow.add( arc );
  2358. container.add( arcRow );
  2359. //
  2360. function update() {
  2361. editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
  2362. radius.getValue(),
  2363. tube.getValue(),
  2364. radialSegments.getValue(),
  2365. tubularSegments.getValue(),
  2366. arc.getValue()
  2367. ) ) );
  2368. }
  2369. return container;
  2370. };
  2371. Sidebar.Geometry.TorusBufferGeometry = Sidebar.Geometry.TorusGeometry;
  2372. /**
  2373. * @author TristanVALCKE / https://github.com/Itee
  2374. */
  2375. /* global QUnit */
  2376. QUnit.module( 'Editor', () => {
  2377. QUnit.module.todo( 'Sidebar.Geometry.TorusGeometry', () => {
  2378. QUnit.test( 'write me !', ( assert ) => {
  2379. assert.ok( false, "everything's gonna be alright" );
  2380. } );
  2381. } );
  2382. } );
  2383. /**
  2384. * @author mrdoob / http://mrdoob.com/
  2385. */
  2386. Sidebar.Geometry.TorusKnotGeometry = function ( editor, object ) {
  2387. var signals = editor.signals;
  2388. var container = new UI.Row();
  2389. var geometry = object.geometry;
  2390. var parameters = geometry.parameters;
  2391. // radius
  2392. var radiusRow = new UI.Row();
  2393. var radius = new UI.Number( parameters.radius ).onChange( update );
  2394. radiusRow.add( new UI.Text( 'Radius' ).setWidth( '90px' ) );
  2395. radiusRow.add( radius );
  2396. container.add( radiusRow );
  2397. // tube
  2398. var tubeRow = new UI.Row();
  2399. var tube = new UI.Number( parameters.tube ).onChange( update );
  2400. tubeRow.add( new UI.Text( 'Tube' ).setWidth( '90px' ) );
  2401. tubeRow.add( tube );
  2402. container.add( tubeRow );
  2403. // tubularSegments
  2404. var tubularSegmentsRow = new UI.Row();
  2405. var tubularSegments = new UI.Integer( parameters.tubularSegments ).setRange( 1, Infinity ).onChange( update );
  2406. tubularSegmentsRow.add( new UI.Text( 'Tubular segments' ).setWidth( '90px' ) );
  2407. tubularSegmentsRow.add( tubularSegments );
  2408. container.add( tubularSegmentsRow );
  2409. // radialSegments
  2410. var radialSegmentsRow = new UI.Row();
  2411. var radialSegments = new UI.Integer( parameters.radialSegments ).setRange( 1, Infinity ).onChange( update );
  2412. radialSegmentsRow.add( new UI.Text( 'Radial segments' ).setWidth( '90px' ) );
  2413. radialSegmentsRow.add( radialSegments );
  2414. container.add( radialSegmentsRow );
  2415. // p
  2416. var pRow = new UI.Row();
  2417. var p = new UI.Number( parameters.p ).onChange( update );
  2418. pRow.add( new UI.Text( 'P' ).setWidth( '90px' ) );
  2419. pRow.add( p );
  2420. container.add( pRow );
  2421. // q
  2422. var qRow = new UI.Row();
  2423. var q = new UI.Number( parameters.q ).onChange( update );
  2424. pRow.add( new UI.Text( 'Q' ).setWidth( '90px' ) );
  2425. pRow.add( q );
  2426. container.add( qRow );
  2427. //
  2428. function update() {
  2429. editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
  2430. radius.getValue(),
  2431. tube.getValue(),
  2432. tubularSegments.getValue(),
  2433. radialSegments.getValue(),
  2434. p.getValue(),
  2435. q.getValue()
  2436. ) ) );
  2437. }
  2438. return container;
  2439. };
  2440. Sidebar.Geometry.TorusKnotBufferGeometry = Sidebar.Geometry.TorusKnotGeometry;
  2441. /**
  2442. * @author TristanVALCKE / https://github.com/Itee
  2443. */
  2444. /* global QUnit */
  2445. QUnit.module( 'Editor', () => {
  2446. QUnit.module.todo( 'Sidebar.Geometry.TorusKnotGeometry', () => {
  2447. QUnit.test( 'write me !', ( assert ) => {
  2448. assert.ok( false, "everything's gonna be alright" );
  2449. } );
  2450. } );
  2451. } );
  2452. /**
  2453. * @author dforrer / https://github.com/dforrer
  2454. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  2455. */
  2456. Sidebar.History = function ( editor ) {
  2457. var signals = editor.signals;
  2458. var config = editor.config;
  2459. var history = editor.history;
  2460. var container = new UI.Panel();
  2461. container.add( new UI.Text( 'HISTORY' ) );
  2462. //
  2463. var persistent = new UI.THREE.Boolean( config.getKey( 'settings/history' ), 'persistent' );
  2464. persistent.setPosition( 'absolute' ).setRight( '8px' );
  2465. persistent.onChange( function () {
  2466. var value = this.getValue();
  2467. config.setKey( 'settings/history', value );
  2468. if ( value ) {
  2469. alert( 'The history will be preserved across sessions.\nThis can have an impact on performance when working with textures.' );
  2470. var lastUndoCmd = history.undos[ history.undos.length - 1 ];
  2471. var lastUndoId = ( lastUndoCmd !== undefined ) ? lastUndoCmd.id : 0;
  2472. editor.history.enableSerialization( lastUndoId );
  2473. } else {
  2474. signals.historyChanged.dispatch();
  2475. }
  2476. } );
  2477. container.add( persistent );
  2478. container.add( new UI.Break(), new UI.Break() );
  2479. var ignoreObjectSelectedSignal = false;
  2480. var outliner = new UI.Outliner( editor );
  2481. outliner.onChange( function () {
  2482. ignoreObjectSelectedSignal = true;
  2483. editor.history.goToState( parseInt( outliner.getValue() ) );
  2484. ignoreObjectSelectedSignal = false;
  2485. } );
  2486. container.add( outliner );
  2487. //
  2488. var refreshUI = function () {
  2489. var options = [];
  2490. var enumerator = 1;
  2491. function buildOption( object ) {
  2492. var option = document.createElement( 'div' );
  2493. option.value = object.id;
  2494. return option;
  2495. }
  2496. ( function addObjects( objects ) {
  2497. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  2498. var object = objects[ i ];
  2499. var option = buildOption( object );
  2500. option.innerHTML = '&nbsp;' + object.name;
  2501. options.push( option );
  2502. }
  2503. } )( history.undos );
  2504. ( function addObjects( objects, pad ) {
  2505. for ( var i = objects.length - 1; i >= 0; i -- ) {
  2506. var object = objects[ i ];
  2507. var option = buildOption( object );
  2508. option.innerHTML = '&nbsp;' + object.name;
  2509. option.style.opacity = 0.3;
  2510. options.push( option );
  2511. }
  2512. } )( history.redos, '&nbsp;' );
  2513. outliner.setOptions( options );
  2514. };
  2515. refreshUI();
  2516. // events
  2517. signals.editorCleared.add( refreshUI );
  2518. signals.historyChanged.add( refreshUI );
  2519. signals.historyChanged.add( function ( cmd ) {
  2520. outliner.setValue( cmd !== undefined ? cmd.id : null );
  2521. } );
  2522. return container;
  2523. };
  2524. /**
  2525. * @author TristanVALCKE / https://github.com/Itee
  2526. */
  2527. /* global QUnit */
  2528. QUnit.module( 'Editor', () => {
  2529. QUnit.module.todo( 'Sidebar.History', () => {
  2530. QUnit.test( 'write me !', ( assert ) => {
  2531. assert.ok( false, "everything's gonna be alright" );
  2532. } );
  2533. } );
  2534. } );
  2535. /**
  2536. * @author mrdoob / http://mrdoob.com/
  2537. */
  2538. Sidebar.Material = function ( editor ) {
  2539. var signals = editor.signals;
  2540. var currentObject;
  2541. var currentMaterialSlot = 0;
  2542. var container = new UI.Panel();
  2543. container.setBorderTop( '0' );
  2544. container.setPaddingTop( '20px' );
  2545. // New / Copy / Paste
  2546. var copiedMaterial;
  2547. var managerRow = new UI.Row();
  2548. // Current material slot
  2549. var materialSlotRow = new UI.Row();
  2550. materialSlotRow.add( new UI.Text( 'Slot' ).setWidth( '90px' ) );
  2551. var materialSlotSelect = new UI.Select().setWidth( '170px' ).setFontSize( '12px' ).onChange( update );
  2552. materialSlotSelect.setOptions( { 0: '' } ).setValue( 0 );
  2553. materialSlotRow.add( materialSlotSelect );
  2554. container.add( materialSlotRow );
  2555. managerRow.add( new UI.Text( '' ).setWidth( '90px' ) );
  2556. managerRow.add( new UI.Button( 'New' ).onClick( function () {
  2557. var material = new THREE[ materialClass.getValue() ]();
  2558. editor.execute( new SetMaterialCommand( currentObject, material, currentMaterialSlot ), 'New Material: ' + materialClass.getValue() );
  2559. update();
  2560. } ) );
  2561. managerRow.add( new UI.Button( 'Copy' ).setMarginLeft( '4px' ).onClick( function () {
  2562. copiedMaterial = currentObject.material;
  2563. if ( Array.isArray( copiedMaterial ) ) {
  2564. if ( copiedMaterial.length === 0 ) return;
  2565. copiedMaterial = copiedMaterial[ currentMaterialSlot ];
  2566. }
  2567. } ) );
  2568. managerRow.add( new UI.Button( 'Paste' ).setMarginLeft( '4px' ).onClick( function () {
  2569. if ( copiedMaterial === undefined ) return;
  2570. editor.execute( new SetMaterialCommand( currentObject, copiedMaterial, currentMaterialSlot ), 'Pasted Material: ' + materialClass.getValue() );
  2571. refreshUI();
  2572. update();
  2573. } ) );
  2574. container.add( managerRow );
  2575. // type
  2576. var materialClassRow = new UI.Row();
  2577. var materialClass = new UI.Select().setOptions( {
  2578. 'LineBasicMaterial': 'LineBasicMaterial',
  2579. 'LineDashedMaterial': 'LineDashedMaterial',
  2580. 'MeshBasicMaterial': 'MeshBasicMaterial',
  2581. 'MeshDepthMaterial': 'MeshDepthMaterial',
  2582. 'MeshNormalMaterial': 'MeshNormalMaterial',
  2583. 'MeshLambertMaterial': 'MeshLambertMaterial',
  2584. 'MeshPhongMaterial': 'MeshPhongMaterial',
  2585. 'MeshStandardMaterial': 'MeshStandardMaterial',
  2586. 'MeshPhysicalMaterial': 'MeshPhysicalMaterial',
  2587. 'ShaderMaterial': 'ShaderMaterial',
  2588. 'SpriteMaterial': 'SpriteMaterial'
  2589. } ).setWidth( '150px' ).setFontSize( '12px' ).onChange( update );
  2590. materialClassRow.add( new UI.Text( 'Type' ).setWidth( '90px' ) );
  2591. materialClassRow.add( materialClass );
  2592. container.add( materialClassRow );
  2593. // uuid
  2594. var materialUUIDRow = new UI.Row();
  2595. var materialUUID = new UI.Input().setWidth( '102px' ).setFontSize( '12px' ).setDisabled( true );
  2596. var materialUUIDRenew = new UI.Button( 'New' ).setMarginLeft( '7px' ).onClick( function () {
  2597. materialUUID.setValue( THREE.Math.generateUUID() );
  2598. update();
  2599. } );
  2600. materialUUIDRow.add( new UI.Text( 'UUID' ).setWidth( '90px' ) );
  2601. materialUUIDRow.add( materialUUID );
  2602. materialUUIDRow.add( materialUUIDRenew );
  2603. container.add( materialUUIDRow );
  2604. // name
  2605. var materialNameRow = new UI.Row();
  2606. var materialName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
  2607. editor.execute( new SetMaterialValueCommand( editor.selected, 'name', materialName.getValue(), currentMaterialSlot ) );
  2608. } );
  2609. materialNameRow.add( new UI.Text( 'Name' ).setWidth( '90px' ) );
  2610. materialNameRow.add( materialName );
  2611. container.add( materialNameRow );
  2612. // program
  2613. var materialProgramRow = new UI.Row();
  2614. materialProgramRow.add( new UI.Text( 'Program' ).setWidth( '90px' ) );
  2615. var materialProgramInfo = new UI.Button( 'Info' );
  2616. materialProgramInfo.setMarginLeft( '4px' );
  2617. materialProgramInfo.onClick( function () {
  2618. signals.editScript.dispatch( currentObject, 'programInfo' );
  2619. } );
  2620. materialProgramRow.add( materialProgramInfo );
  2621. var materialProgramVertex = new UI.Button( 'Vertex' );
  2622. materialProgramVertex.setMarginLeft( '4px' );
  2623. materialProgramVertex.onClick( function () {
  2624. signals.editScript.dispatch( currentObject, 'vertexShader' );
  2625. } );
  2626. materialProgramRow.add( materialProgramVertex );
  2627. var materialProgramFragment = new UI.Button( 'Fragment' );
  2628. materialProgramFragment.setMarginLeft( '4px' );
  2629. materialProgramFragment.onClick( function () {
  2630. signals.editScript.dispatch( currentObject, 'fragmentShader' );
  2631. } );
  2632. materialProgramRow.add( materialProgramFragment );
  2633. container.add( materialProgramRow );
  2634. // color
  2635. var materialColorRow = new UI.Row();
  2636. var materialColor = new UI.Color().onChange( update );
  2637. materialColorRow.add( new UI.Text( 'Color' ).setWidth( '90px' ) );
  2638. materialColorRow.add( materialColor );
  2639. container.add( materialColorRow );
  2640. // roughness
  2641. var materialRoughnessRow = new UI.Row();
  2642. var materialRoughness = new UI.Number( 0.5 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
  2643. materialRoughnessRow.add( new UI.Text( 'Roughness' ).setWidth( '90px' ) );
  2644. materialRoughnessRow.add( materialRoughness );
  2645. container.add( materialRoughnessRow );
  2646. // metalness
  2647. var materialMetalnessRow = new UI.Row();
  2648. var materialMetalness = new UI.Number( 0.5 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
  2649. materialMetalnessRow.add( new UI.Text( 'Metalness' ).setWidth( '90px' ) );
  2650. materialMetalnessRow.add( materialMetalness );
  2651. container.add( materialMetalnessRow );
  2652. // emissive
  2653. var materialEmissiveRow = new UI.Row();
  2654. var materialEmissive = new UI.Color().setHexValue( 0x000000 ).onChange( update );
  2655. materialEmissiveRow.add( new UI.Text( 'Emissive' ).setWidth( '90px' ) );
  2656. materialEmissiveRow.add( materialEmissive );
  2657. container.add( materialEmissiveRow );
  2658. // specular
  2659. var materialSpecularRow = new UI.Row();
  2660. var materialSpecular = new UI.Color().setHexValue( 0x111111 ).onChange( update );
  2661. materialSpecularRow.add( new UI.Text( 'Specular' ).setWidth( '90px' ) );
  2662. materialSpecularRow.add( materialSpecular );
  2663. container.add( materialSpecularRow );
  2664. // shininess
  2665. var materialShininessRow = new UI.Row();
  2666. var materialShininess = new UI.Number( 30 ).onChange( update );
  2667. materialShininessRow.add( new UI.Text( 'Shininess' ).setWidth( '90px' ) );
  2668. materialShininessRow.add( materialShininess );
  2669. container.add( materialShininessRow );
  2670. // clearCoat
  2671. var materialClearCoatRow = new UI.Row();
  2672. var materialClearCoat = new UI.Number( 1 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
  2673. materialClearCoatRow.add( new UI.Text( 'ClearCoat' ).setWidth( '90px' ) );
  2674. materialClearCoatRow.add( materialClearCoat );
  2675. container.add( materialClearCoatRow );
  2676. // clearCoatRoughness
  2677. var materialClearCoatRoughnessRow = new UI.Row();
  2678. var materialClearCoatRoughness = new UI.Number( 1 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
  2679. materialClearCoatRoughnessRow.add( new UI.Text( 'ClearCoat Roughness' ).setWidth( '90px' ) );
  2680. materialClearCoatRoughnessRow.add( materialClearCoatRoughness );
  2681. container.add( materialClearCoatRoughnessRow );
  2682. // vertex colors
  2683. var materialVertexColorsRow = new UI.Row();
  2684. var materialVertexColors = new UI.Select().setOptions( {
  2685. 0: 'No',
  2686. 1: 'Face',
  2687. 2: 'Vertex'
  2688. } ).onChange( update );
  2689. materialVertexColorsRow.add( new UI.Text( 'Vertex Colors' ).setWidth( '90px' ) );
  2690. materialVertexColorsRow.add( materialVertexColors );
  2691. container.add( materialVertexColorsRow );
  2692. // skinning
  2693. var materialSkinningRow = new UI.Row();
  2694. var materialSkinning = new UI.Checkbox( false ).onChange( update );
  2695. materialSkinningRow.add( new UI.Text( 'Skinning' ).setWidth( '90px' ) );
  2696. materialSkinningRow.add( materialSkinning );
  2697. container.add( materialSkinningRow );
  2698. // map
  2699. var materialMapRow = new UI.Row();
  2700. var materialMapEnabled = new UI.Checkbox( false ).onChange( update );
  2701. var materialMap = new UI.Texture().onChange( update );
  2702. materialMapRow.add( new UI.Text( 'Map' ).setWidth( '90px' ) );
  2703. materialMapRow.add( materialMapEnabled );
  2704. materialMapRow.add( materialMap );
  2705. container.add( materialMapRow );
  2706. // alpha map
  2707. var materialAlphaMapRow = new UI.Row();
  2708. var materialAlphaMapEnabled = new UI.Checkbox( false ).onChange( update );
  2709. var materialAlphaMap = new UI.Texture().onChange( update );
  2710. materialAlphaMapRow.add( new UI.Text( 'Alpha Map' ).setWidth( '90px' ) );
  2711. materialAlphaMapRow.add( materialAlphaMapEnabled );
  2712. materialAlphaMapRow.add( materialAlphaMap );
  2713. container.add( materialAlphaMapRow );
  2714. // bump map
  2715. var materialBumpMapRow = new UI.Row();
  2716. var materialBumpMapEnabled = new UI.Checkbox( false ).onChange( update );
  2717. var materialBumpMap = new UI.Texture().onChange( update );
  2718. var materialBumpScale = new UI.Number( 1 ).setWidth( '30px' ).onChange( update );
  2719. materialBumpMapRow.add( new UI.Text( 'Bump Map' ).setWidth( '90px' ) );
  2720. materialBumpMapRow.add( materialBumpMapEnabled );
  2721. materialBumpMapRow.add( materialBumpMap );
  2722. materialBumpMapRow.add( materialBumpScale );
  2723. container.add( materialBumpMapRow );
  2724. // normal map
  2725. var materialNormalMapRow = new UI.Row();
  2726. var materialNormalMapEnabled = new UI.Checkbox( false ).onChange( update );
  2727. var materialNormalMap = new UI.Texture().onChange( update );
  2728. materialNormalMapRow.add( new UI.Text( 'Normal Map' ).setWidth( '90px' ) );
  2729. materialNormalMapRow.add( materialNormalMapEnabled );
  2730. materialNormalMapRow.add( materialNormalMap );
  2731. container.add( materialNormalMapRow );
  2732. // displacement map
  2733. var materialDisplacementMapRow = new UI.Row();
  2734. var materialDisplacementMapEnabled = new UI.Checkbox( false ).onChange( update );
  2735. var materialDisplacementMap = new UI.Texture().onChange( update );
  2736. var materialDisplacementScale = new UI.Number( 1 ).setWidth( '30px' ).onChange( update );
  2737. materialDisplacementMapRow.add( new UI.Text( 'Displace Map' ).setWidth( '90px' ) );
  2738. materialDisplacementMapRow.add( materialDisplacementMapEnabled );
  2739. materialDisplacementMapRow.add( materialDisplacementMap );
  2740. materialDisplacementMapRow.add( materialDisplacementScale );
  2741. container.add( materialDisplacementMapRow );
  2742. // roughness map
  2743. var materialRoughnessMapRow = new UI.Row();
  2744. var materialRoughnessMapEnabled = new UI.Checkbox( false ).onChange( update );
  2745. var materialRoughnessMap = new UI.Texture().onChange( update );
  2746. materialRoughnessMapRow.add( new UI.Text( 'Rough. Map' ).setWidth( '90px' ) );
  2747. materialRoughnessMapRow.add( materialRoughnessMapEnabled );
  2748. materialRoughnessMapRow.add( materialRoughnessMap );
  2749. container.add( materialRoughnessMapRow );
  2750. // metalness map
  2751. var materialMetalnessMapRow = new UI.Row();
  2752. var materialMetalnessMapEnabled = new UI.Checkbox( false ).onChange( update );
  2753. var materialMetalnessMap = new UI.Texture().onChange( update );
  2754. materialMetalnessMapRow.add( new UI.Text( 'Metal. Map' ).setWidth( '90px' ) );
  2755. materialMetalnessMapRow.add( materialMetalnessMapEnabled );
  2756. materialMetalnessMapRow.add( materialMetalnessMap );
  2757. container.add( materialMetalnessMapRow );
  2758. // specular map
  2759. var materialSpecularMapRow = new UI.Row();
  2760. var materialSpecularMapEnabled = new UI.Checkbox( false ).onChange( update );
  2761. var materialSpecularMap = new UI.Texture().onChange( update );
  2762. materialSpecularMapRow.add( new UI.Text( 'Specular Map' ).setWidth( '90px' ) );
  2763. materialSpecularMapRow.add( materialSpecularMapEnabled );
  2764. materialSpecularMapRow.add( materialSpecularMap );
  2765. container.add( materialSpecularMapRow );
  2766. // env map
  2767. var materialEnvMapRow = new UI.Row();
  2768. var materialEnvMapEnabled = new UI.Checkbox( false ).onChange( update );
  2769. var materialEnvMap = new UI.Texture( THREE.SphericalReflectionMapping ).onChange( update );
  2770. var materialReflectivity = new UI.Number( 1 ).setWidth( '30px' ).onChange( update );
  2771. materialEnvMapRow.add( new UI.Text( 'Env Map' ).setWidth( '90px' ) );
  2772. materialEnvMapRow.add( materialEnvMapEnabled );
  2773. materialEnvMapRow.add( materialEnvMap );
  2774. materialEnvMapRow.add( materialReflectivity );
  2775. container.add( materialEnvMapRow );
  2776. // light map
  2777. var materialLightMapRow = new UI.Row();
  2778. var materialLightMapEnabled = new UI.Checkbox( false ).onChange( update );
  2779. var materialLightMap = new UI.Texture().onChange( update );
  2780. materialLightMapRow.add( new UI.Text( 'Light Map' ).setWidth( '90px' ) );
  2781. materialLightMapRow.add( materialLightMapEnabled );
  2782. materialLightMapRow.add( materialLightMap );
  2783. container.add( materialLightMapRow );
  2784. // ambient occlusion map
  2785. var materialAOMapRow = new UI.Row();
  2786. var materialAOMapEnabled = new UI.Checkbox( false ).onChange( update );
  2787. var materialAOMap = new UI.Texture().onChange( update );
  2788. var materialAOScale = new UI.Number( 1 ).setRange( 0, 1 ).setWidth( '30px' ).onChange( update );
  2789. materialAOMapRow.add( new UI.Text( 'AO Map' ).setWidth( '90px' ) );
  2790. materialAOMapRow.add( materialAOMapEnabled );
  2791. materialAOMapRow.add( materialAOMap );
  2792. materialAOMapRow.add( materialAOScale );
  2793. container.add( materialAOMapRow );
  2794. // emissive map
  2795. var materialEmissiveMapRow = new UI.Row();
  2796. var materialEmissiveMapEnabled = new UI.Checkbox( false ).onChange( update );
  2797. var materialEmissiveMap = new UI.Texture().onChange( update );
  2798. materialEmissiveMapRow.add( new UI.Text( 'Emissive Map' ).setWidth( '90px' ) );
  2799. materialEmissiveMapRow.add( materialEmissiveMapEnabled );
  2800. materialEmissiveMapRow.add( materialEmissiveMap );
  2801. container.add( materialEmissiveMapRow );
  2802. // side
  2803. var materialSideRow = new UI.Row();
  2804. var materialSide = new UI.Select().setOptions( {
  2805. 0: 'Front',
  2806. 1: 'Back',
  2807. 2: 'Double'
  2808. } ).setWidth( '150px' ).setFontSize( '12px' ).onChange( update );
  2809. materialSideRow.add( new UI.Text( 'Side' ).setWidth( '90px' ) );
  2810. materialSideRow.add( materialSide );
  2811. container.add( materialSideRow );
  2812. // shading
  2813. var materialShadingRow = new UI.Row();
  2814. var materialShading = new UI.Checkbox(false).setLeft( '100px' ).onChange( update );
  2815. materialShadingRow.add( new UI.Text( 'Flat Shaded' ).setWidth( '90px' ) );
  2816. materialShadingRow.add( materialShading );
  2817. container.add( materialShadingRow );
  2818. // blending
  2819. var materialBlendingRow = new UI.Row();
  2820. var materialBlending = new UI.Select().setOptions( {
  2821. 0: 'No',
  2822. 1: 'Normal',
  2823. 2: 'Additive',
  2824. 3: 'Subtractive',
  2825. 4: 'Multiply',
  2826. 5: 'Custom'
  2827. } ).setWidth( '150px' ).setFontSize( '12px' ).onChange( update );
  2828. materialBlendingRow.add( new UI.Text( 'Blending' ).setWidth( '90px' ) );
  2829. materialBlendingRow.add( materialBlending );
  2830. container.add( materialBlendingRow );
  2831. // opacity
  2832. var materialOpacityRow = new UI.Row();
  2833. var materialOpacity = new UI.Number( 1 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
  2834. materialOpacityRow.add( new UI.Text( 'Opacity' ).setWidth( '90px' ) );
  2835. materialOpacityRow.add( materialOpacity );
  2836. container.add( materialOpacityRow );
  2837. // transparent
  2838. var materialTransparentRow = new UI.Row();
  2839. var materialTransparent = new UI.Checkbox().setLeft( '100px' ).onChange( update );
  2840. materialTransparentRow.add( new UI.Text( 'Transparent' ).setWidth( '90px' ) );
  2841. materialTransparentRow.add( materialTransparent );
  2842. container.add( materialTransparentRow );
  2843. // alpha test
  2844. var materialAlphaTestRow = new UI.Row();
  2845. var materialAlphaTest = new UI.Number().setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
  2846. materialAlphaTestRow.add( new UI.Text( 'Alpha Test' ).setWidth( '90px' ) );
  2847. materialAlphaTestRow.add( materialAlphaTest );
  2848. container.add( materialAlphaTestRow );
  2849. // wireframe
  2850. var materialWireframeRow = new UI.Row();
  2851. var materialWireframe = new UI.Checkbox( false ).onChange( update );
  2852. var materialWireframeLinewidth = new UI.Number( 1 ).setWidth( '60px' ).setRange( 0, 100 ).onChange( update );
  2853. materialWireframeRow.add( new UI.Text( 'Wireframe' ).setWidth( '90px' ) );
  2854. materialWireframeRow.add( materialWireframe );
  2855. materialWireframeRow.add( materialWireframeLinewidth );
  2856. container.add( materialWireframeRow );
  2857. //
  2858. function update() {
  2859. var object = currentObject;
  2860. var geometry = object.geometry;
  2861. var previousSelectedSlot = currentMaterialSlot;
  2862. currentMaterialSlot = parseInt( materialSlotSelect.getValue() );
  2863. if ( currentMaterialSlot !== previousSelectedSlot ) refreshUI( true );
  2864. var material = editor.getObjectMaterial( currentObject, currentMaterialSlot );
  2865. var textureWarning = false;
  2866. var objectHasUvs = false;
  2867. if ( object instanceof THREE.Sprite ) objectHasUvs = true;
  2868. if ( geometry instanceof THREE.Geometry && geometry.faceVertexUvs[ 0 ].length > 0 ) objectHasUvs = true;
  2869. if ( geometry instanceof THREE.BufferGeometry && geometry.attributes.uv !== undefined ) objectHasUvs = true;
  2870. if ( material ) {
  2871. if ( material.uuid !== undefined && material.uuid !== materialUUID.getValue() ) {
  2872. editor.execute( new SetMaterialValueCommand( currentObject, 'uuid', materialUUID.getValue(), currentMaterialSlot ) );
  2873. }
  2874. if ( material instanceof THREE[ materialClass.getValue() ] === false ) {
  2875. material = new THREE[ materialClass.getValue() ]();
  2876. editor.execute( new SetMaterialCommand( currentObject, material, currentMaterialSlot ), 'New Material: ' + materialClass.getValue() );
  2877. // TODO Copy other references in the scene graph
  2878. // keeping name and UUID then.
  2879. // Also there should be means to create a unique
  2880. // copy for the current object explicitly and to
  2881. // attach the current material to other objects.
  2882. }
  2883. if ( material.color !== undefined && material.color.getHex() !== materialColor.getHexValue() ) {
  2884. editor.execute( new SetMaterialColorCommand( currentObject, 'color', materialColor.getHexValue(), currentMaterialSlot ) );
  2885. }
  2886. if ( material.roughness !== undefined && Math.abs( material.roughness - materialRoughness.getValue() ) >= 0.01 ) {
  2887. editor.execute( new SetMaterialValueCommand( currentObject, 'roughness', materialRoughness.getValue(), currentMaterialSlot ) );
  2888. }
  2889. if ( material.metalness !== undefined && Math.abs( material.metalness - materialMetalness.getValue() ) >= 0.01 ) {
  2890. editor.execute( new SetMaterialValueCommand( currentObject, 'metalness', materialMetalness.getValue(), currentMaterialSlot ) );
  2891. }
  2892. if ( material.emissive !== undefined && material.emissive.getHex() !== materialEmissive.getHexValue() ) {
  2893. editor.execute( new SetMaterialColorCommand( currentObject, 'emissive', materialEmissive.getHexValue(), currentMaterialSlot ) );
  2894. }
  2895. if ( material.specular !== undefined && material.specular.getHex() !== materialSpecular.getHexValue() ) {
  2896. editor.execute( new SetMaterialColorCommand( currentObject, 'specular', materialSpecular.getHexValue(), currentMaterialSlot ) );
  2897. }
  2898. if ( material.shininess !== undefined && Math.abs( material.shininess - materialShininess.getValue() ) >= 0.01 ) {
  2899. editor.execute( new SetMaterialValueCommand( currentObject, 'shininess', materialShininess.getValue(), currentMaterialSlot ) );
  2900. }
  2901. if ( material.clearCoat !== undefined && Math.abs( material.clearCoat - materialClearCoat.getValue() ) >= 0.01 ) {
  2902. editor.execute( new SetMaterialValueCommand( currentObject, 'clearCoat', materialClearCoat.getValue(), currentMaterialSlot ) );
  2903. }
  2904. if ( material.clearCoatRoughness !== undefined && Math.abs( material.clearCoatRoughness - materialClearCoatRoughness.getValue() ) >= 0.01 ) {
  2905. editor.execute( new SetMaterialValueCommand( currentObject, 'clearCoatRoughness', materialClearCoatRoughness.getValue(), currentMaterialSlot ) );
  2906. }
  2907. if ( material.vertexColors !== undefined ) {
  2908. var vertexColors = parseInt( materialVertexColors.getValue() );
  2909. if ( material.vertexColors !== vertexColors ) {
  2910. editor.execute( new SetMaterialValueCommand( currentObject, 'vertexColors', vertexColors, currentMaterialSlot ) );
  2911. }
  2912. }
  2913. if ( material.skinning !== undefined && material.skinning !== materialSkinning.getValue() ) {
  2914. editor.execute( new SetMaterialValueCommand( currentObject, 'skinning', materialSkinning.getValue(), currentMaterialSlot ) );
  2915. }
  2916. if ( material.map !== undefined ) {
  2917. var mapEnabled = materialMapEnabled.getValue() === true;
  2918. if ( objectHasUvs ) {
  2919. var map = mapEnabled ? materialMap.getValue() : null;
  2920. if ( material.map !== map ) {
  2921. editor.execute( new SetMaterialMapCommand( currentObject, 'map', map, currentMaterialSlot ) );
  2922. }
  2923. } else {
  2924. if ( mapEnabled ) textureWarning = true;
  2925. }
  2926. }
  2927. if ( material.alphaMap !== undefined ) {
  2928. var mapEnabled = materialAlphaMapEnabled.getValue() === true;
  2929. if ( objectHasUvs ) {
  2930. var alphaMap = mapEnabled ? materialAlphaMap.getValue() : null;
  2931. if ( material.alphaMap !== alphaMap ) {
  2932. editor.execute( new SetMaterialMapCommand( currentObject, 'alphaMap', alphaMap, currentMaterialSlot ) );
  2933. }
  2934. } else {
  2935. if ( mapEnabled ) textureWarning = true;
  2936. }
  2937. }
  2938. if ( material.bumpMap !== undefined ) {
  2939. var bumpMapEnabled = materialBumpMapEnabled.getValue() === true;
  2940. if ( objectHasUvs ) {
  2941. var bumpMap = bumpMapEnabled ? materialBumpMap.getValue() : null;
  2942. if ( material.bumpMap !== bumpMap ) {
  2943. editor.execute( new SetMaterialMapCommand( currentObject, 'bumpMap', bumpMap, currentMaterialSlot ) );
  2944. }
  2945. if ( material.bumpScale !== materialBumpScale.getValue() ) {
  2946. editor.execute( new SetMaterialValueCommand( currentObject, 'bumpScale', materialBumpScale.getValue(), currentMaterialSlot ) );
  2947. }
  2948. } else {
  2949. if ( bumpMapEnabled ) textureWarning = true;
  2950. }
  2951. }
  2952. if ( material.normalMap !== undefined ) {
  2953. var normalMapEnabled = materialNormalMapEnabled.getValue() === true;
  2954. if ( objectHasUvs ) {
  2955. var normalMap = normalMapEnabled ? materialNormalMap.getValue() : null;
  2956. if ( material.normalMap !== normalMap ) {
  2957. editor.execute( new SetMaterialMapCommand( currentObject, 'normalMap', normalMap, currentMaterialSlot ) );
  2958. }
  2959. } else {
  2960. if ( normalMapEnabled ) textureWarning = true;
  2961. }
  2962. }
  2963. if ( material.displacementMap !== undefined ) {
  2964. var displacementMapEnabled = materialDisplacementMapEnabled.getValue() === true;
  2965. if ( objectHasUvs ) {
  2966. var displacementMap = displacementMapEnabled ? materialDisplacementMap.getValue() : null;
  2967. if ( material.displacementMap !== displacementMap ) {
  2968. editor.execute( new SetMaterialMapCommand( currentObject, 'displacementMap', displacementMap, currentMaterialSlot ) );
  2969. }
  2970. if ( material.displacementScale !== materialDisplacementScale.getValue() ) {
  2971. editor.execute( new SetMaterialValueCommand( currentObject, 'displacementScale', materialDisplacementScale.getValue(), currentMaterialSlot ) );
  2972. }
  2973. } else {
  2974. if ( displacementMapEnabled ) textureWarning = true;
  2975. }
  2976. }
  2977. if ( material.roughnessMap !== undefined ) {
  2978. var roughnessMapEnabled = materialRoughnessMapEnabled.getValue() === true;
  2979. if ( objectHasUvs ) {
  2980. var roughnessMap = roughnessMapEnabled ? materialRoughnessMap.getValue() : null;
  2981. if ( material.roughnessMap !== roughnessMap ) {
  2982. editor.execute( new SetMaterialMapCommand( currentObject, 'roughnessMap', roughnessMap, currentMaterialSlot ) );
  2983. }
  2984. } else {
  2985. if ( roughnessMapEnabled ) textureWarning = true;
  2986. }
  2987. }
  2988. if ( material.metalnessMap !== undefined ) {
  2989. var metalnessMapEnabled = materialMetalnessMapEnabled.getValue() === true;
  2990. if ( objectHasUvs ) {
  2991. var metalnessMap = metalnessMapEnabled ? materialMetalnessMap.getValue() : null;
  2992. if ( material.metalnessMap !== metalnessMap ) {
  2993. editor.execute( new SetMaterialMapCommand( currentObject, 'metalnessMap', metalnessMap, currentMaterialSlot ) );
  2994. }
  2995. } else {
  2996. if ( metalnessMapEnabled ) textureWarning = true;
  2997. }
  2998. }
  2999. if ( material.specularMap !== undefined ) {
  3000. var specularMapEnabled = materialSpecularMapEnabled.getValue() === true;
  3001. if ( objectHasUvs ) {
  3002. var specularMap = specularMapEnabled ? materialSpecularMap.getValue() : null;
  3003. if ( material.specularMap !== specularMap ) {
  3004. editor.execute( new SetMaterialMapCommand( currentObject, 'specularMap', specularMap, currentMaterialSlot ) );
  3005. }
  3006. } else {
  3007. if ( specularMapEnabled ) textureWarning = true;
  3008. }
  3009. }
  3010. if ( material.envMap !== undefined ) {
  3011. var envMapEnabled = materialEnvMapEnabled.getValue() === true;
  3012. var envMap = envMapEnabled ? materialEnvMap.getValue() : null;
  3013. if ( material.envMap !== envMap ) {
  3014. editor.execute( new SetMaterialMapCommand( currentObject, 'envMap', envMap, currentMaterialSlot ) );
  3015. }
  3016. }
  3017. if ( material.reflectivity !== undefined ) {
  3018. var reflectivity = materialReflectivity.getValue();
  3019. if ( material.reflectivity !== reflectivity ) {
  3020. editor.execute( new SetMaterialValueCommand( currentObject, 'reflectivity', reflectivity, currentMaterialSlot ) );
  3021. }
  3022. }
  3023. if ( material.lightMap !== undefined ) {
  3024. var lightMapEnabled = materialLightMapEnabled.getValue() === true;
  3025. if ( objectHasUvs ) {
  3026. var lightMap = lightMapEnabled ? materialLightMap.getValue() : null;
  3027. if ( material.lightMap !== lightMap ) {
  3028. editor.execute( new SetMaterialMapCommand( currentObject, 'lightMap', lightMap, currentMaterialSlot ) );
  3029. }
  3030. } else {
  3031. if ( lightMapEnabled ) textureWarning = true;
  3032. }
  3033. }
  3034. if ( material.aoMap !== undefined ) {
  3035. var aoMapEnabled = materialAOMapEnabled.getValue() === true;
  3036. if ( objectHasUvs ) {
  3037. var aoMap = aoMapEnabled ? materialAOMap.getValue() : null;
  3038. if ( material.aoMap !== aoMap ) {
  3039. editor.execute( new SetMaterialMapCommand( currentObject, 'aoMap', aoMap, currentMaterialSlot ) );
  3040. }
  3041. if ( material.aoMapIntensity !== materialAOScale.getValue() ) {
  3042. editor.execute( new SetMaterialValueCommand( currentObject, 'aoMapIntensity', materialAOScale.getValue(), currentMaterialSlot ) );
  3043. }
  3044. } else {
  3045. if ( aoMapEnabled ) textureWarning = true;
  3046. }
  3047. }
  3048. if ( material.emissiveMap !== undefined ) {
  3049. var emissiveMapEnabled = materialEmissiveMapEnabled.getValue() === true;
  3050. if ( objectHasUvs ) {
  3051. var emissiveMap = emissiveMapEnabled ? materialEmissiveMap.getValue() : null;
  3052. if ( material.emissiveMap !== emissiveMap ) {
  3053. editor.execute( new SetMaterialMapCommand( currentObject, 'emissiveMap', emissiveMap, currentMaterialSlot ) );
  3054. }
  3055. } else {
  3056. if ( emissiveMapEnabled ) textureWarning = true;
  3057. }
  3058. }
  3059. if ( material.side !== undefined ) {
  3060. var side = parseInt( materialSide.getValue() );
  3061. if ( material.side !== side ) {
  3062. editor.execute( new SetMaterialValueCommand( currentObject, 'side', side, currentMaterialSlot ) );
  3063. }
  3064. }
  3065. if ( material.flatShading !== undefined ) {
  3066. var flatShading = materialShading.getValue();
  3067. if ( material.flatShading != flatShading ) {
  3068. editor.execute( new SetMaterialValueCommand( currentObject, 'flatShading', flatShading, currentMaterialSlot ) );
  3069. }
  3070. }
  3071. if ( material.blending !== undefined ) {
  3072. var blending = parseInt( materialBlending.getValue() );
  3073. if ( material.blending !== blending ) {
  3074. editor.execute( new SetMaterialValueCommand( currentObject, 'blending', blending, currentMaterialSlot ) );
  3075. }
  3076. }
  3077. if ( material.opacity !== undefined && Math.abs( material.opacity - materialOpacity.getValue() ) >= 0.01 ) {
  3078. editor.execute( new SetMaterialValueCommand( currentObject, 'opacity', materialOpacity.getValue(), currentMaterialSlot ) );
  3079. }
  3080. if ( material.transparent !== undefined && material.transparent !== materialTransparent.getValue() ) {
  3081. editor.execute( new SetMaterialValueCommand( currentObject, 'transparent', materialTransparent.getValue(), currentMaterialSlot ) );
  3082. }
  3083. if ( material.alphaTest !== undefined && Math.abs( material.alphaTest - materialAlphaTest.getValue() ) >= 0.01 ) {
  3084. editor.execute( new SetMaterialValueCommand( currentObject, 'alphaTest', materialAlphaTest.getValue(), currentMaterialSlot ) );
  3085. }
  3086. if ( material.wireframe !== undefined && material.wireframe !== materialWireframe.getValue() ) {
  3087. editor.execute( new SetMaterialValueCommand( currentObject, 'wireframe', materialWireframe.getValue(), currentMaterialSlot) );
  3088. }
  3089. if ( material.wireframeLinewidth !== undefined && Math.abs( material.wireframeLinewidth - materialWireframeLinewidth.getValue() ) >= 0.01 ) {
  3090. editor.execute( new SetMaterialValueCommand( currentObject, 'wireframeLinewidth', materialWireframeLinewidth.getValue(), currentMaterialSlot ) );
  3091. }
  3092. refreshUI();
  3093. }
  3094. if ( textureWarning ) {
  3095. console.warn( "Can't set texture, model doesn't have texture coordinates" );
  3096. }
  3097. }
  3098. //
  3099. function setRowVisibility() {
  3100. var properties = {
  3101. 'name': materialNameRow,
  3102. 'color': materialColorRow,
  3103. 'roughness': materialRoughnessRow,
  3104. 'metalness': materialMetalnessRow,
  3105. 'emissive': materialEmissiveRow,
  3106. 'specular': materialSpecularRow,
  3107. 'shininess': materialShininessRow,
  3108. 'clearCoat': materialClearCoatRow,
  3109. 'clearCoatRoughness': materialClearCoatRoughnessRow,
  3110. 'vertexShader': materialProgramRow,
  3111. 'vertexColors': materialVertexColorsRow,
  3112. 'skinning': materialSkinningRow,
  3113. 'map': materialMapRow,
  3114. 'alphaMap': materialAlphaMapRow,
  3115. 'bumpMap': materialBumpMapRow,
  3116. 'normalMap': materialNormalMapRow,
  3117. 'displacementMap': materialDisplacementMapRow,
  3118. 'roughnessMap': materialRoughnessMapRow,
  3119. 'metalnessMap': materialMetalnessMapRow,
  3120. 'specularMap': materialSpecularMapRow,
  3121. 'envMap': materialEnvMapRow,
  3122. 'lightMap': materialLightMapRow,
  3123. 'aoMap': materialAOMapRow,
  3124. 'emissiveMap': materialEmissiveMapRow,
  3125. 'side': materialSideRow,
  3126. 'flatShading': materialShadingRow,
  3127. 'blending': materialBlendingRow,
  3128. 'opacity': materialOpacityRow,
  3129. 'transparent': materialTransparentRow,
  3130. 'alphaTest': materialAlphaTestRow,
  3131. 'wireframe': materialWireframeRow
  3132. };
  3133. var material = currentObject.material;
  3134. if ( Array.isArray( material ) ) {
  3135. materialSlotRow.setDisplay( '' );
  3136. if ( material.length === 0 ) return;
  3137. material = material[ currentMaterialSlot ];
  3138. } else {
  3139. materialSlotRow.setDisplay( 'none' );
  3140. }
  3141. for ( var property in properties ) {
  3142. properties[ property ].setDisplay( material[ property ] !== undefined ? '' : 'none' );
  3143. }
  3144. }
  3145. function refreshUI( resetTextureSelectors ) {
  3146. if ( ! currentObject ) return;
  3147. var material = currentObject.material;
  3148. if ( Array.isArray( material ) ) {
  3149. var slotOptions = {};
  3150. currentMaterialSlot = Math.max( 0, Math.min( material.length, currentMaterialSlot ) );
  3151. for ( var i = 0; i < material.length; i ++ ) {
  3152. slotOptions[ i ] = String( i + 1 ) + ': ' + material[ i ].name;
  3153. }
  3154. materialSlotSelect.setOptions( slotOptions ).setValue( currentMaterialSlot );
  3155. }
  3156. material = editor.getObjectMaterial( currentObject, currentMaterialSlot );
  3157. if ( material.uuid !== undefined ) {
  3158. materialUUID.setValue( material.uuid );
  3159. }
  3160. if ( material.name !== undefined ) {
  3161. materialName.setValue( material.name );
  3162. }
  3163. materialClass.setValue( material.type );
  3164. if ( material.color !== undefined ) {
  3165. materialColor.setHexValue( material.color.getHexString() );
  3166. }
  3167. if ( material.roughness !== undefined ) {
  3168. materialRoughness.setValue( material.roughness );
  3169. }
  3170. if ( material.metalness !== undefined ) {
  3171. materialMetalness.setValue( material.metalness );
  3172. }
  3173. if ( material.emissive !== undefined ) {
  3174. materialEmissive.setHexValue( material.emissive.getHexString() );
  3175. }
  3176. if ( material.specular !== undefined ) {
  3177. materialSpecular.setHexValue( material.specular.getHexString() );
  3178. }
  3179. if ( material.shininess !== undefined ) {
  3180. materialShininess.setValue( material.shininess );
  3181. }
  3182. if ( material.clearCoat !== undefined ) {
  3183. materialClearCoat.setValue( material.clearCoat );
  3184. }
  3185. if ( material.clearCoatRoughness !== undefined ) {
  3186. materialClearCoatRoughness.setValue( material.clearCoatRoughness );
  3187. }
  3188. if ( material.vertexColors !== undefined ) {
  3189. materialVertexColors.setValue( material.vertexColors );
  3190. }
  3191. if ( material.skinning !== undefined ) {
  3192. materialSkinning.setValue( material.skinning );
  3193. }
  3194. if ( material.map !== undefined ) {
  3195. materialMapEnabled.setValue( material.map !== null );
  3196. if ( material.map !== null || resetTextureSelectors ) {
  3197. materialMap.setValue( material.map );
  3198. }
  3199. }
  3200. if ( material.alphaMap !== undefined ) {
  3201. materialAlphaMapEnabled.setValue( material.alphaMap !== null );
  3202. if ( material.alphaMap !== null || resetTextureSelectors ) {
  3203. materialAlphaMap.setValue( material.alphaMap );
  3204. }
  3205. }
  3206. if ( material.bumpMap !== undefined ) {
  3207. materialBumpMapEnabled.setValue( material.bumpMap !== null );
  3208. if ( material.bumpMap !== null || resetTextureSelectors ) {
  3209. materialBumpMap.setValue( material.bumpMap );
  3210. }
  3211. materialBumpScale.setValue( material.bumpScale );
  3212. }
  3213. if ( material.normalMap !== undefined ) {
  3214. materialNormalMapEnabled.setValue( material.normalMap !== null );
  3215. if ( material.normalMap !== null || resetTextureSelectors ) {
  3216. materialNormalMap.setValue( material.normalMap );
  3217. }
  3218. }
  3219. if ( material.displacementMap !== undefined ) {
  3220. materialDisplacementMapEnabled.setValue( material.displacementMap !== null );
  3221. if ( material.displacementMap !== null || resetTextureSelectors ) {
  3222. materialDisplacementMap.setValue( material.displacementMap );
  3223. }
  3224. materialDisplacementScale.setValue( material.displacementScale );
  3225. }
  3226. if ( material.roughnessMap !== undefined ) {
  3227. materialRoughnessMapEnabled.setValue( material.roughnessMap !== null );
  3228. if ( material.roughnessMap !== null || resetTextureSelectors ) {
  3229. materialRoughnessMap.setValue( material.roughnessMap );
  3230. }
  3231. }
  3232. if ( material.metalnessMap !== undefined ) {
  3233. materialMetalnessMapEnabled.setValue( material.metalnessMap !== null );
  3234. if ( material.metalnessMap !== null || resetTextureSelectors ) {
  3235. materialMetalnessMap.setValue( material.metalnessMap );
  3236. }
  3237. }
  3238. if ( material.specularMap !== undefined ) {
  3239. materialSpecularMapEnabled.setValue( material.specularMap !== null );
  3240. if ( material.specularMap !== null || resetTextureSelectors ) {
  3241. materialSpecularMap.setValue( material.specularMap );
  3242. }
  3243. }
  3244. if ( material.envMap !== undefined ) {
  3245. materialEnvMapEnabled.setValue( material.envMap !== null );
  3246. if ( material.envMap !== null || resetTextureSelectors ) {
  3247. materialEnvMap.setValue( material.envMap );
  3248. }
  3249. }
  3250. if ( material.reflectivity !== undefined ) {
  3251. materialReflectivity.setValue( material.reflectivity );
  3252. }
  3253. if ( material.lightMap !== undefined ) {
  3254. materialLightMapEnabled.setValue( material.lightMap !== null );
  3255. if ( material.lightMap !== null || resetTextureSelectors ) {
  3256. materialLightMap.setValue( material.lightMap );
  3257. }
  3258. }
  3259. if ( material.aoMap !== undefined ) {
  3260. materialAOMapEnabled.setValue( material.aoMap !== null );
  3261. if ( material.aoMap !== null || resetTextureSelectors ) {
  3262. materialAOMap.setValue( material.aoMap );
  3263. }
  3264. materialAOScale.setValue( material.aoMapIntensity );
  3265. }
  3266. if ( material.emissiveMap !== undefined ) {
  3267. materialEmissiveMapEnabled.setValue( material.emissiveMap !== null );
  3268. if ( material.emissiveMap !== null || resetTextureSelectors ) {
  3269. materialEmissiveMap.setValue( material.emissiveMap );
  3270. }
  3271. }
  3272. if ( material.side !== undefined ) {
  3273. materialSide.setValue( material.side );
  3274. }
  3275. if ( material.flatShading !== undefined ) {
  3276. materialShading.setValue( material.flatShading );
  3277. }
  3278. if ( material.blending !== undefined ) {
  3279. materialBlending.setValue( material.blending );
  3280. }
  3281. if ( material.opacity !== undefined ) {
  3282. materialOpacity.setValue( material.opacity );
  3283. }
  3284. if ( material.transparent !== undefined ) {
  3285. materialTransparent.setValue( material.transparent );
  3286. }
  3287. if ( material.alphaTest !== undefined ) {
  3288. materialAlphaTest.setValue( material.alphaTest );
  3289. }
  3290. if ( material.wireframe !== undefined ) {
  3291. materialWireframe.setValue( material.wireframe );
  3292. }
  3293. if ( material.wireframeLinewidth !== undefined ) {
  3294. materialWireframeLinewidth.setValue( material.wireframeLinewidth );
  3295. }
  3296. setRowVisibility();
  3297. }
  3298. // events
  3299. signals.objectSelected.add( function ( object ) {
  3300. var hasMaterial = false;
  3301. if ( object && object.material ) {
  3302. hasMaterial = true;
  3303. if ( Array.isArray( object.material ) && object.material.length === 0 ) {
  3304. hasMaterial = false;
  3305. }
  3306. }
  3307. if ( hasMaterial ) {
  3308. var objectChanged = object !== currentObject;
  3309. currentObject = object;
  3310. refreshUI( objectChanged );
  3311. container.setDisplay( '' );
  3312. } else {
  3313. currentObject = null;
  3314. container.setDisplay( 'none' );
  3315. }
  3316. } );
  3317. signals.materialChanged.add( function () {
  3318. refreshUI();
  3319. } );
  3320. return container;
  3321. };
  3322. /**
  3323. * @author TristanVALCKE / https://github.com/Itee
  3324. */
  3325. /* global QUnit */
  3326. QUnit.module( 'Editor', () => {
  3327. QUnit.module.todo( 'Sidebar.Material', () => {
  3328. QUnit.test( 'write me !', ( assert ) => {
  3329. assert.ok( false, "everything's gonna be alright" );
  3330. } );
  3331. } );
  3332. } );
  3333. /**
  3334. * @author mrdoob / http://mrdoob.com/
  3335. */
  3336. Sidebar.Object = function ( editor ) {
  3337. var signals = editor.signals;
  3338. var container = new UI.Panel();
  3339. container.setBorderTop( '0' );
  3340. container.setPaddingTop( '20px' );
  3341. container.setDisplay( 'none' );
  3342. // Actions
  3343. var objectActions = new UI.Select().setPosition( 'absolute' ).setRight( '8px' ).setFontSize( '11px' );
  3344. objectActions.setOptions( {
  3345. 'Actions': 'Actions',
  3346. 'Reset Position': 'Reset Position',
  3347. 'Reset Rotation': 'Reset Rotation',
  3348. 'Reset Scale': 'Reset Scale'
  3349. } );
  3350. objectActions.onClick( function ( event ) {
  3351. event.stopPropagation(); // Avoid panel collapsing
  3352. } );
  3353. objectActions.onChange( function ( event ) {
  3354. var object = editor.selected;
  3355. switch ( this.getValue() ) {
  3356. case 'Reset Position':
  3357. editor.execute( new SetPositionCommand( object, new THREE.Vector3( 0, 0, 0 ) ) );
  3358. break;
  3359. case 'Reset Rotation':
  3360. editor.execute( new SetRotationCommand( object, new THREE.Euler( 0, 0, 0 ) ) );
  3361. break;
  3362. case 'Reset Scale':
  3363. editor.execute( new SetScaleCommand( object, new THREE.Vector3( 1, 1, 1 ) ) );
  3364. break;
  3365. }
  3366. this.setValue( 'Actions' );
  3367. } );
  3368. // container.addStatic( objectActions );
  3369. // type
  3370. var objectTypeRow = new UI.Row();
  3371. var objectType = new UI.Text();
  3372. objectTypeRow.add( new UI.Text( 'Type' ).setWidth( '90px' ) );
  3373. objectTypeRow.add( objectType );
  3374. container.add( objectTypeRow );
  3375. // uuid
  3376. var objectUUIDRow = new UI.Row();
  3377. var objectUUID = new UI.Input().setWidth( '102px' ).setFontSize( '12px' ).setDisabled( true );
  3378. var objectUUIDRenew = new UI.Button( 'New' ).setMarginLeft( '7px' ).onClick( function () {
  3379. objectUUID.setValue( THREE.Math.generateUUID() );
  3380. editor.execute( new SetUuidCommand( editor.selected, objectUUID.getValue() ) );
  3381. } );
  3382. objectUUIDRow.add( new UI.Text( 'UUID' ).setWidth( '90px' ) );
  3383. objectUUIDRow.add( objectUUID );
  3384. objectUUIDRow.add( objectUUIDRenew );
  3385. container.add( objectUUIDRow );
  3386. // name
  3387. var objectNameRow = new UI.Row();
  3388. var objectName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
  3389. editor.execute( new SetValueCommand( editor.selected, 'name', objectName.getValue() ) );
  3390. } );
  3391. objectNameRow.add( new UI.Text( 'Name' ).setWidth( '90px' ) );
  3392. objectNameRow.add( objectName );
  3393. container.add( objectNameRow );
  3394. // position
  3395. var objectPositionRow = new UI.Row();
  3396. var objectPositionX = new UI.Number().setWidth( '50px' ).onChange( update );
  3397. var objectPositionY = new UI.Number().setWidth( '50px' ).onChange( update );
  3398. var objectPositionZ = new UI.Number().setWidth( '50px' ).onChange( update );
  3399. objectPositionRow.add( new UI.Text( 'Position' ).setWidth( '90px' ) );
  3400. objectPositionRow.add( objectPositionX, objectPositionY, objectPositionZ );
  3401. container.add( objectPositionRow );
  3402. // rotation
  3403. var objectRotationRow = new UI.Row();
  3404. var objectRotationX = new UI.Number().setStep( 10 ).setUnit( '°' ).setWidth( '50px' ).onChange( update );
  3405. var objectRotationY = new UI.Number().setStep( 10 ).setUnit( '°' ).setWidth( '50px' ).onChange( update );
  3406. var objectRotationZ = new UI.Number().setStep( 10 ).setUnit( '°' ).setWidth( '50px' ).onChange( update );
  3407. objectRotationRow.add( new UI.Text( 'Rotation' ).setWidth( '90px' ) );
  3408. objectRotationRow.add( objectRotationX, objectRotationY, objectRotationZ );
  3409. container.add( objectRotationRow );
  3410. // scale
  3411. var objectScaleRow = new UI.Row();
  3412. var objectScaleLock = new UI.Checkbox( true ).setPosition( 'absolute' ).setLeft( '75px' );
  3413. var objectScaleX = new UI.Number( 1 ).setRange( 0.01, Infinity ).setWidth( '50px' ).onChange( updateScaleX );
  3414. var objectScaleY = new UI.Number( 1 ).setRange( 0.01, Infinity ).setWidth( '50px' ).onChange( updateScaleY );
  3415. var objectScaleZ = new UI.Number( 1 ).setRange( 0.01, Infinity ).setWidth( '50px' ).onChange( updateScaleZ );
  3416. objectScaleRow.add( new UI.Text( 'Scale' ).setWidth( '90px' ) );
  3417. objectScaleRow.add( objectScaleLock );
  3418. objectScaleRow.add( objectScaleX, objectScaleY, objectScaleZ );
  3419. container.add( objectScaleRow );
  3420. // fov
  3421. var objectFovRow = new UI.Row();
  3422. var objectFov = new UI.Number().onChange( update );
  3423. objectFovRow.add( new UI.Text( 'Fov' ).setWidth( '90px' ) );
  3424. objectFovRow.add( objectFov );
  3425. container.add( objectFovRow );
  3426. // near
  3427. var objectNearRow = new UI.Row();
  3428. var objectNear = new UI.Number().onChange( update );
  3429. objectNearRow.add( new UI.Text( 'Near' ).setWidth( '90px' ) );
  3430. objectNearRow.add( objectNear );
  3431. container.add( objectNearRow );
  3432. // far
  3433. var objectFarRow = new UI.Row();
  3434. var objectFar = new UI.Number().onChange( update );
  3435. objectFarRow.add( new UI.Text( 'Far' ).setWidth( '90px' ) );
  3436. objectFarRow.add( objectFar );
  3437. container.add( objectFarRow );
  3438. // intensity
  3439. var objectIntensityRow = new UI.Row();
  3440. var objectIntensity = new UI.Number().setRange( 0, Infinity ).onChange( update );
  3441. objectIntensityRow.add( new UI.Text( 'Intensity' ).setWidth( '90px' ) );
  3442. objectIntensityRow.add( objectIntensity );
  3443. container.add( objectIntensityRow );
  3444. // color
  3445. var objectColorRow = new UI.Row();
  3446. var objectColor = new UI.Color().onChange( update );
  3447. objectColorRow.add( new UI.Text( 'Color' ).setWidth( '90px' ) );
  3448. objectColorRow.add( objectColor );
  3449. container.add( objectColorRow );
  3450. // ground color
  3451. var objectGroundColorRow = new UI.Row();
  3452. var objectGroundColor = new UI.Color().onChange( update );
  3453. objectGroundColorRow.add( new UI.Text( 'Ground color' ).setWidth( '90px' ) );
  3454. objectGroundColorRow.add( objectGroundColor );
  3455. container.add( objectGroundColorRow );
  3456. // distance
  3457. var objectDistanceRow = new UI.Row();
  3458. var objectDistance = new UI.Number().setRange( 0, Infinity ).onChange( update );
  3459. objectDistanceRow.add( new UI.Text( 'Distance' ).setWidth( '90px' ) );
  3460. objectDistanceRow.add( objectDistance );
  3461. container.add( objectDistanceRow );
  3462. // angle
  3463. var objectAngleRow = new UI.Row();
  3464. var objectAngle = new UI.Number().setPrecision( 3 ).setRange( 0, Math.PI / 2 ).onChange( update );
  3465. objectAngleRow.add( new UI.Text( 'Angle' ).setWidth( '90px' ) );
  3466. objectAngleRow.add( objectAngle );
  3467. container.add( objectAngleRow );
  3468. // penumbra
  3469. var objectPenumbraRow = new UI.Row();
  3470. var objectPenumbra = new UI.Number().setRange( 0, 1 ).onChange( update );
  3471. objectPenumbraRow.add( new UI.Text( 'Penumbra' ).setWidth( '90px' ) );
  3472. objectPenumbraRow.add( objectPenumbra );
  3473. container.add( objectPenumbraRow );
  3474. // decay
  3475. var objectDecayRow = new UI.Row();
  3476. var objectDecay = new UI.Number().setRange( 0, Infinity ).onChange( update );
  3477. objectDecayRow.add( new UI.Text( 'Decay' ).setWidth( '90px' ) );
  3478. objectDecayRow.add( objectDecay );
  3479. container.add( objectDecayRow );
  3480. // shadow
  3481. var objectShadowRow = new UI.Row();
  3482. objectShadowRow.add( new UI.Text( 'Shadow' ).setWidth( '90px' ) );
  3483. var objectCastShadow = new UI.THREE.Boolean( false, 'cast' ).onChange( update );
  3484. objectShadowRow.add( objectCastShadow );
  3485. var objectReceiveShadow = new UI.THREE.Boolean( false, 'receive' ).onChange( update );
  3486. objectShadowRow.add( objectReceiveShadow );
  3487. var objectShadowRadius = new UI.Number( 1 ).onChange( update );
  3488. objectShadowRow.add( objectShadowRadius );
  3489. container.add( objectShadowRow );
  3490. // visible
  3491. var objectVisibleRow = new UI.Row();
  3492. var objectVisible = new UI.Checkbox().onChange( update );
  3493. objectVisibleRow.add( new UI.Text( 'Visible' ).setWidth( '90px' ) );
  3494. objectVisibleRow.add( objectVisible );
  3495. container.add( objectVisibleRow );
  3496. // user data
  3497. var timeout;
  3498. var objectUserDataRow = new UI.Row();
  3499. var objectUserData = new UI.TextArea().setWidth( '150px' ).setHeight( '40px' ).setFontSize( '12px' ).onChange( update );
  3500. objectUserData.onKeyUp( function () {
  3501. try {
  3502. JSON.parse( objectUserData.getValue() );
  3503. objectUserData.dom.classList.add( 'success' );
  3504. objectUserData.dom.classList.remove( 'fail' );
  3505. } catch ( error ) {
  3506. objectUserData.dom.classList.remove( 'success' );
  3507. objectUserData.dom.classList.add( 'fail' );
  3508. }
  3509. } );
  3510. objectUserDataRow.add( new UI.Text( 'User data' ).setWidth( '90px' ) );
  3511. objectUserDataRow.add( objectUserData );
  3512. container.add( objectUserDataRow );
  3513. //
  3514. function updateScaleX() {
  3515. var object = editor.selected;
  3516. if ( objectScaleLock.getValue() === true ) {
  3517. var scale = objectScaleX.getValue() / object.scale.x;
  3518. objectScaleY.setValue( objectScaleY.getValue() * scale );
  3519. objectScaleZ.setValue( objectScaleZ.getValue() * scale );
  3520. }
  3521. update();
  3522. }
  3523. function updateScaleY() {
  3524. var object = editor.selected;
  3525. if ( objectScaleLock.getValue() === true ) {
  3526. var scale = objectScaleY.getValue() / object.scale.y;
  3527. objectScaleX.setValue( objectScaleX.getValue() * scale );
  3528. objectScaleZ.setValue( objectScaleZ.getValue() * scale );
  3529. }
  3530. update();
  3531. }
  3532. function updateScaleZ() {
  3533. var object = editor.selected;
  3534. if ( objectScaleLock.getValue() === true ) {
  3535. var scale = objectScaleZ.getValue() / object.scale.z;
  3536. objectScaleX.setValue( objectScaleX.getValue() * scale );
  3537. objectScaleY.setValue( objectScaleY.getValue() * scale );
  3538. }
  3539. update();
  3540. }
  3541. function update() {
  3542. var object = editor.selected;
  3543. if ( object !== null ) {
  3544. var newPosition = new THREE.Vector3( objectPositionX.getValue(), objectPositionY.getValue(), objectPositionZ.getValue() );
  3545. if ( object.position.distanceTo( newPosition ) >= 0.01 ) {
  3546. editor.execute( new SetPositionCommand( object, newPosition ) );
  3547. }
  3548. var newRotation = new THREE.Euler( objectRotationX.getValue() * THREE.Math.DEG2RAD, objectRotationY.getValue() * THREE.Math.DEG2RAD, objectRotationZ.getValue() * THREE.Math.DEG2RAD );
  3549. if ( object.rotation.toVector3().distanceTo( newRotation.toVector3() ) >= 0.01 ) {
  3550. editor.execute( new SetRotationCommand( object, newRotation ) );
  3551. }
  3552. var newScale = new THREE.Vector3( objectScaleX.getValue(), objectScaleY.getValue(), objectScaleZ.getValue() );
  3553. if ( object.scale.distanceTo( newScale ) >= 0.01 ) {
  3554. editor.execute( new SetScaleCommand( object, newScale ) );
  3555. }
  3556. if ( object.fov !== undefined && Math.abs( object.fov - objectFov.getValue() ) >= 0.01 ) {
  3557. editor.execute( new SetValueCommand( object, 'fov', objectFov.getValue() ) );
  3558. object.updateProjectionMatrix();
  3559. }
  3560. if ( object.near !== undefined && Math.abs( object.near - objectNear.getValue() ) >= 0.01 ) {
  3561. editor.execute( new SetValueCommand( object, 'near', objectNear.getValue() ) );
  3562. }
  3563. if ( object.far !== undefined && Math.abs( object.far - objectFar.getValue() ) >= 0.01 ) {
  3564. editor.execute( new SetValueCommand( object, 'far', objectFar.getValue() ) );
  3565. }
  3566. if ( object.intensity !== undefined && Math.abs( object.intensity - objectIntensity.getValue() ) >= 0.01 ) {
  3567. editor.execute( new SetValueCommand( object, 'intensity', objectIntensity.getValue() ) );
  3568. }
  3569. if ( object.color !== undefined && object.color.getHex() !== objectColor.getHexValue() ) {
  3570. editor.execute( new SetColorCommand( object, 'color', objectColor.getHexValue() ) );
  3571. }
  3572. if ( object.groundColor !== undefined && object.groundColor.getHex() !== objectGroundColor.getHexValue() ) {
  3573. editor.execute( new SetColorCommand( object, 'groundColor', objectGroundColor.getHexValue() ) );
  3574. }
  3575. if ( object.distance !== undefined && Math.abs( object.distance - objectDistance.getValue() ) >= 0.01 ) {
  3576. editor.execute( new SetValueCommand( object, 'distance', objectDistance.getValue() ) );
  3577. }
  3578. if ( object.angle !== undefined && Math.abs( object.angle - objectAngle.getValue() ) >= 0.01 ) {
  3579. editor.execute( new SetValueCommand( object, 'angle', objectAngle.getValue() ) );
  3580. }
  3581. if ( object.penumbra !== undefined && Math.abs( object.penumbra - objectPenumbra.getValue() ) >= 0.01 ) {
  3582. editor.execute( new SetValueCommand( object, 'penumbra', objectPenumbra.getValue() ) );
  3583. }
  3584. if ( object.decay !== undefined && Math.abs( object.decay - objectDecay.getValue() ) >= 0.01 ) {
  3585. editor.execute( new SetValueCommand( object, 'decay', objectDecay.getValue() ) );
  3586. }
  3587. if ( object.visible !== objectVisible.getValue() ) {
  3588. editor.execute( new SetValueCommand( object, 'visible', objectVisible.getValue() ) );
  3589. }
  3590. if ( object.castShadow !== undefined && object.castShadow !== objectCastShadow.getValue() ) {
  3591. editor.execute( new SetValueCommand( object, 'castShadow', objectCastShadow.getValue() ) );
  3592. }
  3593. if ( object.receiveShadow !== undefined && object.receiveShadow !== objectReceiveShadow.getValue() ) {
  3594. editor.execute( new SetValueCommand( object, 'receiveShadow', objectReceiveShadow.getValue() ) );
  3595. object.material.needsUpdate = true;
  3596. }
  3597. if ( object.shadow !== undefined ) {
  3598. if ( object.shadow.radius !== objectShadowRadius.getValue() ) {
  3599. editor.execute( new SetValueCommand( object.shadow, 'radius', objectShadowRadius.getValue() ) );
  3600. }
  3601. }
  3602. try {
  3603. var userData = JSON.parse( objectUserData.getValue() );
  3604. if ( JSON.stringify( object.userData ) != JSON.stringify( userData ) ) {
  3605. editor.execute( new SetValueCommand( object, 'userData', userData ) );
  3606. }
  3607. } catch ( exception ) {
  3608. console.warn( exception );
  3609. }
  3610. }
  3611. }
  3612. function updateRows( object ) {
  3613. var properties = {
  3614. 'fov': objectFovRow,
  3615. 'near': objectNearRow,
  3616. 'far': objectFarRow,
  3617. 'intensity': objectIntensityRow,
  3618. 'color': objectColorRow,
  3619. 'groundColor': objectGroundColorRow,
  3620. 'distance' : objectDistanceRow,
  3621. 'angle' : objectAngleRow,
  3622. 'penumbra' : objectPenumbraRow,
  3623. 'decay' : objectDecayRow,
  3624. 'castShadow' : objectShadowRow,
  3625. 'receiveShadow' : objectReceiveShadow,
  3626. 'shadow': objectShadowRadius
  3627. };
  3628. for ( var property in properties ) {
  3629. properties[ property ].setDisplay( object[ property ] !== undefined ? '' : 'none' );
  3630. }
  3631. }
  3632. function updateTransformRows( object ) {
  3633. if ( object instanceof THREE.Light ||
  3634. ( object instanceof THREE.Object3D && object.userData.targetInverse ) ) {
  3635. objectRotationRow.setDisplay( 'none' );
  3636. objectScaleRow.setDisplay( 'none' );
  3637. } else {
  3638. objectRotationRow.setDisplay( '' );
  3639. objectScaleRow.setDisplay( '' );
  3640. }
  3641. }
  3642. // events
  3643. signals.objectSelected.add( function ( object ) {
  3644. if ( object !== null ) {
  3645. container.setDisplay( 'block' );
  3646. updateRows( object );
  3647. updateUI( object );
  3648. } else {
  3649. container.setDisplay( 'none' );
  3650. }
  3651. } );
  3652. signals.objectChanged.add( function ( object ) {
  3653. if ( object !== editor.selected ) return;
  3654. updateUI( object );
  3655. } );
  3656. signals.refreshSidebarObject3D.add( function ( object ) {
  3657. if ( object !== editor.selected ) return;
  3658. updateUI( object );
  3659. } );
  3660. function updateUI( object ) {
  3661. objectType.setValue( object.type );
  3662. objectUUID.setValue( object.uuid );
  3663. objectName.setValue( object.name );
  3664. objectPositionX.setValue( object.position.x );
  3665. objectPositionY.setValue( object.position.y );
  3666. objectPositionZ.setValue( object.position.z );
  3667. objectRotationX.setValue( object.rotation.x * THREE.Math.RAD2DEG );
  3668. objectRotationY.setValue( object.rotation.y * THREE.Math.RAD2DEG );
  3669. objectRotationZ.setValue( object.rotation.z * THREE.Math.RAD2DEG );
  3670. objectScaleX.setValue( object.scale.x );
  3671. objectScaleY.setValue( object.scale.y );
  3672. objectScaleZ.setValue( object.scale.z );
  3673. if ( object.fov !== undefined ) {
  3674. objectFov.setValue( object.fov );
  3675. }
  3676. if ( object.near !== undefined ) {
  3677. objectNear.setValue( object.near );
  3678. }
  3679. if ( object.far !== undefined ) {
  3680. objectFar.setValue( object.far );
  3681. }
  3682. if ( object.intensity !== undefined ) {
  3683. objectIntensity.setValue( object.intensity );
  3684. }
  3685. if ( object.color !== undefined ) {
  3686. objectColor.setHexValue( object.color.getHexString() );
  3687. }
  3688. if ( object.groundColor !== undefined ) {
  3689. objectGroundColor.setHexValue( object.groundColor.getHexString() );
  3690. }
  3691. if ( object.distance !== undefined ) {
  3692. objectDistance.setValue( object.distance );
  3693. }
  3694. if ( object.angle !== undefined ) {
  3695. objectAngle.setValue( object.angle );
  3696. }
  3697. if ( object.penumbra !== undefined ) {
  3698. objectPenumbra.setValue( object.penumbra );
  3699. }
  3700. if ( object.decay !== undefined ) {
  3701. objectDecay.setValue( object.decay );
  3702. }
  3703. if ( object.castShadow !== undefined ) {
  3704. objectCastShadow.setValue( object.castShadow );
  3705. }
  3706. if ( object.receiveShadow !== undefined ) {
  3707. objectReceiveShadow.setValue( object.receiveShadow );
  3708. }
  3709. if ( object.shadow !== undefined ) {
  3710. objectShadowRadius.setValue( object.shadow.radius );
  3711. }
  3712. objectVisible.setValue( object.visible );
  3713. try {
  3714. objectUserData.setValue( JSON.stringify( object.userData, null, ' ' ) );
  3715. } catch ( error ) {
  3716. console.log( error );
  3717. }
  3718. objectUserData.setBorderColor( 'transparent' );
  3719. objectUserData.setBackgroundColor( '' );
  3720. updateTransformRows( object );
  3721. }
  3722. return container;
  3723. };
  3724. /**
  3725. * @author TristanVALCKE / https://github.com/Itee
  3726. */
  3727. /* global QUnit */
  3728. QUnit.module( 'Editor', () => {
  3729. QUnit.module.todo( 'Sidebar.Object', () => {
  3730. QUnit.test( 'write me !', ( assert ) => {
  3731. assert.ok( false, "everything's gonna be alright" );
  3732. } );
  3733. } );
  3734. } );
  3735. /**
  3736. * @author mrdoob / http://mrdoob.com/
  3737. */
  3738. Sidebar.Project = function ( editor ) {
  3739. var config = editor.config;
  3740. var signals = editor.signals;
  3741. var rendererTypes = {
  3742. 'WebGLRenderer': THREE.WebGLRenderer,
  3743. 'CanvasRenderer': THREE.CanvasRenderer,
  3744. 'SVGRenderer': THREE.SVGRenderer,
  3745. 'SoftwareRenderer': THREE.SoftwareRenderer,
  3746. 'RaytracingRenderer': THREE.RaytracingRenderer
  3747. };
  3748. var container = new UI.Panel();
  3749. container.setBorderTop( '0' );
  3750. container.setPaddingTop( '20px' );
  3751. // class
  3752. var options = {};
  3753. for ( var key in rendererTypes ) {
  3754. if ( key.indexOf( 'WebGL' ) >= 0 && System.support.webgl === false ) continue;
  3755. options[ key ] = key;
  3756. }
  3757. var rendererTypeRow = new UI.Row();
  3758. var rendererType = new UI.Select().setOptions( options ).setWidth( '150px' ).onChange( function () {
  3759. var value = this.getValue();
  3760. config.setKey( 'project/renderer', value );
  3761. updateRenderer();
  3762. } );
  3763. rendererTypeRow.add( new UI.Text( 'Renderer' ).setWidth( '90px' ) );
  3764. rendererTypeRow.add( rendererType );
  3765. container.add( rendererTypeRow );
  3766. if ( config.getKey( 'project/renderer' ) !== undefined ) {
  3767. rendererType.setValue( config.getKey( 'project/renderer' ) );
  3768. }
  3769. // antialiasing
  3770. var rendererPropertiesRow = new UI.Row().setMarginLeft( '90px' );
  3771. var rendererAntialias = new UI.THREE.Boolean( config.getKey( 'project/renderer/antialias' ), 'antialias' ).onChange( function () {
  3772. config.setKey( 'project/renderer/antialias', this.getValue() );
  3773. updateRenderer();
  3774. } );
  3775. rendererPropertiesRow.add( rendererAntialias );
  3776. // shadow
  3777. var rendererShadows = new UI.THREE.Boolean( config.getKey( 'project/renderer/shadows' ), 'shadows' ).onChange( function () {
  3778. config.setKey( 'project/renderer/shadows', this.getValue() );
  3779. updateRenderer();
  3780. } );
  3781. rendererPropertiesRow.add( rendererShadows );
  3782. rendererPropertiesRow.add( new UI.Break() );
  3783. // gamma input
  3784. var rendererGammaInput = new UI.THREE.Boolean( config.getKey( 'project/renderer/gammaInput' ), 'γ input' ).onChange( function () {
  3785. config.setKey( 'project/renderer/gammaInput', this.getValue() );
  3786. updateRenderer();
  3787. } );
  3788. rendererPropertiesRow.add( rendererGammaInput );
  3789. // gamma output
  3790. var rendererGammaOutput = new UI.THREE.Boolean( config.getKey( 'project/renderer/gammaOutput' ), 'γ output' ).onChange( function () {
  3791. config.setKey( 'project/renderer/gammaOutput', this.getValue() );
  3792. updateRenderer();
  3793. } );
  3794. rendererPropertiesRow.add( rendererGammaOutput );
  3795. container.add( rendererPropertiesRow );
  3796. // VR
  3797. var vrRow = new UI.Row();
  3798. var vr = new UI.Checkbox( config.getKey( 'project/vr' ) ).setLeft( '100px' ).onChange( function () {
  3799. config.setKey( 'project/vr', this.getValue() );
  3800. // updateRenderer();
  3801. } );
  3802. vrRow.add( new UI.Text( 'VR' ).setWidth( '90px' ) );
  3803. vrRow.add( vr );
  3804. container.add( vrRow );
  3805. //
  3806. function updateRenderer() {
  3807. createRenderer( rendererType.getValue(), rendererAntialias.getValue(), rendererShadows.getValue(), rendererGammaInput.getValue(), rendererGammaOutput.getValue() );
  3808. }
  3809. function createRenderer( type, antialias, shadows, gammaIn, gammaOut ) {
  3810. if ( type === 'WebGLRenderer' && System.support.webgl === false ) {
  3811. type = 'CanvasRenderer';
  3812. }
  3813. rendererPropertiesRow.setDisplay( type === 'WebGLRenderer' ? '' : 'none' );
  3814. var renderer = new rendererTypes[ type ]( { antialias: antialias} );
  3815. renderer.gammaInput = gammaIn;
  3816. renderer.gammaOutput = gammaOut;
  3817. if ( shadows && renderer.shadowMap ) {
  3818. renderer.shadowMap.enabled = true;
  3819. // renderer.shadowMap.type = THREE.PCFSoftShadowMap;
  3820. }
  3821. signals.rendererChanged.dispatch( renderer );
  3822. }
  3823. 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' ) );
  3824. return container;
  3825. };
  3826. /**
  3827. * @author TristanVALCKE / https://github.com/Itee
  3828. */
  3829. /* global QUnit */
  3830. QUnit.module( 'Editor', () => {
  3831. QUnit.module.todo( 'Sidebar.Project', () => {
  3832. QUnit.test( 'write me !', ( assert ) => {
  3833. assert.ok( false, "everything's gonna be alright" );
  3834. } );
  3835. } );
  3836. } );
  3837. /**
  3838. * @author mrdoob / http://mrdoob.com/
  3839. */
  3840. Sidebar.Properties = function ( editor ) {
  3841. var signals = editor.signals;
  3842. var container = new UI.Span();
  3843. var objectTab = new UI.Text( 'OBJECT' ).onClick( onClick );
  3844. var geometryTab = new UI.Text( 'GEOMETRY' ).onClick( onClick );
  3845. var materialTab = new UI.Text( 'MATERIAL' ).onClick( onClick );
  3846. var tabs = new UI.Div();
  3847. tabs.setId( 'tabs' );
  3848. tabs.add( objectTab, geometryTab, materialTab );
  3849. container.add( tabs );
  3850. function onClick( event ) {
  3851. select( event.target.textContent );
  3852. }
  3853. //
  3854. var object = new UI.Span().add(
  3855. new Sidebar.Object( editor )
  3856. );
  3857. container.add( object );
  3858. var geometry = new UI.Span().add(
  3859. new Sidebar.Geometry( editor )
  3860. );
  3861. container.add( geometry );
  3862. var material = new UI.Span().add(
  3863. new Sidebar.Material( editor )
  3864. );
  3865. container.add( material );
  3866. //
  3867. function select( section ) {
  3868. objectTab.setClass( '' );
  3869. geometryTab.setClass( '' );
  3870. materialTab.setClass( '' );
  3871. object.setDisplay( 'none' );
  3872. geometry.setDisplay( 'none' );
  3873. material.setDisplay( 'none' );
  3874. switch ( section ) {
  3875. case 'OBJECT':
  3876. objectTab.setClass( 'selected' );
  3877. object.setDisplay( '' );
  3878. break;
  3879. case 'GEOMETRY':
  3880. geometryTab.setClass( 'selected' );
  3881. geometry.setDisplay( '' );
  3882. break;
  3883. case 'MATERIAL':
  3884. materialTab.setClass( 'selected' );
  3885. material.setDisplay( '' );
  3886. break;
  3887. }
  3888. }
  3889. select( 'OBJECT' );
  3890. return container;
  3891. };
  3892. /**
  3893. * @author TristanVALCKE / https://github.com/Itee
  3894. */
  3895. /* global QUnit */
  3896. QUnit.module( 'Editor', () => {
  3897. QUnit.module.todo( 'Sidebar.Properties', () => {
  3898. QUnit.test( 'write me !', ( assert ) => {
  3899. assert.ok( false, "everything's gonna be alright" );
  3900. } );
  3901. } );
  3902. } );
  3903. /**
  3904. * @author mrdoob / http://mrdoob.com/
  3905. */
  3906. Sidebar.Scene = function ( editor ) {
  3907. var signals = editor.signals;
  3908. var container = new UI.Panel();
  3909. container.setBorderTop( '0' );
  3910. container.setPaddingTop( '20px' );
  3911. // outliner
  3912. function buildOption( object, draggable ) {
  3913. var option = document.createElement( 'div' );
  3914. option.draggable = draggable;
  3915. option.innerHTML = buildHTML( object );
  3916. option.value = object.id;
  3917. return option;
  3918. }
  3919. function getMaterialName( material ) {
  3920. if ( Array.isArray( material ) ) {
  3921. var array = [];
  3922. for ( var i = 0; i < material.length; i ++ ) {
  3923. array.push( material[ i ].name );
  3924. }
  3925. return array.join( ',' );
  3926. }
  3927. return material.name;
  3928. }
  3929. function buildHTML( object ) {
  3930. var html = '<span class="type ' + object.type + '"></span> ' + object.name;
  3931. if ( object instanceof THREE.Mesh ) {
  3932. var geometry = object.geometry;
  3933. var material = object.material;
  3934. html += ' <span class="type ' + geometry.type + '"></span> ' + geometry.name;
  3935. html += ' <span class="type ' + material.type + '"></span> ' + getMaterialName( material );
  3936. }
  3937. html += getScript( object.uuid );
  3938. return html;
  3939. }
  3940. function getScript( uuid ) {
  3941. if ( editor.scripts[ uuid ] !== undefined ) {
  3942. return ' <span class="type Script"></span>';
  3943. }
  3944. return '';
  3945. }
  3946. var ignoreObjectSelectedSignal = false;
  3947. var outliner = new UI.Outliner( editor );
  3948. outliner.setId( 'outliner' );
  3949. outliner.onChange( function () {
  3950. ignoreObjectSelectedSignal = true;
  3951. editor.selectById( parseInt( outliner.getValue() ) );
  3952. ignoreObjectSelectedSignal = false;
  3953. } );
  3954. outliner.onDblClick( function () {
  3955. editor.focusById( parseInt( outliner.getValue() ) );
  3956. } );
  3957. container.add( outliner );
  3958. container.add( new UI.Break() );
  3959. // background
  3960. function onBackgroundChanged() {
  3961. signals.sceneBackgroundChanged.dispatch( backgroundColor.getHexValue() );
  3962. }
  3963. var backgroundRow = new UI.Row();
  3964. var backgroundColor = new UI.Color().setValue( '#aaaaaa' ).onChange( onBackgroundChanged );
  3965. backgroundRow.add( new UI.Text( 'Background' ).setWidth( '90px' ) );
  3966. backgroundRow.add( backgroundColor );
  3967. container.add( backgroundRow );
  3968. // fog
  3969. function onFogChanged() {
  3970. signals.sceneFogChanged.dispatch(
  3971. fogType.getValue(),
  3972. fogColor.getHexValue(),
  3973. fogNear.getValue(),
  3974. fogFar.getValue(),
  3975. fogDensity.getValue()
  3976. );
  3977. }
  3978. var fogTypeRow = new UI.Row();
  3979. var fogType = new UI.Select().setOptions( {
  3980. 'None': 'None',
  3981. 'Fog': 'Linear',
  3982. 'FogExp2': 'Exponential'
  3983. } ).setWidth( '150px' );
  3984. fogType.onChange( function () {
  3985. onFogChanged();
  3986. refreshFogUI();
  3987. } );
  3988. fogTypeRow.add( new UI.Text( 'Fog' ).setWidth( '90px' ) );
  3989. fogTypeRow.add( fogType );
  3990. container.add( fogTypeRow );
  3991. // fog color
  3992. var fogPropertiesRow = new UI.Row();
  3993. fogPropertiesRow.setDisplay( 'none' );
  3994. fogPropertiesRow.setMarginLeft( '90px' );
  3995. container.add( fogPropertiesRow );
  3996. var fogColor = new UI.Color().setValue( '#aaaaaa' );
  3997. fogColor.onChange( onFogChanged );
  3998. fogPropertiesRow.add( fogColor );
  3999. // fog near
  4000. var fogNear = new UI.Number( 0.1 ).setWidth( '40px' ).setRange( 0, Infinity ).onChange( onFogChanged );
  4001. fogPropertiesRow.add( fogNear );
  4002. // fog far
  4003. var fogFar = new UI.Number( 50 ).setWidth( '40px' ).setRange( 0, Infinity ).onChange( onFogChanged );
  4004. fogPropertiesRow.add( fogFar );
  4005. // fog density
  4006. var fogDensity = new UI.Number( 0.05 ).setWidth( '40px' ).setRange( 0, 0.1 ).setPrecision( 3 ).onChange( onFogChanged );
  4007. fogPropertiesRow.add( fogDensity );
  4008. //
  4009. function refreshUI() {
  4010. var camera = editor.camera;
  4011. var scene = editor.scene;
  4012. var options = [];
  4013. options.push( buildOption( camera, false ) );
  4014. options.push( buildOption( scene, false ) );
  4015. ( function addObjects( objects, pad ) {
  4016. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4017. var object = objects[ i ];
  4018. var option = buildOption( object, true );
  4019. option.style.paddingLeft = ( pad * 10 ) + 'px';
  4020. options.push( option );
  4021. addObjects( object.children, pad + 1 );
  4022. }
  4023. } )( scene.children, 1 );
  4024. outliner.setOptions( options );
  4025. if ( editor.selected !== null ) {
  4026. outliner.setValue( editor.selected.id );
  4027. }
  4028. if ( scene.background ) {
  4029. backgroundColor.setHexValue( scene.background.getHex() );
  4030. }
  4031. if ( scene.fog ) {
  4032. fogColor.setHexValue( scene.fog.color.getHex() );
  4033. if ( scene.fog instanceof THREE.Fog ) {
  4034. fogType.setValue( "Fog" );
  4035. fogNear.setValue( scene.fog.near );
  4036. fogFar.setValue( scene.fog.far );
  4037. } else if ( scene.fog instanceof THREE.FogExp2 ) {
  4038. fogType.setValue( "FogExp2" );
  4039. fogDensity.setValue( scene.fog.density );
  4040. }
  4041. } else {
  4042. fogType.setValue( "None" );
  4043. }
  4044. refreshFogUI();
  4045. }
  4046. function refreshFogUI() {
  4047. var type = fogType.getValue();
  4048. fogPropertiesRow.setDisplay( type === 'None' ? 'none' : '' );
  4049. fogNear.setDisplay( type === 'Fog' ? '' : 'none' );
  4050. fogFar.setDisplay( type === 'Fog' ? '' : 'none' );
  4051. fogDensity.setDisplay( type === 'FogExp2' ? '' : 'none' );
  4052. }
  4053. refreshUI();
  4054. // events
  4055. signals.editorCleared.add( refreshUI );
  4056. signals.sceneGraphChanged.add( refreshUI );
  4057. signals.objectChanged.add( function ( object ) {
  4058. var options = outliner.options;
  4059. for ( var i = 0; i < options.length; i ++ ) {
  4060. var option = options[ i ];
  4061. if ( option.value === object.id ) {
  4062. option.innerHTML = buildHTML( object );
  4063. return;
  4064. }
  4065. }
  4066. } );
  4067. signals.objectSelected.add( function ( object ) {
  4068. if ( ignoreObjectSelectedSignal === true ) return;
  4069. outliner.setValue( object !== null ? object.id : null );
  4070. } );
  4071. return container;
  4072. };
  4073. /**
  4074. * @author TristanVALCKE / https://github.com/Itee
  4075. */
  4076. /* global QUnit */
  4077. QUnit.module( 'Editor', () => {
  4078. QUnit.module.todo( 'Sidebar.Scene', () => {
  4079. QUnit.test( 'write me !', ( assert ) => {
  4080. assert.ok( false, "everything's gonna be alright" );
  4081. } );
  4082. } );
  4083. } );
  4084. /**
  4085. * @author mrdoob / http://mrdoob.com/
  4086. */
  4087. Sidebar.Script = function ( editor ) {
  4088. var signals = editor.signals;
  4089. var container = new UI.Panel();
  4090. container.setDisplay( 'none' );
  4091. container.add( new UI.Text( 'Script' ).setTextTransform( 'uppercase' ) );
  4092. container.add( new UI.Break() );
  4093. container.add( new UI.Break() );
  4094. //
  4095. var scriptsContainer = new UI.Row();
  4096. container.add( scriptsContainer );
  4097. var newScript = new UI.Button( 'New' );
  4098. newScript.onClick( function () {
  4099. var script = { name: '', source: 'function update( event ) {}' };
  4100. editor.execute( new AddScriptCommand( editor.selected, script ) );
  4101. } );
  4102. container.add( newScript );
  4103. /*
  4104. var loadScript = new UI.Button( 'Load' );
  4105. loadScript.setMarginLeft( '4px' );
  4106. container.add( loadScript );
  4107. */
  4108. //
  4109. function update() {
  4110. scriptsContainer.clear();
  4111. scriptsContainer.setDisplay( 'none' );
  4112. var object = editor.selected;
  4113. if ( object === null ) {
  4114. return;
  4115. }
  4116. var scripts = editor.scripts[ object.uuid ];
  4117. if ( scripts !== undefined ) {
  4118. scriptsContainer.setDisplay( 'block' );
  4119. for ( var i = 0; i < scripts.length; i ++ ) {
  4120. ( function ( object, script ) {
  4121. var name = new UI.Input( script.name ).setWidth( '130px' ).setFontSize( '12px' );
  4122. name.onChange( function () {
  4123. editor.execute( new SetScriptValueCommand( editor.selected, script, 'name', this.getValue() ) );
  4124. } );
  4125. scriptsContainer.add( name );
  4126. var edit = new UI.Button( 'Edit' );
  4127. edit.setMarginLeft( '4px' );
  4128. edit.onClick( function () {
  4129. signals.editScript.dispatch( object, script );
  4130. } );
  4131. scriptsContainer.add( edit );
  4132. var remove = new UI.Button( 'Remove' );
  4133. remove.setMarginLeft( '4px' );
  4134. remove.onClick( function () {
  4135. if ( confirm( 'Are you sure?' ) ) {
  4136. editor.execute( new RemoveScriptCommand( editor.selected, script ) );
  4137. }
  4138. } );
  4139. scriptsContainer.add( remove );
  4140. scriptsContainer.add( new UI.Break() );
  4141. } )( object, scripts[ i ] );
  4142. }
  4143. }
  4144. }
  4145. // signals
  4146. signals.objectSelected.add( function ( object ) {
  4147. if ( object !== null && editor.camera !== object ) {
  4148. container.setDisplay( 'block' );
  4149. update();
  4150. } else {
  4151. container.setDisplay( 'none' );
  4152. }
  4153. } );
  4154. signals.scriptAdded.add( update );
  4155. signals.scriptRemoved.add( update );
  4156. signals.scriptChanged.add( update );
  4157. return container;
  4158. };
  4159. /**
  4160. * @author TristanVALCKE / https://github.com/Itee
  4161. */
  4162. /* global QUnit */
  4163. QUnit.module( 'Editor', () => {
  4164. QUnit.module.todo( 'Sidebar.Script', () => {
  4165. QUnit.test( 'write me !', ( assert ) => {
  4166. assert.ok( false, "everything's gonna be alright" );
  4167. } );
  4168. } );
  4169. } );
  4170. /**
  4171. * @author mrdoob / http://mrdoob.com/
  4172. */
  4173. Sidebar.Settings = function ( editor ) {
  4174. var config = editor.config;
  4175. var signals = editor.signals;
  4176. var container = new UI.Panel();
  4177. container.setBorderTop( '0' );
  4178. container.setPaddingTop( '20px' );
  4179. // class
  4180. var options = {
  4181. 'css/light.css': 'light',
  4182. 'css/dark.css': 'dark'
  4183. };
  4184. var themeRow = new UI.Row();
  4185. var theme = new UI.Select().setWidth( '150px' );
  4186. theme.setOptions( options );
  4187. if ( config.getKey( 'theme' ) !== undefined ) {
  4188. theme.setValue( config.getKey( 'theme' ) );
  4189. }
  4190. theme.onChange( function () {
  4191. var value = this.getValue();
  4192. editor.setTheme( value );
  4193. editor.config.setKey( 'theme', value );
  4194. } );
  4195. themeRow.add( new UI.Text( 'Theme' ).setWidth( '90px' ) );
  4196. themeRow.add( theme );
  4197. container.add( themeRow );
  4198. return container;
  4199. };
  4200. /**
  4201. * @author TristanVALCKE / https://github.com/Itee
  4202. */
  4203. /* global QUnit */
  4204. QUnit.module( 'Editor', () => {
  4205. QUnit.module.todo( 'Sidebar.Settings', () => {
  4206. QUnit.test( 'write me !', ( assert ) => {
  4207. assert.ok( false, "everything's gonna be alright" );
  4208. } );
  4209. } );
  4210. } );
  4211. /**
  4212. * @author mrdoob / http://mrdoob.com/
  4213. */
  4214. /**
  4215. * @author TristanVALCKE / https://github.com/Itee
  4216. */
  4217. /* global QUnit */
  4218. QUnit.module( 'Editor', () => {
  4219. QUnit.module.todo( 'Storage', () => {
  4220. QUnit.test( 'write me !', ( assert ) => {
  4221. assert.ok( false, "everything's gonna be alright" );
  4222. } );
  4223. } );
  4224. } );
  4225. /**
  4226. * @author mrdoob / http://mrdoob.com/
  4227. */
  4228. /**
  4229. * @author TristanVALCKE / https://github.com/Itee
  4230. */
  4231. /* global QUnit */
  4232. QUnit.module( 'Editor', () => {
  4233. QUnit.module.todo( 'Toolbar', () => {
  4234. QUnit.test( 'write me !', ( assert ) => {
  4235. assert.ok( false, "everything's gonna be alright" );
  4236. } );
  4237. } );
  4238. } );
  4239. /**
  4240. * @author mrdoob / http://mrdoob.com/
  4241. */
  4242. /**
  4243. * @author TristanVALCKE / https://github.com/Itee
  4244. */
  4245. /* global QUnit */
  4246. QUnit.module( 'Editor', () => {
  4247. QUnit.module.todo( 'Viewport', () => {
  4248. QUnit.test( 'write me !', ( assert ) => {
  4249. assert.ok( false, "everything's gonna be alright" );
  4250. } );
  4251. } );
  4252. } );
  4253. /**
  4254. * @author mrdoob / http://mrdoob.com/
  4255. */
  4256. Viewport.Info = function ( editor ) {
  4257. var signals = editor.signals;
  4258. var container = new UI.Panel();
  4259. container.setId( 'info' );
  4260. container.setPosition( 'absolute' );
  4261. container.setLeft( '10px' );
  4262. container.setBottom( '10px' );
  4263. container.setFontSize( '12px' );
  4264. container.setColor( '#fff' );
  4265. var objectsText = new UI.Text( '0' ).setMarginLeft( '6px' );
  4266. var verticesText = new UI.Text( '0' ).setMarginLeft( '6px' );
  4267. var trianglesText = new UI.Text( '0' ).setMarginLeft( '6px' );
  4268. container.add( new UI.Text( 'objects' ), objectsText, new UI.Break() );
  4269. container.add( new UI.Text( 'vertices' ), verticesText, new UI.Break() );
  4270. container.add( new UI.Text( 'triangles' ), trianglesText, new UI.Break() );
  4271. signals.objectAdded.add( update );
  4272. signals.objectRemoved.add( update );
  4273. signals.geometryChanged.add( update );
  4274. //
  4275. function update() {
  4276. var scene = editor.scene;
  4277. var objects = 0, vertices = 0, triangles = 0;
  4278. for ( var i = 0, l = scene.children.length; i < l; i ++ ) {
  4279. var object = scene.children[ i ];
  4280. object.traverseVisible( function ( object ) {
  4281. objects ++;
  4282. if ( object instanceof THREE.Mesh ) {
  4283. var geometry = object.geometry;
  4284. if ( geometry instanceof THREE.Geometry ) {
  4285. vertices += geometry.vertices.length;
  4286. triangles += geometry.faces.length;
  4287. } else if ( geometry instanceof THREE.BufferGeometry ) {
  4288. if ( geometry.index !== null ) {
  4289. vertices += geometry.index.count * 3;
  4290. triangles += geometry.index.count;
  4291. } else {
  4292. vertices += geometry.attributes.position.count;
  4293. triangles += geometry.attributes.position.count / 3;
  4294. }
  4295. }
  4296. }
  4297. } );
  4298. }
  4299. objectsText.setValue( objects.format() );
  4300. verticesText.setValue( vertices.format() );
  4301. trianglesText.setValue( triangles.format() );
  4302. }
  4303. return container;
  4304. };
  4305. /**
  4306. * @author TristanVALCKE / https://github.com/Itee
  4307. */
  4308. /* global QUnit */
  4309. QUnit.module( 'Editor', () => {
  4310. QUnit.module.todo( 'Viewport.Info', () => {
  4311. QUnit.test( 'write me !', ( assert ) => {
  4312. assert.ok( false, "everything's gonna be alright" );
  4313. } );
  4314. } );
  4315. } );
  4316. /**
  4317. * @author dforrer / https://github.com/dforrer
  4318. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4319. */
  4320. /**
  4321. * @param object THREE.Object3D
  4322. * @constructor
  4323. */
  4324. var AddObjectCommand$1 = function ( object ) {
  4325. Command.call( this );
  4326. this.type = 'AddObjectCommand';
  4327. this.object = object;
  4328. if ( object !== undefined ) {
  4329. this.name = 'Add Object: ' + object.name;
  4330. }
  4331. };
  4332. AddObjectCommand$1.prototype = {
  4333. execute: function () {
  4334. this.editor.addObject( this.object );
  4335. this.editor.select( this.object );
  4336. },
  4337. undo: function () {
  4338. this.editor.removeObject( this.object );
  4339. this.editor.deselect();
  4340. },
  4341. toJSON: function () {
  4342. var output = Command.prototype.toJSON.call( this );
  4343. output.object = this.object.toJSON();
  4344. return output;
  4345. },
  4346. fromJSON: function ( json ) {
  4347. Command.prototype.fromJSON.call( this, json );
  4348. this.object = this.editor.objectByUuid( json.object.object.uuid );
  4349. if ( this.object === undefined ) {
  4350. var loader = new THREE.ObjectLoader();
  4351. this.object = loader.parse( json.object );
  4352. }
  4353. }
  4354. };
  4355. /**
  4356. * @author TristanVALCKE / https://github.com/Itee
  4357. */
  4358. /* global QUnit */
  4359. QUnit.module( 'Editor', () => {
  4360. QUnit.module( 'Commands', () => {
  4361. QUnit.module.todo( 'AddObjectCommand', () => {
  4362. QUnit.test( 'write me !', ( assert ) => {
  4363. assert.ok( false, "everything's gonna be alright" );
  4364. } );
  4365. } );
  4366. } );
  4367. } );
  4368. /**
  4369. * @author dforrer / https://github.com/dforrer
  4370. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4371. */
  4372. /**
  4373. * @param object THREE.Object3D
  4374. * @param script javascript object
  4375. * @constructor
  4376. */
  4377. var AddScriptCommand$1 = function ( object, script ) {
  4378. Command.call( this );
  4379. this.type = 'AddScriptCommand';
  4380. this.name = 'Add Script';
  4381. this.object = object;
  4382. this.script = script;
  4383. };
  4384. AddScriptCommand$1.prototype = {
  4385. execute: function () {
  4386. if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
  4387. this.editor.scripts[ this.object.uuid ] = [];
  4388. }
  4389. this.editor.scripts[ this.object.uuid ].push( this.script );
  4390. this.editor.signals.scriptAdded.dispatch( this.script );
  4391. },
  4392. undo: function () {
  4393. if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
  4394. var index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
  4395. if ( index !== - 1 ) {
  4396. this.editor.scripts[ this.object.uuid ].splice( index, 1 );
  4397. }
  4398. this.editor.signals.scriptRemoved.dispatch( this.script );
  4399. },
  4400. toJSON: function () {
  4401. var output = Command.prototype.toJSON.call( this );
  4402. output.objectUuid = this.object.uuid;
  4403. output.script = this.script;
  4404. return output;
  4405. },
  4406. fromJSON: function ( json ) {
  4407. Command.prototype.fromJSON.call( this, json );
  4408. this.script = json.script;
  4409. this.object = this.editor.objectByUuid( json.objectUuid );
  4410. }
  4411. };
  4412. /**
  4413. * @author TristanVALCKE / https://github.com/Itee
  4414. */
  4415. /* global QUnit */
  4416. QUnit.module( 'Editor', () => {
  4417. QUnit.module( 'Commands', () => {
  4418. QUnit.module.todo( 'AddScriptCommand', () => {
  4419. QUnit.test( 'write me !', ( assert ) => {
  4420. assert.ok( false, "everything's gonna be alright" );
  4421. } );
  4422. } );
  4423. } );
  4424. } );
  4425. /**
  4426. * @author dforrer / https://github.com/dforrer
  4427. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4428. */
  4429. /**
  4430. * @param object THREE.Object3D
  4431. * @param newParent THREE.Object3D
  4432. * @param newBefore THREE.Object3D
  4433. * @constructor
  4434. */
  4435. var MoveObjectCommand = function ( object, newParent, newBefore ) {
  4436. Command.call( this );
  4437. this.type = 'MoveObjectCommand';
  4438. this.name = 'Move Object';
  4439. this.object = object;
  4440. this.oldParent = ( object !== undefined ) ? object.parent : undefined;
  4441. this.oldIndex = ( this.oldParent !== undefined ) ? this.oldParent.children.indexOf( this.object ) : undefined;
  4442. this.newParent = newParent;
  4443. if ( newBefore !== undefined ) {
  4444. this.newIndex = ( newParent !== undefined ) ? newParent.children.indexOf( newBefore ) : undefined;
  4445. } else {
  4446. this.newIndex = ( newParent !== undefined ) ? newParent.children.length : undefined;
  4447. }
  4448. if ( this.oldParent === this.newParent && this.newIndex > this.oldIndex ) {
  4449. this.newIndex --;
  4450. }
  4451. this.newBefore = newBefore;
  4452. };
  4453. MoveObjectCommand.prototype = {
  4454. execute: function () {
  4455. this.oldParent.remove( this.object );
  4456. var children = this.newParent.children;
  4457. children.splice( this.newIndex, 0, this.object );
  4458. this.object.parent = this.newParent;
  4459. this.editor.signals.sceneGraphChanged.dispatch();
  4460. },
  4461. undo: function () {
  4462. this.newParent.remove( this.object );
  4463. var children = this.oldParent.children;
  4464. children.splice( this.oldIndex, 0, this.object );
  4465. this.object.parent = this.oldParent;
  4466. this.editor.signals.sceneGraphChanged.dispatch();
  4467. },
  4468. toJSON: function () {
  4469. var output = Command.prototype.toJSON.call( this );
  4470. output.objectUuid = this.object.uuid;
  4471. output.newParentUuid = this.newParent.uuid;
  4472. output.oldParentUuid = this.oldParent.uuid;
  4473. output.newIndex = this.newIndex;
  4474. output.oldIndex = this.oldIndex;
  4475. return output;
  4476. },
  4477. fromJSON: function ( json ) {
  4478. Command.prototype.fromJSON.call( this, json );
  4479. this.object = this.editor.objectByUuid( json.objectUuid );
  4480. this.oldParent = this.editor.objectByUuid( json.oldParentUuid );
  4481. if ( this.oldParent === undefined ) {
  4482. this.oldParent = this.editor.scene;
  4483. }
  4484. this.newParent = this.editor.objectByUuid( json.newParentUuid );
  4485. if ( this.newParent === undefined ) {
  4486. this.newParent = this.editor.scene;
  4487. }
  4488. this.newIndex = json.newIndex;
  4489. this.oldIndex = json.oldIndex;
  4490. }
  4491. };
  4492. /**
  4493. * @author TristanVALCKE / https://github.com/Itee
  4494. */
  4495. /* global QUnit */
  4496. QUnit.module( 'Editor', () => {
  4497. QUnit.module( 'Commands', () => {
  4498. QUnit.module.todo( 'MoveObjectCommand', () => {
  4499. QUnit.test( 'write me !', ( assert ) => {
  4500. assert.ok( false, "everything's gonna be alright" );
  4501. } );
  4502. } );
  4503. } );
  4504. } );
  4505. /**
  4506. * @author dforrer / https://github.com/dforrer
  4507. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4508. */
  4509. /**
  4510. * @param cmdArray array containing command objects
  4511. * @constructor
  4512. */
  4513. var MultiCmdsCommand$1 = function ( cmdArray ) {
  4514. Command.call( this );
  4515. this.type = 'MultiCmdsCommand';
  4516. this.name = 'Multiple Changes';
  4517. this.cmdArray = ( cmdArray !== undefined ) ? cmdArray : [];
  4518. };
  4519. MultiCmdsCommand$1.prototype = {
  4520. execute: function () {
  4521. this.editor.signals.sceneGraphChanged.active = false;
  4522. for ( var i = 0; i < this.cmdArray.length; i ++ ) {
  4523. this.cmdArray[ i ].execute();
  4524. }
  4525. this.editor.signals.sceneGraphChanged.active = true;
  4526. this.editor.signals.sceneGraphChanged.dispatch();
  4527. },
  4528. undo: function () {
  4529. this.editor.signals.sceneGraphChanged.active = false;
  4530. for ( var i = this.cmdArray.length - 1; i >= 0; i -- ) {
  4531. this.cmdArray[ i ].undo();
  4532. }
  4533. this.editor.signals.sceneGraphChanged.active = true;
  4534. this.editor.signals.sceneGraphChanged.dispatch();
  4535. },
  4536. toJSON: function () {
  4537. var output = Command.prototype.toJSON.call( this );
  4538. var cmds = [];
  4539. for ( var i = 0; i < this.cmdArray.length; i ++ ) {
  4540. cmds.push( this.cmdArray[ i ].toJSON() );
  4541. }
  4542. output.cmds = cmds;
  4543. return output;
  4544. },
  4545. fromJSON: function ( json ) {
  4546. Command.prototype.fromJSON.call( this, json );
  4547. var cmds = json.cmds;
  4548. for ( var i = 0; i < cmds.length; i ++ ) {
  4549. var cmd = new window[ cmds[ i ].type ](); // creates a new object of type "json.type"
  4550. cmd.fromJSON( cmds[ i ] );
  4551. this.cmdArray.push( cmd );
  4552. }
  4553. }
  4554. };
  4555. /**
  4556. * @author TristanVALCKE / https://github.com/Itee
  4557. */
  4558. /* global QUnit */
  4559. QUnit.module( 'Editor', () => {
  4560. QUnit.module( 'Commands', () => {
  4561. QUnit.module.todo( 'MultiCmdsCommand', () => {
  4562. QUnit.test( 'write me !', ( assert ) => {
  4563. assert.ok( false, "everything's gonna be alright" );
  4564. } );
  4565. } );
  4566. } );
  4567. } );
  4568. /**
  4569. * @author dforrer / https://github.com/dforrer
  4570. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4571. */
  4572. /**
  4573. * @param object THREE.Object3D
  4574. * @constructor
  4575. */
  4576. var RemoveObjectCommand$1 = function ( object ) {
  4577. Command.call( this );
  4578. this.type = 'RemoveObjectCommand';
  4579. this.name = 'Remove Object';
  4580. this.object = object;
  4581. this.parent = ( object !== undefined ) ? object.parent : undefined;
  4582. if ( this.parent !== undefined ) {
  4583. this.index = this.parent.children.indexOf( this.object );
  4584. }
  4585. };
  4586. RemoveObjectCommand$1.prototype = {
  4587. execute: function () {
  4588. var scope = this.editor;
  4589. this.object.traverse( function ( child ) {
  4590. scope.removeHelper( child );
  4591. } );
  4592. this.parent.remove( this.object );
  4593. this.editor.select( this.parent );
  4594. this.editor.signals.objectRemoved.dispatch( this.object );
  4595. this.editor.signals.sceneGraphChanged.dispatch();
  4596. },
  4597. undo: function () {
  4598. var scope = this.editor;
  4599. this.object.traverse( function ( child ) {
  4600. if ( child.geometry !== undefined ) scope.addGeometry( child.geometry );
  4601. if ( child.material !== undefined ) scope.addMaterial( child.material );
  4602. scope.addHelper( child );
  4603. } );
  4604. this.parent.children.splice( this.index, 0, this.object );
  4605. this.object.parent = this.parent;
  4606. this.editor.select( this.object );
  4607. this.editor.signals.objectAdded.dispatch( this.object );
  4608. this.editor.signals.sceneGraphChanged.dispatch();
  4609. },
  4610. toJSON: function () {
  4611. var output = Command.prototype.toJSON.call( this );
  4612. output.object = this.object.toJSON();
  4613. output.index = this.index;
  4614. output.parentUuid = this.parent.uuid;
  4615. return output;
  4616. },
  4617. fromJSON: function ( json ) {
  4618. Command.prototype.fromJSON.call( this, json );
  4619. this.parent = this.editor.objectByUuid( json.parentUuid );
  4620. if ( this.parent === undefined ) {
  4621. this.parent = this.editor.scene;
  4622. }
  4623. this.index = json.index;
  4624. this.object = this.editor.objectByUuid( json.object.object.uuid );
  4625. if ( this.object === undefined ) {
  4626. var loader = new THREE.ObjectLoader();
  4627. this.object = loader.parse( json.object );
  4628. }
  4629. }
  4630. };
  4631. /**
  4632. * @author TristanVALCKE / https://github.com/Itee
  4633. */
  4634. /* global QUnit */
  4635. QUnit.module( 'Editor', () => {
  4636. QUnit.module( 'Commands', () => {
  4637. QUnit.module.todo( 'RemoveObjectCommand', () => {
  4638. QUnit.test( 'write me !', ( assert ) => {
  4639. assert.ok( false, "everything's gonna be alright" );
  4640. } );
  4641. } );
  4642. } );
  4643. } );
  4644. /**
  4645. * @author dforrer / https://github.com/dforrer
  4646. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4647. */
  4648. /**
  4649. * @param object THREE.Object3D
  4650. * @param script javascript object
  4651. * @constructor
  4652. */
  4653. var RemoveScriptCommand$1 = function ( object, script ) {
  4654. Command.call( this );
  4655. this.type = 'RemoveScriptCommand';
  4656. this.name = 'Remove Script';
  4657. this.object = object;
  4658. this.script = script;
  4659. if ( this.object && this.script ) {
  4660. this.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
  4661. }
  4662. };
  4663. RemoveScriptCommand$1.prototype = {
  4664. execute: function () {
  4665. if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
  4666. if ( this.index !== - 1 ) {
  4667. this.editor.scripts[ this.object.uuid ].splice( this.index, 1 );
  4668. }
  4669. this.editor.signals.scriptRemoved.dispatch( this.script );
  4670. },
  4671. undo: function () {
  4672. if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
  4673. this.editor.scripts[ this.object.uuid ] = [];
  4674. }
  4675. this.editor.scripts[ this.object.uuid ].splice( this.index, 0, this.script );
  4676. this.editor.signals.scriptAdded.dispatch( this.script );
  4677. },
  4678. toJSON: function () {
  4679. var output = Command.prototype.toJSON.call( this );
  4680. output.objectUuid = this.object.uuid;
  4681. output.script = this.script;
  4682. output.index = this.index;
  4683. return output;
  4684. },
  4685. fromJSON: function ( json ) {
  4686. Command.prototype.fromJSON.call( this, json );
  4687. this.script = json.script;
  4688. this.index = json.index;
  4689. this.object = this.editor.objectByUuid( json.objectUuid );
  4690. }
  4691. };
  4692. /**
  4693. * @author TristanVALCKE / https://github.com/Itee
  4694. */
  4695. /* global QUnit */
  4696. QUnit.module( 'Editor', () => {
  4697. QUnit.module( 'Commands', () => {
  4698. QUnit.module.todo( 'RemoveScriptCommand', () => {
  4699. QUnit.test( 'write me !', ( assert ) => {
  4700. assert.ok( false, "everything's gonna be alright" );
  4701. } );
  4702. } );
  4703. } );
  4704. } );
  4705. /**
  4706. * @author dforrer / https://github.com/dforrer
  4707. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4708. */
  4709. /**
  4710. * @param object THREE.Object3D
  4711. * @param attributeName string
  4712. * @param newValue integer representing a hex color value
  4713. * @constructor
  4714. */
  4715. var SetColorCommand$1 = function ( object, attributeName, newValue ) {
  4716. Command.call( this );
  4717. this.type = 'SetColorCommand';
  4718. this.name = 'Set ' + attributeName;
  4719. this.updatable = true;
  4720. this.object = object;
  4721. this.attributeName = attributeName;
  4722. this.oldValue = ( object !== undefined ) ? this.object[ this.attributeName ].getHex() : undefined;
  4723. this.newValue = newValue;
  4724. };
  4725. SetColorCommand$1.prototype = {
  4726. execute: function () {
  4727. this.object[ this.attributeName ].setHex( this.newValue );
  4728. this.editor.signals.objectChanged.dispatch( this.object );
  4729. },
  4730. undo: function () {
  4731. this.object[ this.attributeName ].setHex( this.oldValue );
  4732. this.editor.signals.objectChanged.dispatch( this.object );
  4733. },
  4734. update: function ( cmd ) {
  4735. this.newValue = cmd.newValue;
  4736. },
  4737. toJSON: function () {
  4738. var output = Command.prototype.toJSON.call( this );
  4739. output.objectUuid = this.object.uuid;
  4740. output.attributeName = this.attributeName;
  4741. output.oldValue = this.oldValue;
  4742. output.newValue = this.newValue;
  4743. return output;
  4744. },
  4745. fromJSON: function ( json ) {
  4746. Command.prototype.fromJSON.call( this, json );
  4747. this.object = this.editor.objectByUuid( json.objectUuid );
  4748. this.attributeName = json.attributeName;
  4749. this.oldValue = json.oldValue;
  4750. this.newValue = json.newValue;
  4751. }
  4752. };
  4753. /**
  4754. * @author TristanVALCKE / https://github.com/Itee
  4755. */
  4756. /* global QUnit */
  4757. QUnit.module( 'Editor', () => {
  4758. QUnit.module( 'Commands', () => {
  4759. QUnit.module.todo( 'SetColorCommand', () => {
  4760. QUnit.test( 'write me !', ( assert ) => {
  4761. assert.ok( false, "everything's gonna be alright" );
  4762. } );
  4763. } );
  4764. } );
  4765. } );
  4766. /**
  4767. * @author dforrer / https://github.com/dforrer
  4768. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4769. */
  4770. /**
  4771. * @param object THREE.Object3D
  4772. * @param newGeometry THREE.Geometry
  4773. * @constructor
  4774. */
  4775. var SetGeometryCommand$1 = function ( object, newGeometry ) {
  4776. Command.call( this );
  4777. this.type = 'SetGeometryCommand';
  4778. this.name = 'Set Geometry';
  4779. this.updatable = true;
  4780. this.object = object;
  4781. this.oldGeometry = ( object !== undefined ) ? object.geometry : undefined;
  4782. this.newGeometry = newGeometry;
  4783. };
  4784. SetGeometryCommand$1.prototype = {
  4785. execute: function () {
  4786. this.object.geometry.dispose();
  4787. this.object.geometry = this.newGeometry;
  4788. this.object.geometry.computeBoundingSphere();
  4789. this.editor.signals.geometryChanged.dispatch( this.object );
  4790. this.editor.signals.sceneGraphChanged.dispatch();
  4791. },
  4792. undo: function () {
  4793. this.object.geometry.dispose();
  4794. this.object.geometry = this.oldGeometry;
  4795. this.object.geometry.computeBoundingSphere();
  4796. this.editor.signals.geometryChanged.dispatch( this.object );
  4797. this.editor.signals.sceneGraphChanged.dispatch();
  4798. },
  4799. update: function ( cmd ) {
  4800. this.newGeometry = cmd.newGeometry;
  4801. },
  4802. toJSON: function () {
  4803. var output = Command.prototype.toJSON.call( this );
  4804. output.objectUuid = this.object.uuid;
  4805. output.oldGeometry = this.object.geometry.toJSON();
  4806. output.newGeometry = this.newGeometry.toJSON();
  4807. return output;
  4808. },
  4809. fromJSON: function ( json ) {
  4810. Command.prototype.fromJSON.call( this, json );
  4811. this.object = this.editor.objectByUuid( json.objectUuid );
  4812. this.oldGeometry = parseGeometry( json.oldGeometry );
  4813. this.newGeometry = parseGeometry( json.newGeometry );
  4814. function parseGeometry ( data ) {
  4815. var loader = new THREE.ObjectLoader();
  4816. return loader.parseGeometries( [ data ] )[ data.uuid ];
  4817. }
  4818. }
  4819. };
  4820. /**
  4821. * @author TristanVALCKE / https://github.com/Itee
  4822. */
  4823. /* global QUnit */
  4824. QUnit.module( 'Editor', () => {
  4825. QUnit.module( 'Commands', () => {
  4826. QUnit.module.todo( 'SetGeometryCommand', () => {
  4827. QUnit.test( 'write me !', ( assert ) => {
  4828. assert.ok( false, "everything's gonna be alright" );
  4829. } );
  4830. } );
  4831. } );
  4832. } );
  4833. /**
  4834. * @author dforrer / https://github.com/dforrer
  4835. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4836. */
  4837. /**
  4838. * @param object THREE.Object3D
  4839. * @param attributeName string
  4840. * @param newValue number, string, boolean or object
  4841. * @constructor
  4842. */
  4843. var SetGeometryValueCommand$1 = function ( object, attributeName, newValue ) {
  4844. Command.call( this );
  4845. this.type = 'SetGeometryValueCommand';
  4846. this.name = 'Set Geometry.' + attributeName;
  4847. this.object = object;
  4848. this.attributeName = attributeName;
  4849. this.oldValue = ( object !== undefined ) ? object.geometry[ attributeName ] : undefined;
  4850. this.newValue = newValue;
  4851. };
  4852. SetGeometryValueCommand$1.prototype = {
  4853. execute: function () {
  4854. this.object.geometry[ this.attributeName ] = this.newValue;
  4855. this.editor.signals.objectChanged.dispatch( this.object );
  4856. this.editor.signals.geometryChanged.dispatch();
  4857. this.editor.signals.sceneGraphChanged.dispatch();
  4858. },
  4859. undo: function () {
  4860. this.object.geometry[ this.attributeName ] = this.oldValue;
  4861. this.editor.signals.objectChanged.dispatch( this.object );
  4862. this.editor.signals.geometryChanged.dispatch();
  4863. this.editor.signals.sceneGraphChanged.dispatch();
  4864. },
  4865. toJSON: function () {
  4866. var output = Command.prototype.toJSON.call( this );
  4867. output.objectUuid = this.object.uuid;
  4868. output.attributeName = this.attributeName;
  4869. output.oldValue = this.oldValue;
  4870. output.newValue = this.newValue;
  4871. return output;
  4872. },
  4873. fromJSON: function ( json ) {
  4874. Command.prototype.fromJSON.call( this, json );
  4875. this.object = this.editor.objectByUuid( json.objectUuid );
  4876. this.attributeName = json.attributeName;
  4877. this.oldValue = json.oldValue;
  4878. this.newValue = json.newValue;
  4879. }
  4880. };
  4881. /**
  4882. * @author TristanVALCKE / https://github.com/Itee
  4883. */
  4884. /* global QUnit */
  4885. QUnit.module( 'Editor', () => {
  4886. QUnit.module( 'Commands', () => {
  4887. QUnit.module.todo( 'SetGeometryValueCommand', () => {
  4888. QUnit.test( 'write me !', ( assert ) => {
  4889. assert.ok( false, "everything's gonna be alright" );
  4890. } );
  4891. } );
  4892. } );
  4893. } );
  4894. /**
  4895. * @author dforrer / https://github.com/dforrer
  4896. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4897. */
  4898. /**
  4899. * @param object THREE.Object3D
  4900. * @param attributeName string
  4901. * @param newValue integer representing a hex color value
  4902. * @constructor
  4903. */
  4904. var SetMaterialColorCommand$1 = function ( object, attributeName, newValue, materialSlot ) {
  4905. Command.call( this );
  4906. this.type = 'SetMaterialColorCommand';
  4907. this.name = 'Set Material.' + attributeName;
  4908. this.updatable = true;
  4909. this.object = object;
  4910. this.material = this.editor.getObjectMaterial( object, materialSlot );
  4911. this.oldValue = ( this.material !== undefined ) ? this.material[ attributeName ].getHex() : undefined;
  4912. this.newValue = newValue;
  4913. this.attributeName = attributeName;
  4914. };
  4915. SetMaterialColorCommand$1.prototype = {
  4916. execute: function () {
  4917. this.material[ this.attributeName ].setHex( this.newValue );
  4918. this.editor.signals.materialChanged.dispatch( this.material );
  4919. },
  4920. undo: function () {
  4921. this.material[ this.attributeName ].setHex( this.oldValue );
  4922. this.editor.signals.materialChanged.dispatch( this.material );
  4923. },
  4924. update: function ( cmd ) {
  4925. this.newValue = cmd.newValue;
  4926. },
  4927. toJSON: function () {
  4928. var output = Command.prototype.toJSON.call( this );
  4929. output.objectUuid = this.object.uuid;
  4930. output.attributeName = this.attributeName;
  4931. output.oldValue = this.oldValue;
  4932. output.newValue = this.newValue;
  4933. return output;
  4934. },
  4935. fromJSON: function ( json ) {
  4936. Command.prototype.fromJSON.call( this, json );
  4937. this.object = this.editor.objectByUuid( json.objectUuid );
  4938. this.attributeName = json.attributeName;
  4939. this.oldValue = json.oldValue;
  4940. this.newValue = json.newValue;
  4941. }
  4942. };
  4943. /**
  4944. * @author TristanVALCKE / https://github.com/Itee
  4945. */
  4946. /* global QUnit */
  4947. QUnit.module( 'Editor', () => {
  4948. QUnit.module( 'Commands', () => {
  4949. QUnit.module.todo( 'SetMaterialColorCommand', () => {
  4950. QUnit.test( 'write me !', ( assert ) => {
  4951. assert.ok( false, "everything's gonna be alright" );
  4952. } );
  4953. } );
  4954. } );
  4955. } );
  4956. /**
  4957. * @author dforrer / https://github.com/dforrer
  4958. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4959. */
  4960. /**
  4961. * @param object THREE.Object3D
  4962. * @param newMaterial THREE.Material
  4963. * @constructor
  4964. */
  4965. var SetMaterialCommand$1 = function ( object, newMaterial, materialSlot ) {
  4966. Command.call( this );
  4967. this.type = 'SetMaterialCommand';
  4968. this.name = 'New Material';
  4969. this.object = object;
  4970. this.materialSlot = materialSlot;
  4971. this.oldMaterial = this.editor.getObjectMaterial( object, materialSlot );
  4972. this.newMaterial = newMaterial;
  4973. };
  4974. SetMaterialCommand$1.prototype = {
  4975. execute: function () {
  4976. this.editor.setObjectMaterial( this.object, this.materialSlot, this.newMaterial );
  4977. this.editor.signals.materialChanged.dispatch( this.newMaterial );
  4978. },
  4979. undo: function () {
  4980. this.editor.setObjectMaterial( this.object, this.materialSlot, this.oldMaterial );
  4981. this.editor.signals.materialChanged.dispatch( this.oldMaterial );
  4982. },
  4983. toJSON: function () {
  4984. var output = Command.prototype.toJSON.call( this );
  4985. output.objectUuid = this.object.uuid;
  4986. output.oldMaterial = this.oldMaterial.toJSON();
  4987. output.newMaterial = this.newMaterial.toJSON();
  4988. return output;
  4989. },
  4990. fromJSON: function ( json ) {
  4991. Command.prototype.fromJSON.call( this, json );
  4992. this.object = this.editor.objectByUuid( json.objectUuid );
  4993. this.oldMaterial = parseMaterial( json.oldMaterial );
  4994. this.newMaterial = parseMaterial( json.newMaterial );
  4995. function parseMaterial ( json ) {
  4996. var loader = new THREE.ObjectLoader();
  4997. var images = loader.parseImages( json.images );
  4998. var textures = loader.parseTextures( json.textures, images );
  4999. var materials = loader.parseMaterials( [ json ], textures );
  5000. return materials[ json.uuid ];
  5001. }
  5002. }
  5003. };
  5004. /**
  5005. * @author TristanVALCKE / https://github.com/Itee
  5006. */
  5007. /* global QUnit */
  5008. QUnit.module( 'Editor', () => {
  5009. QUnit.module( 'Commands', () => {
  5010. QUnit.module.todo( 'SetMaterialCommand', () => {
  5011. QUnit.test( 'write me !', ( assert ) => {
  5012. assert.ok( false, "everything's gonna be alright" );
  5013. } );
  5014. } );
  5015. } );
  5016. } );
  5017. /**
  5018. * @author dforrer / https://github.com/dforrer
  5019. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  5020. */
  5021. /**
  5022. * @param object THREE.Object3D
  5023. * @param mapName string
  5024. * @param newMap THREE.Texture
  5025. * @constructor
  5026. */
  5027. var SetMaterialMapCommand$1 = function ( object, mapName, newMap, materialSlot ) {
  5028. Command.call( this );
  5029. this.type = 'SetMaterialMapCommand';
  5030. this.name = 'Set Material.' + mapName;
  5031. this.object = object;
  5032. this.material = this.editor.getObjectMaterial( object, materialSlot );
  5033. this.oldMap = ( object !== undefined ) ? this.material[ mapName ] : undefined;
  5034. this.newMap = newMap;
  5035. this.mapName = mapName;
  5036. };
  5037. SetMaterialMapCommand$1.prototype = {
  5038. execute: function () {
  5039. this.material[ this.mapName ] = this.newMap;
  5040. this.material.needsUpdate = true;
  5041. this.editor.signals.materialChanged.dispatch( this.material );
  5042. },
  5043. undo: function () {
  5044. this.material[ this.mapName ] = this.oldMap;
  5045. this.material.needsUpdate = true;
  5046. this.editor.signals.materialChanged.dispatch( this.material );
  5047. },
  5048. toJSON: function () {
  5049. var output = Command.prototype.toJSON.call( this );
  5050. output.objectUuid = this.object.uuid;
  5051. output.mapName = this.mapName;
  5052. output.newMap = serializeMap( this.newMap );
  5053. output.oldMap = serializeMap( this.oldMap );
  5054. return output;
  5055. // serializes a map (THREE.Texture)
  5056. function serializeMap ( map ) {
  5057. if ( map === null || map === undefined ) return null;
  5058. var meta = {
  5059. geometries: {},
  5060. materials: {},
  5061. textures: {},
  5062. images: {}
  5063. };
  5064. var json = map.toJSON( meta );
  5065. var images = extractFromCache( meta.images );
  5066. if ( images.length > 0 ) json.images = images;
  5067. json.sourceFile = map.sourceFile;
  5068. return json;
  5069. }
  5070. // Note: The function 'extractFromCache' is copied from Object3D.toJSON()
  5071. // extract data from the cache hash
  5072. // remove metadata on each item
  5073. // and return as array
  5074. function extractFromCache ( cache ) {
  5075. var values = [];
  5076. for ( var key in cache ) {
  5077. var data = cache[ key ];
  5078. delete data.metadata;
  5079. values.push( data );
  5080. }
  5081. return values;
  5082. }
  5083. },
  5084. fromJSON: function ( json ) {
  5085. Command.prototype.fromJSON.call( this, json );
  5086. this.object = this.editor.objectByUuid( json.objectUuid );
  5087. this.mapName = json.mapName;
  5088. this.oldMap = parseTexture( json.oldMap );
  5089. this.newMap = parseTexture( json.newMap );
  5090. function parseTexture ( json ) {
  5091. var map = null;
  5092. if ( json !== null ) {
  5093. var loader = new THREE.ObjectLoader();
  5094. var images = loader.parseImages( json.images );
  5095. var textures = loader.parseTextures( [ json ], images );
  5096. map = textures[ json.uuid ];
  5097. map.sourceFile = json.sourceFile;
  5098. }
  5099. return map;
  5100. }
  5101. }
  5102. };
  5103. /**
  5104. * @author TristanVALCKE / https://github.com/Itee
  5105. */
  5106. /* global QUnit */
  5107. QUnit.module( 'Editor', () => {
  5108. QUnit.module( 'Commands', () => {
  5109. QUnit.module.todo( 'SetMaterialMapCommand', () => {
  5110. QUnit.test( 'write me !', ( assert ) => {
  5111. assert.ok( false, "everything's gonna be alright" );
  5112. } );
  5113. } );
  5114. } );
  5115. } );
  5116. /**
  5117. * @author dforrer / https://github.com/dforrer
  5118. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  5119. */
  5120. /**
  5121. * @param object THREE.Object3D
  5122. * @param attributeName string
  5123. * @param newValue number, string, boolean or object
  5124. * @constructor
  5125. */
  5126. var SetMaterialValueCommand$1 = function ( object, attributeName, newValue, materialSlot ) {
  5127. Command.call( this );
  5128. this.type = 'SetMaterialValueCommand';
  5129. this.name = 'Set Material.' + attributeName;
  5130. this.updatable = true;
  5131. this.object = object;
  5132. this.material = this.editor.getObjectMaterial( object, materialSlot );
  5133. this.oldValue = ( this.material !== undefined ) ? this.material[ attributeName ] : undefined;
  5134. this.newValue = newValue;
  5135. this.attributeName = attributeName;
  5136. };
  5137. SetMaterialValueCommand$1.prototype = {
  5138. execute: function () {
  5139. this.material[ this.attributeName ] = this.newValue;
  5140. this.material.needsUpdate = true;
  5141. this.editor.signals.objectChanged.dispatch( this.object );
  5142. this.editor.signals.materialChanged.dispatch( this.material );
  5143. },
  5144. undo: function () {
  5145. this.material[ this.attributeName ] = this.oldValue;
  5146. this.material.needsUpdate = true;
  5147. this.editor.signals.objectChanged.dispatch( this.object );
  5148. this.editor.signals.materialChanged.dispatch( this.material );
  5149. },
  5150. update: function ( cmd ) {
  5151. this.newValue = cmd.newValue;
  5152. },
  5153. toJSON: function () {
  5154. var output = Command.prototype.toJSON.call( this );
  5155. output.objectUuid = this.object.uuid;
  5156. output.attributeName = this.attributeName;
  5157. output.oldValue = this.oldValue;
  5158. output.newValue = this.newValue;
  5159. return output;
  5160. },
  5161. fromJSON: function ( json ) {
  5162. Command.prototype.fromJSON.call( this, json );
  5163. this.attributeName = json.attributeName;
  5164. this.oldValue = json.oldValue;
  5165. this.newValue = json.newValue;
  5166. this.object = this.editor.objectByUuid( json.objectUuid );
  5167. }
  5168. };
  5169. /**
  5170. * @author TristanVALCKE / https://github.com/Itee
  5171. */
  5172. /* global QUnit */
  5173. QUnit.module( 'Editor', () => {
  5174. QUnit.module( 'Commands', () => {
  5175. QUnit.module.todo( 'SetMaterialValueCommand', () => {
  5176. QUnit.test( 'write me !', ( assert ) => {
  5177. assert.ok( false, "everything's gonna be alright" );
  5178. } );
  5179. } );
  5180. } );
  5181. } );
  5182. /**
  5183. * @author dforrer / https://github.com/dforrer
  5184. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  5185. */
  5186. /**
  5187. * @param object THREE.Object3D
  5188. * @param newPosition THREE.Vector3
  5189. * @param optionalOldPosition THREE.Vector3
  5190. * @constructor
  5191. */
  5192. var SetPositionCommand$1 = function ( object, newPosition, optionalOldPosition ) {
  5193. Command.call( this );
  5194. this.type = 'SetPositionCommand';
  5195. this.name = 'Set Position';
  5196. this.updatable = true;
  5197. this.object = object;
  5198. if ( object !== undefined && newPosition !== undefined ) {
  5199. this.oldPosition = object.position.clone();
  5200. this.newPosition = newPosition.clone();
  5201. }
  5202. if ( optionalOldPosition !== undefined ) {
  5203. this.oldPosition = optionalOldPosition.clone();
  5204. }
  5205. };
  5206. SetPositionCommand$1.prototype = {
  5207. execute: function () {
  5208. this.object.position.copy( this.newPosition );
  5209. this.object.updateMatrixWorld( true );
  5210. this.editor.signals.objectChanged.dispatch( this.object );
  5211. },
  5212. undo: function () {
  5213. this.object.position.copy( this.oldPosition );
  5214. this.object.updateMatrixWorld( true );
  5215. this.editor.signals.objectChanged.dispatch( this.object );
  5216. },
  5217. update: function ( command ) {
  5218. this.newPosition.copy( command.newPosition );
  5219. },
  5220. toJSON: function () {
  5221. var output = Command.prototype.toJSON.call( this );
  5222. output.objectUuid = this.object.uuid;
  5223. output.oldPosition = this.oldPosition.toArray();
  5224. output.newPosition = this.newPosition.toArray();
  5225. return output;
  5226. },
  5227. fromJSON: function ( json ) {
  5228. Command.prototype.fromJSON.call( this, json );
  5229. this.object = this.editor.objectByUuid( json.objectUuid );
  5230. this.oldPosition = new THREE.Vector3().fromArray( json.oldPosition );
  5231. this.newPosition = new THREE.Vector3().fromArray( json.newPosition );
  5232. }
  5233. };
  5234. /**
  5235. * @author TristanVALCKE / https://github.com/Itee
  5236. */
  5237. /* global QUnit */
  5238. QUnit.module( 'Editor', () => {
  5239. QUnit.module( 'Commands', () => {
  5240. QUnit.module.todo( 'SetPositionCommand', () => {
  5241. QUnit.test( 'write me !', ( assert ) => {
  5242. assert.ok( false, "everything's gonna be alright" );
  5243. } );
  5244. } );
  5245. } );
  5246. } );
  5247. /**
  5248. * @author dforrer / https://github.com/dforrer
  5249. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  5250. */
  5251. /**
  5252. * @param object THREE.Object3D
  5253. * @param newRotation THREE.Euler
  5254. * @param optionalOldRotation THREE.Euler
  5255. * @constructor
  5256. */
  5257. var SetRotationCommand$1 = function ( object, newRotation, optionalOldRotation ) {
  5258. Command.call( this );
  5259. this.type = 'SetRotationCommand';
  5260. this.name = 'Set Rotation';
  5261. this.updatable = true;
  5262. this.object = object;
  5263. if ( object !== undefined && newRotation !== undefined ) {
  5264. this.oldRotation = object.rotation.clone();
  5265. this.newRotation = newRotation.clone();
  5266. }
  5267. if ( optionalOldRotation !== undefined ) {
  5268. this.oldRotation = optionalOldRotation.clone();
  5269. }
  5270. };
  5271. SetRotationCommand$1.prototype = {
  5272. execute: function () {
  5273. this.object.rotation.copy( this.newRotation );
  5274. this.object.updateMatrixWorld( true );
  5275. this.editor.signals.objectChanged.dispatch( this.object );
  5276. },
  5277. undo: function () {
  5278. this.object.rotation.copy( this.oldRotation );
  5279. this.object.updateMatrixWorld( true );
  5280. this.editor.signals.objectChanged.dispatch( this.object );
  5281. },
  5282. update: function ( command ) {
  5283. this.newRotation.copy( command.newRotation );
  5284. },
  5285. toJSON: function () {
  5286. var output = Command.prototype.toJSON.call( this );
  5287. output.objectUuid = this.object.uuid;
  5288. output.oldRotation = this.oldRotation.toArray();
  5289. output.newRotation = this.newRotation.toArray();
  5290. return output;
  5291. },
  5292. fromJSON: function ( json ) {
  5293. Command.prototype.fromJSON.call( this, json );
  5294. this.object = this.editor.objectByUuid( json.objectUuid );
  5295. this.oldRotation = new THREE.Euler().fromArray( json.oldRotation );
  5296. this.newRotation = new THREE.Euler().fromArray( json.newRotation );
  5297. }
  5298. };
  5299. /**
  5300. * @author TristanVALCKE / https://github.com/Itee
  5301. */
  5302. /* global QUnit */
  5303. QUnit.module( 'Editor', () => {
  5304. QUnit.module( 'Commands', () => {
  5305. QUnit.module.todo( 'SetRotationCommand', () => {
  5306. QUnit.test( 'write me !', ( assert ) => {
  5307. assert.ok( false, "everything's gonna be alright" );
  5308. } );
  5309. } );
  5310. } );
  5311. } );
  5312. /**
  5313. * @author dforrer / https://github.com/dforrer
  5314. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  5315. */
  5316. /**
  5317. * @param object THREE.Object3D
  5318. * @param newScale THREE.Vector3
  5319. * @param optionalOldScale THREE.Vector3
  5320. * @constructor
  5321. */
  5322. var SetScaleCommand$1 = function ( object, newScale, optionalOldScale ) {
  5323. Command.call( this );
  5324. this.type = 'SetScaleCommand';
  5325. this.name = 'Set Scale';
  5326. this.updatable = true;
  5327. this.object = object;
  5328. if ( object !== undefined && newScale !== undefined ) {
  5329. this.oldScale = object.scale.clone();
  5330. this.newScale = newScale.clone();
  5331. }
  5332. if ( optionalOldScale !== undefined ) {
  5333. this.oldScale = optionalOldScale.clone();
  5334. }
  5335. };
  5336. SetScaleCommand$1.prototype = {
  5337. execute: function () {
  5338. this.object.scale.copy( this.newScale );
  5339. this.object.updateMatrixWorld( true );
  5340. this.editor.signals.objectChanged.dispatch( this.object );
  5341. },
  5342. undo: function () {
  5343. this.object.scale.copy( this.oldScale );
  5344. this.object.updateMatrixWorld( true );
  5345. this.editor.signals.objectChanged.dispatch( this.object );
  5346. },
  5347. update: function ( command ) {
  5348. this.newScale.copy( command.newScale );
  5349. },
  5350. toJSON: function () {
  5351. var output = Command.prototype.toJSON.call( this );
  5352. output.objectUuid = this.object.uuid;
  5353. output.oldScale = this.oldScale.toArray();
  5354. output.newScale = this.newScale.toArray();
  5355. return output;
  5356. },
  5357. fromJSON: function ( json ) {
  5358. Command.prototype.fromJSON.call( this, json );
  5359. this.object = this.editor.objectByUuid( json.objectUuid );
  5360. this.oldScale = new THREE.Vector3().fromArray( json.oldScale );
  5361. this.newScale = new THREE.Vector3().fromArray( json.newScale );
  5362. }
  5363. };
  5364. /**
  5365. * @author TristanVALCKE / https://github.com/Itee
  5366. */
  5367. /* global QUnit */
  5368. QUnit.module( 'Editor', () => {
  5369. QUnit.module( 'Commands', () => {
  5370. QUnit.module.todo( 'SetScaleCommand', () => {
  5371. QUnit.test( 'write me !', ( assert ) => {
  5372. assert.ok( false, "everything's gonna be alright" );
  5373. } );
  5374. } );
  5375. } );
  5376. } );
  5377. /**
  5378. * @author dforrer / https://github.com/dforrer
  5379. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  5380. */
  5381. /**
  5382. * @param scene containing children to import
  5383. * @constructor
  5384. */
  5385. var SetSceneCommand$1 = function ( scene ) {
  5386. Command.call( this );
  5387. this.type = 'SetSceneCommand';
  5388. this.name = 'Set Scene';
  5389. this.cmdArray = [];
  5390. if ( scene !== undefined ) {
  5391. this.cmdArray.push( new SetUuidCommand( this.editor.scene, scene.uuid ) );
  5392. this.cmdArray.push( new SetValueCommand( this.editor.scene, 'name', scene.name ) );
  5393. this.cmdArray.push( new SetValueCommand( this.editor.scene, 'userData', JSON.parse( JSON.stringify( scene.userData ) ) ) );
  5394. while ( scene.children.length > 0 ) {
  5395. var child = scene.children.pop();
  5396. this.cmdArray.push( new AddObjectCommand( child ) );
  5397. }
  5398. }
  5399. };
  5400. SetSceneCommand$1.prototype = {
  5401. execute: function () {
  5402. this.editor.signals.sceneGraphChanged.active = false;
  5403. for ( var i = 0; i < this.cmdArray.length; i ++ ) {
  5404. this.cmdArray[ i ].execute();
  5405. }
  5406. this.editor.signals.sceneGraphChanged.active = true;
  5407. this.editor.signals.sceneGraphChanged.dispatch();
  5408. },
  5409. undo: function () {
  5410. this.editor.signals.sceneGraphChanged.active = false;
  5411. for ( var i = this.cmdArray.length - 1; i >= 0; i -- ) {
  5412. this.cmdArray[ i ].undo();
  5413. }
  5414. this.editor.signals.sceneGraphChanged.active = true;
  5415. this.editor.signals.sceneGraphChanged.dispatch();
  5416. },
  5417. toJSON: function () {
  5418. var output = Command.prototype.toJSON.call( this );
  5419. var cmds = [];
  5420. for ( var i = 0; i < this.cmdArray.length; i ++ ) {
  5421. cmds.push( this.cmdArray[ i ].toJSON() );
  5422. }
  5423. output.cmds = cmds;
  5424. return output;
  5425. },
  5426. fromJSON: function ( json ) {
  5427. Command.prototype.fromJSON.call( this, json );
  5428. var cmds = json.cmds;
  5429. for ( var i = 0; i < cmds.length; i ++ ) {
  5430. var cmd = new window[ cmds[ i ].type ](); // creates a new object of type "json.type"
  5431. cmd.fromJSON( cmds[ i ] );
  5432. this.cmdArray.push( cmd );
  5433. }
  5434. }
  5435. };
  5436. /**
  5437. * @author TristanVALCKE / https://github.com/Itee
  5438. */
  5439. /* global QUnit */
  5440. QUnit.module( 'Editor', () => {
  5441. QUnit.module( 'Commands', () => {
  5442. QUnit.module.todo( 'SetSceneCommand', () => {
  5443. QUnit.test( 'write me !', ( assert ) => {
  5444. assert.ok( false, "everything's gonna be alright" );
  5445. } );
  5446. } );
  5447. } );
  5448. } );
  5449. /**
  5450. * @author dforrer / https://github.com/dforrer
  5451. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  5452. */
  5453. /**
  5454. * @param object THREE.Object3D
  5455. * @param script javascript object
  5456. * @param attributeName string
  5457. * @param newValue string, object
  5458. * @constructor
  5459. */
  5460. var SetScriptValueCommand$1 = function ( object, script, attributeName, newValue ) {
  5461. Command.call( this );
  5462. this.type = 'SetScriptValueCommand';
  5463. this.name = 'Set Script.' + attributeName;
  5464. this.updatable = true;
  5465. this.object = object;
  5466. this.script = script;
  5467. this.attributeName = attributeName;
  5468. this.oldValue = ( script !== undefined ) ? script[ this.attributeName ] : undefined;
  5469. this.newValue = newValue;
  5470. };
  5471. SetScriptValueCommand$1.prototype = {
  5472. execute: function () {
  5473. this.script[ this.attributeName ] = this.newValue;
  5474. this.editor.signals.scriptChanged.dispatch();
  5475. },
  5476. undo: function () {
  5477. this.script[ this.attributeName ] = this.oldValue;
  5478. this.editor.signals.scriptChanged.dispatch();
  5479. },
  5480. update: function ( cmd ) {
  5481. this.newValue = cmd.newValue;
  5482. },
  5483. toJSON: function () {
  5484. var output = Command.prototype.toJSON.call( this );
  5485. output.objectUuid = this.object.uuid;
  5486. output.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
  5487. output.attributeName = this.attributeName;
  5488. output.oldValue = this.oldValue;
  5489. output.newValue = this.newValue;
  5490. return output;
  5491. },
  5492. fromJSON: function ( json ) {
  5493. Command.prototype.fromJSON.call( this, json );
  5494. this.oldValue = json.oldValue;
  5495. this.newValue = json.newValue;
  5496. this.attributeName = json.attributeName;
  5497. this.object = this.editor.objectByUuid( json.objectUuid );
  5498. this.script = this.editor.scripts[ json.objectUuid ][ json.index ];
  5499. }
  5500. };
  5501. /**
  5502. * @author TristanVALCKE / https://github.com/Itee
  5503. */
  5504. /* global QUnit */
  5505. QUnit.module( 'Editor', () => {
  5506. QUnit.module( 'Commands', () => {
  5507. QUnit.module.todo( 'SetScriptValueCommand', () => {
  5508. QUnit.test( 'write me !', ( assert ) => {
  5509. assert.ok( false, "everything's gonna be alright" );
  5510. } );
  5511. } );
  5512. } );
  5513. } );
  5514. /**
  5515. * @author dforrer / https://github.com/dforrer
  5516. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  5517. */
  5518. /**
  5519. * @param object THREE.Object3D
  5520. * @param newUuid string
  5521. * @constructor
  5522. */
  5523. var SetUuidCommand$1 = function ( object, newUuid ) {
  5524. Command.call( this );
  5525. this.type = 'SetUuidCommand';
  5526. this.name = 'Update UUID';
  5527. this.object = object;
  5528. this.oldUuid = ( object !== undefined ) ? object.uuid : undefined;
  5529. this.newUuid = newUuid;
  5530. };
  5531. SetUuidCommand$1.prototype = {
  5532. execute: function () {
  5533. this.object.uuid = this.newUuid;
  5534. this.editor.signals.objectChanged.dispatch( this.object );
  5535. this.editor.signals.sceneGraphChanged.dispatch();
  5536. },
  5537. undo: function () {
  5538. this.object.uuid = this.oldUuid;
  5539. this.editor.signals.objectChanged.dispatch( this.object );
  5540. this.editor.signals.sceneGraphChanged.dispatch();
  5541. },
  5542. toJSON: function () {
  5543. var output = Command.prototype.toJSON.call( this );
  5544. output.oldUuid = this.oldUuid;
  5545. output.newUuid = this.newUuid;
  5546. return output;
  5547. },
  5548. fromJSON: function ( json ) {
  5549. Command.prototype.fromJSON.call( this, json );
  5550. this.oldUuid = json.oldUuid;
  5551. this.newUuid = json.newUuid;
  5552. this.object = this.editor.objectByUuid( json.oldUuid );
  5553. if ( this.object === undefined ) {
  5554. this.object = this.editor.objectByUuid( json.newUuid );
  5555. }
  5556. }
  5557. };
  5558. /**
  5559. * @author TristanVALCKE / https://github.com/Itee
  5560. */
  5561. /* global QUnit */
  5562. QUnit.module( 'Editor', () => {
  5563. QUnit.module( 'Commands', () => {
  5564. QUnit.module.todo( 'SetUuidCommand', () => {
  5565. QUnit.test( 'write me !', ( assert ) => {
  5566. assert.ok( false, "everything's gonna be alright" );
  5567. } );
  5568. } );
  5569. } );
  5570. } );
  5571. /**
  5572. * @author dforrer / https://github.com/dforrer
  5573. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  5574. */
  5575. /**
  5576. * @param object THREE.Object3D
  5577. * @param attributeName string
  5578. * @param newValue number, string, boolean or object
  5579. * @constructor
  5580. */
  5581. var SetValueCommand$1 = function ( object, attributeName, newValue ) {
  5582. Command.call( this );
  5583. this.type = 'SetValueCommand';
  5584. this.name = 'Set ' + attributeName;
  5585. this.updatable = true;
  5586. this.object = object;
  5587. this.attributeName = attributeName;
  5588. this.oldValue = ( object !== undefined ) ? object[ attributeName ] : undefined;
  5589. this.newValue = newValue;
  5590. };
  5591. SetValueCommand$1.prototype = {
  5592. execute: function () {
  5593. this.object[ this.attributeName ] = this.newValue;
  5594. this.editor.signals.objectChanged.dispatch( this.object );
  5595. // this.editor.signals.sceneGraphChanged.dispatch();
  5596. },
  5597. undo: function () {
  5598. this.object[ this.attributeName ] = this.oldValue;
  5599. this.editor.signals.objectChanged.dispatch( this.object );
  5600. // this.editor.signals.sceneGraphChanged.dispatch();
  5601. },
  5602. update: function ( cmd ) {
  5603. this.newValue = cmd.newValue;
  5604. },
  5605. toJSON: function () {
  5606. var output = Command.prototype.toJSON.call( this );
  5607. output.objectUuid = this.object.uuid;
  5608. output.attributeName = this.attributeName;
  5609. output.oldValue = this.oldValue;
  5610. output.newValue = this.newValue;
  5611. return output;
  5612. },
  5613. fromJSON: function ( json ) {
  5614. Command.prototype.fromJSON.call( this, json );
  5615. this.attributeName = json.attributeName;
  5616. this.oldValue = json.oldValue;
  5617. this.newValue = json.newValue;
  5618. this.object = this.editor.objectByUuid( json.objectUuid );
  5619. }
  5620. };
  5621. /**
  5622. * @author TristanVALCKE / https://github.com/Itee
  5623. */
  5624. /* global QUnit */
  5625. QUnit.module( 'Editor', () => {
  5626. QUnit.module( 'Commands', () => {
  5627. QUnit.module.todo( 'SetValueCommand', () => {
  5628. QUnit.test( 'write me !', ( assert ) => {
  5629. assert.ok( false, "everything's gonna be alright" );
  5630. } );
  5631. } );
  5632. } );
  5633. } );
  5634. /**
  5635. * @author TristanVALCKE / https://github.com/Itee
  5636. */
  5637. // TODO (Itee) Editor is not es6 module so care to include order !!!
  5638. // TODO: all views could not be testable, waiting modular code before implement units tests on them
  5639. //editor
  5640. //editor/commands
  5641. //editor/others
  5642. } );
  5643. })));
粤ICP备19079148号