123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800 |
- import * as THREE from '../../build/three.module.js';
- import { UIButton, UICheckbox, UIColor, UIInput, UINumber, UIPanel, UIRow, UISelect, UIText } from './libs/ui.js';
- import { UITexture } from './libs/ui.three.js';
- import { SetMaterialCommand } from './commands/SetMaterialCommand.js';
- import { SetMaterialColorCommand } from './commands/SetMaterialColorCommand.js';
- import { SetMaterialMapCommand } from './commands/SetMaterialMapCommand.js';
- import { SetMaterialValueCommand } from './commands/SetMaterialValueCommand.js';
- import { SetMaterialVectorCommand } from './commands/SetMaterialVectorCommand.js';
- var materialClasses = {
- 'LineBasicMaterial': THREE.LineBasicMaterial,
- 'LineDashedMaterial': THREE.LineDashedMaterial,
- 'MeshBasicMaterial': THREE.MeshBasicMaterial,
- 'MeshDepthMaterial': THREE.MeshDepthMaterial,
- 'MeshNormalMaterial': THREE.MeshNormalMaterial,
- 'MeshLambertMaterial': THREE.MeshLambertMaterial,
- 'MeshMatcapMaterial': THREE.MeshMatcapMaterial,
- 'MeshPhongMaterial': THREE.MeshPhongMaterial,
- 'MeshToonMaterial': THREE.MeshToonMaterial,
- 'MeshStandardMaterial': THREE.MeshStandardMaterial,
- 'MeshPhysicalMaterial': THREE.MeshPhysicalMaterial,
- 'RawShaderMaterial': THREE.RawShaderMaterial,
- 'ShaderMaterial': THREE.ShaderMaterial,
- 'ShadowMaterial': THREE.ShadowMaterial,
- 'SpriteMaterial': THREE.SpriteMaterial,
- 'PointsMaterial': THREE.PointsMaterial
- };
- function SidebarMaterial( editor ) {
- var strings = editor.strings;
- var signals = editor.signals;
- var currentObject;
- var currentMaterialSlot = 0;
- var epsilon = 0.01 - Number.EPSILON;
- var container = new UIPanel();
- container.setBorderTop( '0' );
- container.setDisplay( 'none' );
- container.setPaddingTop( '20px' );
- // Current material slot
- var materialSlotRow = new UIRow();
- materialSlotRow.add( new UIText( strings.getKey( 'sidebar/material/slot' ) ).setWidth( '90px' ) );
- var materialSlotSelect = new UISelect().setWidth( '170px' ).setFontSize( '12px' ).onChange( update );
- materialSlotSelect.setOptions( { 0: '' } ).setValue( 0 );
- materialSlotRow.add( materialSlotSelect );
- container.add( materialSlotRow );
- // type
- var materialClassRow = new UIRow();
- var materialClass = new UISelect().setWidth( '150px' ).setFontSize( '12px' ).onChange( update );
- materialClassRow.add( new UIText( strings.getKey( 'sidebar/material/type' ) ).setWidth( '90px' ) );
- materialClassRow.add( materialClass );
- container.add( materialClassRow );
- // uuid
- var materialUUIDRow = new UIRow();
- var materialUUID = new UIInput().setWidth( '102px' ).setFontSize( '12px' ).setDisabled( true );
- var materialUUIDRenew = new UIButton( strings.getKey( 'sidebar/material/new' ) ).setMarginLeft( '7px' ).onClick( function () {
- materialUUID.setValue( THREE.MathUtils.generateUUID() );
- update();
- } );
- materialUUIDRow.add( new UIText( strings.getKey( 'sidebar/material/uuid' ) ).setWidth( '90px' ) );
- materialUUIDRow.add( materialUUID );
- materialUUIDRow.add( materialUUIDRenew );
- container.add( materialUUIDRow );
- // name
- var materialNameRow = new UIRow();
- var materialName = new UIInput().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
- editor.execute( new SetMaterialValueCommand( editor, editor.selected, 'name', materialName.getValue(), currentMaterialSlot ) );
- } );
- materialNameRow.add( new UIText( strings.getKey( 'sidebar/material/name' ) ).setWidth( '90px' ) );
- materialNameRow.add( materialName );
- container.add( materialNameRow );
- // program
- var materialProgramRow = new UIRow();
- materialProgramRow.add( new UIText( strings.getKey( 'sidebar/material/program' ) ).setWidth( '90px' ) );
- var materialProgramInfo = new UIButton( strings.getKey( 'sidebar/material/info' ) );
- materialProgramInfo.setMarginRight( '4px' );
- materialProgramInfo.onClick( function () {
- signals.editScript.dispatch( currentObject, 'programInfo' );
- } );
- materialProgramRow.add( materialProgramInfo );
- var materialProgramVertex = new UIButton( strings.getKey( 'sidebar/material/vertex' ) );
- materialProgramVertex.setMarginRight( '4px' );
- materialProgramVertex.onClick( function () {
- signals.editScript.dispatch( currentObject, 'vertexShader' );
- } );
- materialProgramRow.add( materialProgramVertex );
- var materialProgramFragment = new UIButton( strings.getKey( 'sidebar/material/fragment' ) );
- materialProgramFragment.setMarginRight( '4px' );
- materialProgramFragment.onClick( function () {
- signals.editScript.dispatch( currentObject, 'fragmentShader' );
- } );
- materialProgramRow.add( materialProgramFragment );
- container.add( materialProgramRow );
- // color
- var materialColorRow = new UIRow();
- var materialColor = new UIColor().onInput( update );
- materialColorRow.add( new UIText( strings.getKey( 'sidebar/material/color' ) ).setWidth( '90px' ) );
- materialColorRow.add( materialColor );
- container.add( materialColorRow );
- // roughness
- var materialRoughnessRow = new UIRow();
- var materialRoughness = new UINumber( 0.5 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
- materialRoughnessRow.add( new UIText( strings.getKey( 'sidebar/material/roughness' ) ).setWidth( '90px' ) );
- materialRoughnessRow.add( materialRoughness );
- container.add( materialRoughnessRow );
- // metalness
- var materialMetalnessRow = new UIRow();
- var materialMetalness = new UINumber( 0.5 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
- materialMetalnessRow.add( new UIText( strings.getKey( 'sidebar/material/metalness' ) ).setWidth( '90px' ) );
- materialMetalnessRow.add( materialMetalness );
- container.add( materialMetalnessRow );
- /*
- // sheen
- var materialSheenRow = new UIRow();
- var materialSheenEnabled = new UICheckbox( false ).onChange( update );
- var materialSheen = new UIColor().setHexValue( 0x000000 ).onInput( update );
- materialSheenRow.add( new UIText( strings.getKey( 'sidebar/material/sheen' ) ).setWidth( '90px' ) )
- materialSheenRow.add( materialSheenEnabled );
- materialSheenRow.add( materialSheen );
- container.add( materialSheenRow );
- */
- // emissive
- var materialEmissiveRow = new UIRow();
- var materialEmissive = new UIColor().setHexValue( 0x000000 ).onInput( update );
- var materialEmissiveIntensity = new UINumber( 1 ).setWidth( '30px' ).onChange( update );
- materialEmissiveRow.add( new UIText( strings.getKey( 'sidebar/material/emissive' ) ).setWidth( '90px' ) );
- materialEmissiveRow.add( materialEmissive );
- materialEmissiveRow.add( materialEmissiveIntensity );
- container.add( materialEmissiveRow );
- // specular
- var materialSpecularRow = new UIRow();
- var materialSpecular = new UIColor().setHexValue( 0x111111 ).onInput( update );
- materialSpecularRow.add( new UIText( strings.getKey( 'sidebar/material/specular' ) ).setWidth( '90px' ) );
- materialSpecularRow.add( materialSpecular );
- container.add( materialSpecularRow );
- // shininess
- var materialShininessRow = new UIRow();
- var materialShininess = new UINumber( 30 ).onChange( update );
- materialShininessRow.add( new UIText( strings.getKey( 'sidebar/material/shininess' ) ).setWidth( '90px' ) );
- materialShininessRow.add( materialShininess );
- container.add( materialShininessRow );
- // clearcoat
- var materialClearcoatRow = new UIRow();
- var materialClearcoat = new UINumber( 1 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
- materialClearcoatRow.add( new UIText( strings.getKey( 'sidebar/material/clearcoat' ) ).setWidth( '90px' ) );
- materialClearcoatRow.add( materialClearcoat );
- container.add( materialClearcoatRow );
- // clearcoatRoughness
- var materialClearcoatRoughnessRow = new UIRow();
- var materialClearcoatRoughness = new UINumber( 1 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
- materialClearcoatRoughnessRow.add( new UIText( strings.getKey( 'sidebar/material/clearcoatroughness' ) ).setWidth( '90px' ) );
- materialClearcoatRoughnessRow.add( materialClearcoatRoughness );
- container.add( materialClearcoatRoughnessRow );
- // vertex colors
- var materialVertexColorsRow = new UIRow();
- var materialVertexColors = new UICheckbox( false ).onChange( update );
- materialVertexColorsRow.add( new UIText( strings.getKey( 'sidebar/material/vertexcolors' ) ).setWidth( '90px' ) );
- materialVertexColorsRow.add( materialVertexColors );
- container.add( materialVertexColorsRow );
- // vertex tangents
- var materialVertexTangentsRow = new UIRow();
- var materialVertexTangents = new UICheckbox( false ).onChange( update );
- materialVertexTangentsRow.add( new UIText( strings.getKey( 'sidebar/material/vertextangents' ) ).setWidth( '90px' ) );
- materialVertexTangentsRow.add( materialVertexTangents );
- container.add( materialVertexTangentsRow );
- // depth packing
- var materialDepthPackingRow = new UIRow();
- var materialDepthPacking = new UISelect().setOptions( {
- [ THREE.BasicDepthPacking ]: 'BasicDepthPacking',
- [ THREE.RGBADepthPacking ]: 'RGBADepthPacking'
- } );
- materialDepthPacking.onChange( update );
- materialDepthPackingRow.add( new UIText( strings.getKey( 'sidebar/material/depthPacking' ) ).setWidth( '90px' ) );
- materialDepthPackingRow.add( materialDepthPacking );
- container.add( materialDepthPackingRow );
- // skinning
- var materialSkinningRow = new UIRow();
- var materialSkinning = new UICheckbox( false ).onChange( update );
- materialSkinningRow.add( new UIText( strings.getKey( 'sidebar/material/skinning' ) ).setWidth( '90px' ) );
- materialSkinningRow.add( materialSkinning );
- container.add( materialSkinningRow );
- // map
- var materialMapRow = new UIRow();
- var materialMapEnabled = new UICheckbox( false ).onChange( update );
- var materialMap = new UITexture().onChange( updateMaterial );
- materialMapRow.add( new UIText( strings.getKey( 'sidebar/material/map' ) ).setWidth( '90px' ) );
- materialMapRow.add( materialMapEnabled );
- materialMapRow.add( materialMap );
- container.add( materialMapRow );
- // matcap map
- var materialMatcapMapRow = new UIRow();
- var materialMatcapMapEnabled = new UICheckbox( false ).onChange( update );
- var materialMatcapMap = new UITexture().onChange( update );
- materialMatcapMapRow.add( new UIText( strings.getKey( 'sidebar/material/matcap' ) ).setWidth( '90px' ) );
- materialMatcapMapRow.add( materialMatcapMapEnabled );
- materialMatcapMapRow.add( materialMatcapMap );
- container.add( materialMatcapMapRow );
- // alpha map
- var materialAlphaMapRow = new UIRow();
- var materialAlphaMapEnabled = new UICheckbox( false ).onChange( update );
- var materialAlphaMap = new UITexture().onChange( update );
- materialAlphaMapRow.add( new UIText( strings.getKey( 'sidebar/material/alphamap' ) ).setWidth( '90px' ) );
- materialAlphaMapRow.add( materialAlphaMapEnabled );
- materialAlphaMapRow.add( materialAlphaMap );
- container.add( materialAlphaMapRow );
- // bump map
- var materialBumpMapRow = new UIRow();
- var materialBumpMapEnabled = new UICheckbox( false ).onChange( update );
- var materialBumpMap = new UITexture().onChange( update );
- var materialBumpScale = new UINumber( 1 ).setWidth( '30px' ).onChange( update );
- materialBumpMapRow.add( new UIText( strings.getKey( 'sidebar/material/bumpmap' ) ).setWidth( '90px' ) );
- materialBumpMapRow.add( materialBumpMapEnabled );
- materialBumpMapRow.add( materialBumpMap );
- materialBumpMapRow.add( materialBumpScale );
- container.add( materialBumpMapRow );
- // normal map
- var materialNormalMapRow = new UIRow();
- var materialNormalMapEnabled = new UICheckbox( false ).onChange( update );
- var materialNormalMap = new UITexture().onChange( update );
- var materialNormalScaleX = new UINumber( 1 ).setWidth( '30px' ).onChange( update );
- var materialNormalScaleY = new UINumber( 1 ).setWidth( '30px' ).onChange( update );
- materialNormalMapRow.add( new UIText( strings.getKey( 'sidebar/material/normalmap' ) ).setWidth( '90px' ) );
- materialNormalMapRow.add( materialNormalMapEnabled );
- materialNormalMapRow.add( materialNormalMap );
- materialNormalMapRow.add( materialNormalScaleX );
- materialNormalMapRow.add( materialNormalScaleY );
- container.add( materialNormalMapRow );
- // clearcoat normal map
- var materialClearcoatNormalMapRow = new UIRow();
- var materialClearcoatNormalMapEnabled = new UICheckbox( false ).onChange( update );
- var materialClearcoatNormalMap = new UITexture().onChange( update );
- var materialClearcoatNormalScaleX = new UINumber( 1 ).setWidth( '30px' ).onChange( update );
- var materialClearcoatNormalScaleY = new UINumber( 1 ).setWidth( '30px' ).onChange( update );
- materialClearcoatNormalMapRow.add( new UIText( strings.getKey( 'sidebar/material/clearcoatnormalmap' ) ).setWidth( '90px' ) );
- materialClearcoatNormalMapRow.add( materialClearcoatNormalMapEnabled );
- materialClearcoatNormalMapRow.add( materialClearcoatNormalMap );
- materialClearcoatNormalMapRow.add( materialClearcoatNormalScaleX );
- materialClearcoatNormalMapRow.add( materialClearcoatNormalScaleY );
- container.add( materialClearcoatNormalMapRow );
- // displacement map
- var materialDisplacementMapRow = new UIRow();
- var materialDisplacementMapEnabled = new UICheckbox( false ).onChange( update );
- var materialDisplacementMap = new UITexture().onChange( update );
- var materialDisplacementScale = new UINumber( 1 ).setWidth( '30px' ).onChange( update );
- materialDisplacementMapRow.add( new UIText( strings.getKey( 'sidebar/material/displacemap' ) ).setWidth( '90px' ) );
- materialDisplacementMapRow.add( materialDisplacementMapEnabled );
- materialDisplacementMapRow.add( materialDisplacementMap );
- materialDisplacementMapRow.add( materialDisplacementScale );
- container.add( materialDisplacementMapRow );
- // roughness map
- var materialRoughnessMapRow = new UIRow();
- var materialRoughnessMapEnabled = new UICheckbox( false ).onChange( update );
- var materialRoughnessMap = new UITexture().onChange( update );
- materialRoughnessMapRow.add( new UIText( strings.getKey( 'sidebar/material/roughmap' ) ).setWidth( '90px' ) );
- materialRoughnessMapRow.add( materialRoughnessMapEnabled );
- materialRoughnessMapRow.add( materialRoughnessMap );
- container.add( materialRoughnessMapRow );
- // metalness map
- var materialMetalnessMapRow = new UIRow();
- var materialMetalnessMapEnabled = new UICheckbox( false ).onChange( update );
- var materialMetalnessMap = new UITexture().onChange( update );
- materialMetalnessMapRow.add( new UIText( strings.getKey( 'sidebar/material/metalmap' ) ).setWidth( '90px' ) );
- materialMetalnessMapRow.add( materialMetalnessMapEnabled );
- materialMetalnessMapRow.add( materialMetalnessMap );
- container.add( materialMetalnessMapRow );
- // specular map
- var materialSpecularMapRow = new UIRow();
- var materialSpecularMapEnabled = new UICheckbox( false ).onChange( update );
- var materialSpecularMap = new UITexture().onChange( update );
- materialSpecularMapRow.add( new UIText( strings.getKey( 'sidebar/material/specularmap' ) ).setWidth( '90px' ) );
- materialSpecularMapRow.add( materialSpecularMapEnabled );
- materialSpecularMapRow.add( materialSpecularMap );
- container.add( materialSpecularMapRow );
- // env map
- var materialEnvMapRow = new UIRow();
- var materialEnvMapEnabled = new UICheckbox( false ).onChange( update );
- var materialEnvMap = new UITexture( THREE.EquirectangularReflectionMapping ).onChange( updateMaterial );
- var materialReflectivity = new UINumber( 1 ).setWidth( '30px' ).onChange( update );
- materialEnvMapRow.add( new UIText( strings.getKey( 'sidebar/material/envmap' ) ).setWidth( '90px' ) );
- materialEnvMapRow.add( materialEnvMapEnabled );
- materialEnvMapRow.add( materialEnvMap );
- materialEnvMapRow.add( materialReflectivity );
- container.add( materialEnvMapRow );
- // light map
- var materialLightMapRow = new UIRow();
- var materialLightMapEnabled = new UICheckbox( false ).onChange( update );
- var materialLightMap = new UITexture().onChange( update );
- materialLightMapRow.add( new UIText( strings.getKey( 'sidebar/material/lightmap' ) ).setWidth( '90px' ) );
- materialLightMapRow.add( materialLightMapEnabled );
- materialLightMapRow.add( materialLightMap );
- container.add( materialLightMapRow );
- // ambient occlusion map
- var materialAOMapRow = new UIRow();
- var materialAOMapEnabled = new UICheckbox( false ).onChange( update );
- var materialAOMap = new UITexture().onChange( update );
- var materialAOScale = new UINumber( 1 ).setRange( 0, 1 ).setWidth( '30px' ).onChange( update );
- materialAOMapRow.add( new UIText( strings.getKey( 'sidebar/material/aomap' ) ).setWidth( '90px' ) );
- materialAOMapRow.add( materialAOMapEnabled );
- materialAOMapRow.add( materialAOMap );
- materialAOMapRow.add( materialAOScale );
- container.add( materialAOMapRow );
- // emissive map
- var materialEmissiveMapRow = new UIRow();
- var materialEmissiveMapEnabled = new UICheckbox( false ).onChange( update );
- var materialEmissiveMap = new UITexture().onChange( updateMaterial );
- materialEmissiveMapRow.add( new UIText( strings.getKey( 'sidebar/material/emissivemap' ) ).setWidth( '90px' ) );
- materialEmissiveMapRow.add( materialEmissiveMapEnabled );
- materialEmissiveMapRow.add( materialEmissiveMap );
- container.add( materialEmissiveMapRow );
- // gradient map
- var materialGradientMapRow = new UIRow();
- var materialGradientMapEnabled = new UICheckbox( false ).onChange( update );
- var materialGradientMap = new UITexture().onChange( update );
- materialGradientMapRow.add( new UIText( strings.getKey( 'sidebar/material/gradientmap' ) ).setWidth( '90px' ) );
- materialGradientMapRow.add( materialGradientMapEnabled );
- materialGradientMapRow.add( materialGradientMap );
- container.add( materialGradientMapRow );
- // side
- var materialSideRow = new UIRow();
- var materialSide = new UISelect().setOptions( {
- 0: strings.getKey( 'sidebar/material/side/front' ),
- 1: strings.getKey( 'sidebar/material/side/back' ),
- 2: strings.getKey( 'sidebar/material/side/double' )
- } ).setWidth( '150px' ).setFontSize( '12px' ).onChange( update );
- materialSideRow.add( new UIText( strings.getKey( 'sidebar/material/side' ) ).setWidth( '90px' ) );
- materialSideRow.add( materialSide );
- container.add( materialSideRow );
- // size
- var materialSizeRow = new UIRow();
- var materialSize = new UINumber( 1 ).setWidth( '60px' ).setRange( 0, Infinity ).onChange( update );
- materialSizeRow.add( new UIText( strings.getKey( 'sidebar/material/size' ) ).setWidth( '90px' ) );
- materialSizeRow.add( materialSize );
- container.add( materialSizeRow );
- // sizeAttenuation
- var materialSizeAttenuationRow = new UIRow();
- var materialSizeAttenuation = new UICheckbox( true ).onChange( update );
- materialSizeAttenuationRow.add( new UIText( strings.getKey( 'sidebar/material/sizeAttenuation' ) ).setWidth( '90px' ) );
- materialSizeAttenuationRow.add( materialSizeAttenuation );
- container.add( materialSizeAttenuationRow );
- // shading
- var materialShadingRow = new UIRow();
- var materialShading = new UICheckbox( false ).setLeft( '100px' ).onChange( update );
- materialShadingRow.add( new UIText( strings.getKey( 'sidebar/material/flatshaded' ) ).setWidth( '90px' ) );
- materialShadingRow.add( materialShading );
- container.add( materialShadingRow );
- // blending
- var materialBlendingRow = new UIRow();
- var materialBlending = new UISelect().setOptions( {
- 0: strings.getKey( 'sidebar/material/blending/no' ),
- 1: strings.getKey( 'sidebar/material/blending/normal' ),
- 2: strings.getKey( 'sidebar/material/blending/additive' ),
- 3: strings.getKey( 'sidebar/material/blending/subtractive' ),
- 4: strings.getKey( 'sidebar/material/blending/multiply' ),
- 5: strings.getKey( 'sidebar/material/blending/custom' )
- } ).setWidth( '150px' ).setFontSize( '12px' ).onChange( update );
- materialBlendingRow.add( new UIText( strings.getKey( 'sidebar/material/blending' ) ).setWidth( '90px' ) );
- materialBlendingRow.add( materialBlending );
- container.add( materialBlendingRow );
- // opacity
- var materialOpacityRow = new UIRow();
- var materialOpacity = new UINumber( 1 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
- materialOpacityRow.add( new UIText( strings.getKey( 'sidebar/material/opacity' ) ).setWidth( '90px' ) );
- materialOpacityRow.add( materialOpacity );
- container.add( materialOpacityRow );
- // transparent
- var materialTransparentRow = new UIRow();
- var materialTransparent = new UICheckbox().setLeft( '100px' ).onChange( update );
- materialTransparentRow.add( new UIText( strings.getKey( 'sidebar/material/transparent' ) ).setWidth( '90px' ) );
- materialTransparentRow.add( materialTransparent );
- container.add( materialTransparentRow );
- // alpha test
- var materialAlphaTestRow = new UIRow();
- var materialAlphaTest = new UINumber().setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
- materialAlphaTestRow.add( new UIText( strings.getKey( 'sidebar/material/alphatest' ) ).setWidth( '90px' ) );
- materialAlphaTestRow.add( materialAlphaTest );
- container.add( materialAlphaTestRow );
- // depth test
- var materialDepthTestRow = new UIRow();
- var materialDepthTest = new UICheckbox().onChange( update );
- materialDepthTestRow.add( new UIText( strings.getKey( 'sidebar/material/depthtest' ) ).setWidth( '90px' ) );
- materialDepthTestRow.add( materialDepthTest );
- container.add( materialDepthTestRow );
- // depth write
- var materialDepthWriteRow = new UIRow();
- var materialDepthWrite = new UICheckbox().onChange( update );
- materialDepthWriteRow.add( new UIText( strings.getKey( 'sidebar/material/depthwrite' ) ).setWidth( '90px' ) );
- materialDepthWriteRow.add( materialDepthWrite );
- container.add( materialDepthWriteRow );
- // wireframe
- var materialWireframeRow = new UIRow();
- var materialWireframe = new UICheckbox( false ).onChange( update );
- materialWireframeRow.add( new UIText( strings.getKey( 'sidebar/material/wireframe' ) ).setWidth( '90px' ) );
- materialWireframeRow.add( materialWireframe );
- container.add( materialWireframeRow );
- //
- function update() {
- var object = currentObject;
- var geometry = object.geometry;
- var previousSelectedSlot = currentMaterialSlot;
- currentMaterialSlot = parseInt( materialSlotSelect.getValue() );
- if ( currentMaterialSlot !== previousSelectedSlot ) refreshUI( true );
- var material = editor.getObjectMaterial( currentObject, currentMaterialSlot );
- var textureWarning = false;
- var objectHasUvs = false;
- if ( object.isSprite ) objectHasUvs = true;
- if ( geometry.isGeometry && geometry.faceVertexUvs[ 0 ].length > 0 ) objectHasUvs = true;
- if ( geometry.isBufferGeometry && geometry.attributes.uv !== undefined ) objectHasUvs = true;
- if ( material ) {
- if ( material.uuid !== undefined && material.uuid !== materialUUID.getValue() ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'uuid', materialUUID.getValue(), currentMaterialSlot ) );
- }
- if ( material.type !== materialClass.getValue() ) {
- material = new materialClasses[ materialClass.getValue() ]();
- if ( material.type === 'RawShaderMaterial' ) {
- material.vertexShader = vertexShaderVariables + material.vertexShader;
- }
- if ( Array.isArray( currentObject.material ) ) {
- // don't remove the entire multi-material. just the material of the selected slot
- editor.removeMaterial( currentObject.material[ currentMaterialSlot ] );
- } else {
- editor.removeMaterial( currentObject.material );
- }
- editor.execute( new SetMaterialCommand( editor, currentObject, material, currentMaterialSlot ), 'New Material: ' + materialClass.getValue() );
- editor.addMaterial( material );
- // TODO Copy other references in the scene graph
- // keeping name and UUID then.
- // Also there should be means to create a unique
- // copy for the current object explicitly and to
- // attach the current material to other objects.
- }
- if ( material.color !== undefined && material.color.getHex() !== materialColor.getHexValue() ) {
- editor.execute( new SetMaterialColorCommand( editor, currentObject, 'color', materialColor.getHexValue(), currentMaterialSlot ) );
- }
- if ( material.roughness !== undefined && Math.abs( material.roughness - materialRoughness.getValue() ) >= epsilon ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'roughness', materialRoughness.getValue(), currentMaterialSlot ) );
- }
- if ( material.metalness !== undefined && Math.abs( material.metalness - materialMetalness.getValue() ) >= epsilon ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'metalness', materialMetalness.getValue(), currentMaterialSlot ) );
- }
- /*
- if ( material.sheen !== undefined ) {
- var sheenEnabled = materialSheenEnabled.getValue() === true;
- var sheen = sheenEnabled ? new Color(materialSheen.getHexValue()) : null;
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'sheen', sheen, currentMaterialSlot ) );
- }
- if ( material.sheen !== undefined && material.sheen !== null && material.sheen.getHex() !== materialSheen.getHexValue() ) {
- editor.execute( new SetMaterialColorCommand( editor, currentObject, 'sheen', materialSheen.getHexValue(), currentMaterialSlot ) );
- }
- */
- if ( material.emissive !== undefined && material.emissive.getHex() !== materialEmissive.getHexValue() ) {
- editor.execute( new SetMaterialColorCommand( editor, currentObject, 'emissive', materialEmissive.getHexValue(), currentMaterialSlot ) );
- }
- if ( material.emissiveIntensity !== undefined && material.emissiveIntensity !== materialEmissiveIntensity.getValue() ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'emissiveIntensity', materialEmissiveIntensity.getValue(), currentMaterialSlot ) );
- }
- if ( material.specular !== undefined && material.specular.getHex() !== materialSpecular.getHexValue() ) {
- editor.execute( new SetMaterialColorCommand( editor, currentObject, 'specular', materialSpecular.getHexValue(), currentMaterialSlot ) );
- }
- if ( material.shininess !== undefined && Math.abs( material.shininess - materialShininess.getValue() ) >= epsilon ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'shininess', materialShininess.getValue(), currentMaterialSlot ) );
- }
- if ( material.clearcoat !== undefined && Math.abs( material.clearcoat - materialClearcoat.getValue() ) >= epsilon ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'clearcoat', materialClearcoat.getValue(), currentMaterialSlot ) );
- }
- if ( material.clearcoatRoughness !== undefined && Math.abs( material.clearcoatRoughness - materialClearcoatRoughness.getValue() ) >= epsilon ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'clearcoatRoughness', materialClearcoatRoughness.getValue(), currentMaterialSlot ) );
- }
- if ( material.vertexColors !== undefined ) {
- var vertexColors = materialVertexColors.getValue();
- if ( material.vertexColors !== vertexColors ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'vertexColors', vertexColors, currentMaterialSlot ) );
- }
- }
- if ( material.depthPacking !== undefined ) {
- var depthPacking = parseInt( materialDepthPacking.getValue() );
- if ( material.depthPacking !== depthPacking ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'depthPacking', depthPacking, currentMaterialSlot ) );
- }
- }
- if ( material.skinning !== undefined && material.skinning !== materialSkinning.getValue() ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'skinning', materialSkinning.getValue(), currentMaterialSlot ) );
- }
- if ( material.map !== undefined ) {
- var mapEnabled = materialMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var map = mapEnabled ? materialMap.getValue() : null;
- if ( material.map !== map ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'map', map, currentMaterialSlot ) );
- }
- } else {
- if ( mapEnabled ) textureWarning = true;
- }
- }
- if ( material.matcap !== undefined ) {
- var mapEnabled = materialMatcapMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var matcap = mapEnabled ? materialMatcapMap.getValue() : null;
- if ( material.matcap !== matcap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'matcap', matcap, currentMaterialSlot ) );
- }
- } else {
- if ( mapEnabled ) textureWarning = true;
- }
- }
- if ( material.alphaMap !== undefined ) {
- var mapEnabled = materialAlphaMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var alphaMap = mapEnabled ? materialAlphaMap.getValue() : null;
- if ( material.alphaMap !== alphaMap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'alphaMap', alphaMap, currentMaterialSlot ) );
- }
- } else {
- if ( mapEnabled ) textureWarning = true;
- }
- }
- if ( material.bumpMap !== undefined ) {
- var bumpMapEnabled = materialBumpMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var bumpMap = bumpMapEnabled ? materialBumpMap.getValue() : null;
- if ( material.bumpMap !== bumpMap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'bumpMap', bumpMap, currentMaterialSlot ) );
- }
- if ( material.bumpScale !== materialBumpScale.getValue() ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'bumpScale', materialBumpScale.getValue(), currentMaterialSlot ) );
- }
- } else {
- if ( bumpMapEnabled ) textureWarning = true;
- }
- }
- if ( material.normalMap !== undefined ) {
- var normalMapEnabled = materialNormalMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var normalMap = normalMapEnabled ? materialNormalMap.getValue() : null;
- if ( material.normalMap !== normalMap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'normalMap', normalMap, currentMaterialSlot ) );
- }
- if ( material.normalScale.x !== materialNormalScaleX.getValue() ||
- material.normalScale.y !== materialNormalScaleY.getValue() ) {
- var value = [
- materialNormalScaleX.getValue(),
- materialNormalScaleY.getValue()
- ];
- editor.execute( new SetMaterialVectorCommand( editor, currentObject, 'normalScale', value, currentMaterialSlot ) );
- }
- } else {
- if ( normalMapEnabled ) textureWarning = true;
- }
- }
- if ( material.clearcoatNormalMap !== undefined ) {
- var clearcoatNormalMapEnabled = materialClearcoatNormalMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var clearcoatNormalMap = clearcoatNormalMapEnabled ? materialClearcoatNormalMap.getValue() : null;
- if ( material.clearcoatNormalMap !== clearcoatNormalMap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'clearcoatNormalMap', clearcoatNormalMap, currentMaterialSlot ) );
- }
- if ( material.clearcoatNormalScale.x !== materialClearcoatNormalScaleX.getValue() ||
- material.clearcoatNormalScale.y !== materialClearcoatNormalScaleY.getValue() ) {
- var value = [
- materialClearcoatNormalScaleX.getValue(),
- materialClearcoatNormalScaleY.getValue()
- ];
- editor.execute( new SetMaterialVectorCommand( editor, currentObject, 'clearcoatNormalScale', value, currentMaterialSlot ) );
- }
- } else {
- if ( clearcoatNormalMapEnabled ) textureWarning = true;
- }
- }
- if ( material.displacementMap !== undefined ) {
- var displacementMapEnabled = materialDisplacementMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var displacementMap = displacementMapEnabled ? materialDisplacementMap.getValue() : null;
- if ( material.displacementMap !== displacementMap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'displacementMap', displacementMap, currentMaterialSlot ) );
- }
- if ( material.displacementScale !== materialDisplacementScale.getValue() ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'displacementScale', materialDisplacementScale.getValue(), currentMaterialSlot ) );
- }
- } else {
- if ( displacementMapEnabled ) textureWarning = true;
- }
- }
- if ( material.roughnessMap !== undefined ) {
- var roughnessMapEnabled = materialRoughnessMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var roughnessMap = roughnessMapEnabled ? materialRoughnessMap.getValue() : null;
- if ( material.roughnessMap !== roughnessMap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'roughnessMap', roughnessMap, currentMaterialSlot ) );
- }
- } else {
- if ( roughnessMapEnabled ) textureWarning = true;
- }
- }
- if ( material.metalnessMap !== undefined ) {
- var metalnessMapEnabled = materialMetalnessMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var metalnessMap = metalnessMapEnabled ? materialMetalnessMap.getValue() : null;
- if ( material.metalnessMap !== metalnessMap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'metalnessMap', metalnessMap, currentMaterialSlot ) );
- }
- } else {
- if ( metalnessMapEnabled ) textureWarning = true;
- }
- }
- if ( material.specularMap !== undefined ) {
- var specularMapEnabled = materialSpecularMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var specularMap = specularMapEnabled ? materialSpecularMap.getValue() : null;
- if ( material.specularMap !== specularMap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'specularMap', specularMap, currentMaterialSlot ) );
- }
- } else {
- if ( specularMapEnabled ) textureWarning = true;
- }
- }
- if ( material.envMap !== undefined ) {
- var envMapEnabled = materialEnvMapEnabled.getValue() === true;
- var envMap = envMapEnabled ? materialEnvMap.getValue() : null;
- if ( material.envMap !== envMap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'envMap', envMap, currentMaterialSlot ) );
- }
- }
- if ( material.reflectivity !== undefined ) {
- var reflectivity = materialReflectivity.getValue();
- if ( material.reflectivity !== reflectivity ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'reflectivity', reflectivity, currentMaterialSlot ) );
- }
- }
- if ( material.lightMap !== undefined ) {
- var lightMapEnabled = materialLightMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var lightMap = lightMapEnabled ? materialLightMap.getValue() : null;
- if ( material.lightMap !== lightMap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'lightMap', lightMap, currentMaterialSlot ) );
- }
- } else {
- if ( lightMapEnabled ) textureWarning = true;
- }
- }
- if ( material.aoMap !== undefined ) {
- var aoMapEnabled = materialAOMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var aoMap = aoMapEnabled ? materialAOMap.getValue() : null;
- if ( material.aoMap !== aoMap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'aoMap', aoMap, currentMaterialSlot ) );
- }
- if ( material.aoMapIntensity !== materialAOScale.getValue() ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'aoMapIntensity', materialAOScale.getValue(), currentMaterialSlot ) );
- }
- } else {
- if ( aoMapEnabled ) textureWarning = true;
- }
- }
- if ( material.emissiveMap !== undefined ) {
- var emissiveMapEnabled = materialEmissiveMapEnabled.getValue() === true;
- if ( objectHasUvs ) {
- var emissiveMap = emissiveMapEnabled ? materialEmissiveMap.getValue() : null;
- if ( material.emissiveMap !== emissiveMap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'emissiveMap', emissiveMap, currentMaterialSlot ) );
- }
- } else {
- if ( emissiveMapEnabled ) textureWarning = true;
- }
- }
- if ( material.gradientMap !== undefined ) {
- var gradientMapEnabled = materialGradientMapEnabled.getValue() === true;
- var gradientMap = gradientMapEnabled ? materialGradientMap.getValue() : null;
- if ( material.gradientMap !== gradientMap ) {
- editor.execute( new SetMaterialMapCommand( editor, currentObject, 'gradientMap', gradientMap, currentMaterialSlot ) );
- }
- }
- if ( material.side !== undefined ) {
- var side = parseInt( materialSide.getValue() );
- if ( material.side !== side ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'side', side, currentMaterialSlot ) );
- }
- }
- if ( material.size !== undefined ) {
- var size = materialSize.getValue();
- if ( material.size !== size ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'size', size, currentMaterialSlot ) );
- }
- }
- if ( material.sizeAttenuation !== undefined ) {
- var sizeAttenuation = materialSizeAttenuation.getValue();
- if ( material.sizeAttenuation !== sizeAttenuation ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'sizeAttenuation', sizeAttenuation, currentMaterialSlot ) );
- }
- }
- if ( material.flatShading !== undefined ) {
- var flatShading = materialShading.getValue();
- if ( material.flatShading != flatShading ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'flatShading', flatShading, currentMaterialSlot ) );
- }
- }
- if ( material.blending !== undefined ) {
- var blending = parseInt( materialBlending.getValue() );
- if ( material.blending !== blending ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'blending', blending, currentMaterialSlot ) );
- }
- }
- if ( material.opacity !== undefined && Math.abs( material.opacity - materialOpacity.getValue() ) >= epsilon ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'opacity', materialOpacity.getValue(), currentMaterialSlot ) );
- }
- if ( material.transparent !== undefined && material.transparent !== materialTransparent.getValue() ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'transparent', materialTransparent.getValue(), currentMaterialSlot ) );
- }
- if ( material.alphaTest !== undefined && Math.abs( material.alphaTest - materialAlphaTest.getValue() ) >= epsilon ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'alphaTest', materialAlphaTest.getValue(), currentMaterialSlot ) );
- }
- if ( material.depthTest !== undefined && material.depthTest !== materialDepthTest.getValue() ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'depthTest', materialDepthTest.getValue(), currentMaterialSlot ) );
- }
- if ( material.depthWrite !== undefined && material.depthWrite !== materialDepthWrite.getValue() ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'depthWrite', materialDepthWrite.getValue(), currentMaterialSlot ) );
- }
- if ( material.wireframe !== undefined && material.wireframe !== materialWireframe.getValue() ) {
- editor.execute( new SetMaterialValueCommand( editor, currentObject, 'wireframe', materialWireframe.getValue(), currentMaterialSlot ) );
- }
- refreshUI();
- }
- if ( textureWarning ) {
- console.warn( 'Can\'t set texture, model doesn\'t have texture coordinates' );
- }
- }
- function updateMaterial( texture ) {
- if ( texture !== null ) {
- if ( texture.isDataTexture !== true && texture.encoding !== THREE.sRGBEncoding ) {
- texture.encoding = THREE.sRGBEncoding;
- var object = currentObject;
- if ( object !== null ) {
- object.material.needsUpdate = true;
- }
- }
- }
- update();
- }
- //
- function setRowVisibility() {
- var properties = {
- 'name': materialNameRow,
- 'color': materialColorRow,
- 'roughness': materialRoughnessRow,
- 'metalness': materialMetalnessRow,
- 'emissive': materialEmissiveRow,
- // 'sheen': materialSheenRow,
- 'specular': materialSpecularRow,
- 'shininess': materialShininessRow,
- 'clearcoat': materialClearcoatRow,
- 'clearcoatRoughness': materialClearcoatRoughnessRow,
- 'vertexShader': materialProgramRow,
- 'vertexColors': materialVertexColorsRow,
- 'vertexTangents': materialVertexTangentsRow,
- 'depthPacking': materialDepthPackingRow,
- 'skinning': materialSkinningRow,
- 'map': materialMapRow,
- 'matcap': materialMatcapMapRow,
- 'alphaMap': materialAlphaMapRow,
- 'bumpMap': materialBumpMapRow,
- 'normalMap': materialNormalMapRow,
- 'clearcoatNormalMap': materialClearcoatNormalMapRow,
- 'displacementMap': materialDisplacementMapRow,
- 'roughnessMap': materialRoughnessMapRow,
- 'metalnessMap': materialMetalnessMapRow,
- 'specularMap': materialSpecularMapRow,
- 'envMap': materialEnvMapRow,
- 'lightMap': materialLightMapRow,
- 'aoMap': materialAOMapRow,
- 'emissiveMap': materialEmissiveMapRow,
- 'gradientMap': materialGradientMapRow,
- 'side': materialSideRow,
- 'size': materialSizeRow,
- 'sizeAttenuation': materialSizeAttenuationRow,
- 'flatShading': materialShadingRow,
- 'blending': materialBlendingRow,
- 'opacity': materialOpacityRow,
- 'transparent': materialTransparentRow,
- 'alphaTest': materialAlphaTestRow,
- 'depthTest': materialDepthTestRow,
- 'depthWrite': materialDepthWriteRow,
- 'wireframe': materialWireframeRow
- };
- var material = currentObject.material;
- if ( Array.isArray( material ) ) {
- materialSlotRow.setDisplay( '' );
- if ( material.length === 0 ) return;
- material = material[ currentMaterialSlot ];
- } else {
- materialSlotRow.setDisplay( 'none' );
- }
- for ( var property in properties ) {
- properties[ property ].setDisplay( material[ property ] !== undefined ? '' : 'none' );
- }
- }
- function refreshUI( resetTextureSelectors ) {
- if ( ! currentObject ) return;
- var material = currentObject.material;
- if ( Array.isArray( material ) ) {
- var slotOptions = {};
- currentMaterialSlot = Math.max( 0, Math.min( material.length, currentMaterialSlot ) );
- for ( var i = 0; i < material.length; i ++ ) {
- slotOptions[ i ] = String( i + 1 ) + ': ' + material[ i ].name;
- }
- materialSlotSelect.setOptions( slotOptions ).setValue( currentMaterialSlot );
- }
- material = editor.getObjectMaterial( currentObject, currentMaterialSlot );
- if ( material.uuid !== undefined ) {
- materialUUID.setValue( material.uuid );
- }
- if ( material.name !== undefined ) {
- materialName.setValue( material.name );
- }
- if ( currentObject.isMesh ) {
- materialClass.setOptions( meshMaterialOptions );
- } else if ( currentObject.isSprite ) {
- materialClass.setOptions( spriteMaterialOptions );
- } else if ( currentObject.isPoints ) {
- materialClass.setOptions( pointsMaterialOptions );
- } else if ( currentObject.isLine ) {
- materialClass.setOptions( lineMaterialOptions );
- }
- materialClass.setValue( material.type );
- if ( material.color !== undefined ) {
- materialColor.setHexValue( material.color.getHexString() );
- }
- if ( material.roughness !== undefined ) {
- materialRoughness.setValue( material.roughness );
- }
- if ( material.metalness !== undefined ) {
- materialMetalness.setValue( material.metalness );
- }
- /*
- if ( material.sheen !== undefined && material.sheen !== null ) {
- materialSheenEnabled.setValue( true );
- materialSheen.setHexValue( material.sheen.getHexString() );
- }
- */
- if ( material.emissive !== undefined ) {
- materialEmissive.setHexValue( material.emissive.getHexString() );
- materialEmissiveIntensity.setValue( material.emissiveIntensity );
- }
- if ( material.specular !== undefined ) {
- materialSpecular.setHexValue( material.specular.getHexString() );
- }
- if ( material.shininess !== undefined ) {
- materialShininess.setValue( material.shininess );
- }
- if ( material.clearcoat !== undefined ) {
- materialClearcoat.setValue( material.clearcoat );
- }
- if ( material.clearcoatRoughness !== undefined ) {
- materialClearcoatRoughness.setValue( material.clearcoatRoughness );
- }
- if ( material.vertexColors !== undefined ) {
- materialVertexColors.setValue( material.vertexColors );
- }
- if ( material.depthPacking !== undefined ) {
- materialDepthPacking.setValue( material.depthPacking );
- }
- if ( material.skinning !== undefined ) {
- materialSkinning.setValue( material.skinning );
- }
- if ( material.map !== undefined ) {
- materialMapEnabled.setValue( material.map !== null );
- if ( material.map !== null || resetTextureSelectors ) {
- materialMap.setValue( material.map );
- }
- }
- if ( material.matcap !== undefined ) {
- materialMatcapMapEnabled.setValue( material.matcap !== null );
- if ( material.matcap !== null || resetTextureSelectors ) {
- materialMatcapMap.setValue( material.matcap );
- }
- }
- if ( material.alphaMap !== undefined ) {
- materialAlphaMapEnabled.setValue( material.alphaMap !== null );
- if ( material.alphaMap !== null || resetTextureSelectors ) {
- materialAlphaMap.setValue( material.alphaMap );
- }
- }
- if ( material.bumpMap !== undefined ) {
- materialBumpMapEnabled.setValue( material.bumpMap !== null );
- if ( material.bumpMap !== null || resetTextureSelectors ) {
- materialBumpMap.setValue( material.bumpMap );
- }
- materialBumpScale.setValue( material.bumpScale );
- }
- if ( material.normalMap !== undefined ) {
- materialNormalMapEnabled.setValue( material.normalMap !== null );
- if ( material.normalMap !== null || resetTextureSelectors ) {
- materialNormalMap.setValue( material.normalMap );
- }
- materialNormalScaleX.setValue( material.normalScale.x );
- materialNormalScaleY.setValue( material.normalScale.y );
- }
- if ( material.clearcoatNormalMap !== undefined ) {
- materialClearcoatNormalMapEnabled.setValue( material.clearcoatNormalMap !== null );
- if ( material.clearcoatNormalMap !== null || resetTextureSelectors ) {
- materialClearcoatNormalMap.setValue( material.clearcoatNormalMap );
- }
- materialClearcoatNormalScaleX.setValue( material.clearcoatNormalScale.x );
- materialClearcoatNormalScaleY.setValue( material.clearcoatNormalScale.y );
- }
- if ( material.displacementMap !== undefined ) {
- materialDisplacementMapEnabled.setValue( material.displacementMap !== null );
- if ( material.displacementMap !== null || resetTextureSelectors ) {
- materialDisplacementMap.setValue( material.displacementMap );
- }
- materialDisplacementScale.setValue( material.displacementScale );
- }
- if ( material.roughnessMap !== undefined ) {
- materialRoughnessMapEnabled.setValue( material.roughnessMap !== null );
- if ( material.roughnessMap !== null || resetTextureSelectors ) {
- materialRoughnessMap.setValue( material.roughnessMap );
- }
- }
- if ( material.metalnessMap !== undefined ) {
- materialMetalnessMapEnabled.setValue( material.metalnessMap !== null );
- if ( material.metalnessMap !== null || resetTextureSelectors ) {
- materialMetalnessMap.setValue( material.metalnessMap );
- }
- }
- if ( material.specularMap !== undefined ) {
- materialSpecularMapEnabled.setValue( material.specularMap !== null );
- if ( material.specularMap !== null || resetTextureSelectors ) {
- materialSpecularMap.setValue( material.specularMap );
- }
- }
- if ( material.envMap !== undefined ) {
- materialEnvMapEnabled.setValue( material.envMap !== null );
- if ( material.envMap !== null || resetTextureSelectors ) {
- materialEnvMap.setValue( material.envMap );
- }
- }
- if ( material.gradientMap !== undefined ) {
- materialGradientMapEnabled.setValue( material.gradientMap !== null );
- if ( material.gradientMap !== null || resetTextureSelectors ) {
- materialGradientMap.setValue( material.gradientMap );
- }
- }
- if ( material.reflectivity !== undefined ) {
- materialReflectivity.setValue( material.reflectivity );
- }
- if ( material.lightMap !== undefined ) {
- materialLightMapEnabled.setValue( material.lightMap !== null );
- if ( material.lightMap !== null || resetTextureSelectors ) {
- materialLightMap.setValue( material.lightMap );
- }
- }
- if ( material.aoMap !== undefined ) {
- materialAOMapEnabled.setValue( material.aoMap !== null );
- if ( material.aoMap !== null || resetTextureSelectors ) {
- materialAOMap.setValue( material.aoMap );
- }
- materialAOScale.setValue( material.aoMapIntensity );
- }
- if ( material.emissiveMap !== undefined ) {
- materialEmissiveMapEnabled.setValue( material.emissiveMap !== null );
- if ( material.emissiveMap !== null || resetTextureSelectors ) {
- materialEmissiveMap.setValue( material.emissiveMap );
- }
- }
- if ( material.side !== undefined ) {
- materialSide.setValue( material.side );
- }
- if ( material.size !== undefined ) {
- materialSize.setValue( material.size );
- }
- if ( material.sizeAttenuation !== undefined ) {
- materialSizeAttenuation.setValue( material.sizeAttenuation );
- }
- if ( material.flatShading !== undefined ) {
- materialShading.setValue( material.flatShading );
- }
- if ( material.blending !== undefined ) {
- materialBlending.setValue( material.blending );
- }
- if ( material.opacity !== undefined ) {
- materialOpacity.setValue( material.opacity );
- }
- if ( material.transparent !== undefined ) {
- materialTransparent.setValue( material.transparent );
- }
- if ( material.alphaTest !== undefined ) {
- materialAlphaTest.setValue( material.alphaTest );
- }
- if ( material.depthTest !== undefined ) {
- materialDepthTest.setValue( material.depthTest );
- }
- if ( material.depthWrite !== undefined ) {
- materialDepthWrite.setValue( material.depthWrite );
- }
- if ( material.wireframe !== undefined ) {
- materialWireframe.setValue( material.wireframe );
- }
- setRowVisibility();
- }
- // events
- signals.objectSelected.add( function ( object ) {
- var hasMaterial = false;
- if ( object && object.material ) {
- hasMaterial = true;
- if ( Array.isArray( object.material ) && object.material.length === 0 ) {
- hasMaterial = false;
- }
- }
- if ( hasMaterial ) {
- var objectChanged = object !== currentObject;
- currentObject = object;
- refreshUI( objectChanged );
- container.setDisplay( '' );
- } else {
- currentObject = null;
- container.setDisplay( 'none' );
- }
- } );
- signals.materialChanged.add( function () {
- refreshUI();
- } );
- var vertexShaderVariables = [
- 'uniform mat4 projectionMatrix;',
- 'uniform mat4 modelViewMatrix;\n',
- 'attribute vec3 position;\n\n',
- ].join( '\n' );
- var meshMaterialOptions = {
- 'MeshBasicMaterial': 'MeshBasicMaterial',
- 'MeshDepthMaterial': 'MeshDepthMaterial',
- 'MeshNormalMaterial': 'MeshNormalMaterial',
- 'MeshLambertMaterial': 'MeshLambertMaterial',
- 'MeshMatcapMaterial': 'MeshMatcapMaterial',
- 'MeshPhongMaterial': 'MeshPhongMaterial',
- 'MeshToonMaterial': 'MeshToonMaterial',
- 'MeshStandardMaterial': 'MeshStandardMaterial',
- 'MeshPhysicalMaterial': 'MeshPhysicalMaterial',
- 'RawShaderMaterial': 'RawShaderMaterial',
- 'ShaderMaterial': 'ShaderMaterial',
- 'ShadowMaterial': 'ShadowMaterial'
- };
- var lineMaterialOptions = {
- 'LineBasicMaterial': 'LineBasicMaterial',
- 'LineDashedMaterial': 'LineDashedMaterial',
- 'RawShaderMaterial': 'RawShaderMaterial',
- 'ShaderMaterial': 'ShaderMaterial'
- };
- var spriteMaterialOptions = {
- 'SpriteMaterial': 'SpriteMaterial',
- 'RawShaderMaterial': 'RawShaderMaterial',
- 'ShaderMaterial': 'ShaderMaterial'
- };
- var pointsMaterialOptions = {
- 'PointsMaterial': 'PointsMaterial',
- 'RawShaderMaterial': 'RawShaderMaterial',
- 'ShaderMaterial': 'ShaderMaterial'
- };
- return container;
- }
- export { SidebarMaterial };
|