Sidebar.Object.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. import * as THREE from 'three';
  2. import { UIPanel, UIRow, UIInput, UIButton, UIColor, UICheckbox, UIInteger, UITextArea, UIText, UINumber } from './libs/ui.js';
  3. import { UIBoolean } from './libs/ui.three.js';
  4. import { SetUuidCommand } from './commands/SetUuidCommand.js';
  5. import { SetValueCommand } from './commands/SetValueCommand.js';
  6. import { SetPositionCommand } from './commands/SetPositionCommand.js';
  7. import { SetRotationCommand } from './commands/SetRotationCommand.js';
  8. import { SetScaleCommand } from './commands/SetScaleCommand.js';
  9. import { SetColorCommand } from './commands/SetColorCommand.js';
  10. import { SetShadowValueCommand } from './commands/SetShadowValueCommand.js';
  11. import { SidebarObjectAnimation } from './Sidebar.Object.Animation.js';
  12. function SidebarObject( editor ) {
  13. const strings = editor.strings;
  14. const signals = editor.signals;
  15. const container = new UIPanel();
  16. container.setBorderTop( '0' );
  17. container.setPaddingTop( '20px' );
  18. container.setDisplay( 'none' );
  19. // Actions
  20. /*
  21. let objectActions = new UI.Select().setPosition( 'absolute' ).setRight( '8px' ).setFontSize( '11px' );
  22. objectActions.setOptions( {
  23. 'Actions': 'Actions',
  24. 'Reset Position': 'Reset Position',
  25. 'Reset Rotation': 'Reset Rotation',
  26. 'Reset Scale': 'Reset Scale'
  27. } );
  28. objectActions.onClick( function ( event ) {
  29. event.stopPropagation(); // Avoid panel collapsing
  30. } );
  31. objectActions.onChange( function ( event ) {
  32. let object = editor.selected;
  33. switch ( this.getValue() ) {
  34. case 'Reset Position':
  35. editor.execute( new SetPositionCommand( editor, object, new Vector3( 0, 0, 0 ) ) );
  36. break;
  37. case 'Reset Rotation':
  38. editor.execute( new SetRotationCommand( editor, object, new Euler( 0, 0, 0 ) ) );
  39. break;
  40. case 'Reset Scale':
  41. editor.execute( new SetScaleCommand( editor, object, new Vector3( 1, 1, 1 ) ) );
  42. break;
  43. }
  44. this.setValue( 'Actions' );
  45. } );
  46. container.addStatic( objectActions );
  47. */
  48. // type
  49. const objectTypeRow = new UIRow();
  50. const objectType = new UIText();
  51. objectTypeRow.add( new UIText( strings.getKey( 'sidebar/object/type' ) ).setClass( 'Label' ) );
  52. objectTypeRow.add( objectType );
  53. container.add( objectTypeRow );
  54. // uuid
  55. const objectUUIDRow = new UIRow();
  56. const objectUUID = new UIInput().setWidth( '102px' ).setFontSize( '12px' ).setDisabled( true );
  57. const objectUUIDRenew = new UIButton( strings.getKey( 'sidebar/object/new' ) ).setMarginLeft( '7px' ).onClick( function () {
  58. objectUUID.setValue( THREE.MathUtils.generateUUID() );
  59. editor.execute( new SetUuidCommand( editor, editor.selected, objectUUID.getValue() ) );
  60. } );
  61. objectUUIDRow.add( new UIText( strings.getKey( 'sidebar/object/uuid' ) ).setClass( 'Label' ) );
  62. objectUUIDRow.add( objectUUID );
  63. objectUUIDRow.add( objectUUIDRenew );
  64. container.add( objectUUIDRow );
  65. // name
  66. const objectNameRow = new UIRow();
  67. const objectName = new UIInput().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
  68. editor.execute( new SetValueCommand( editor, editor.selected, 'name', objectName.getValue() ) );
  69. } );
  70. objectNameRow.add( new UIText( strings.getKey( 'sidebar/object/name' ) ).setClass( 'Label' ) );
  71. objectNameRow.add( objectName );
  72. container.add( objectNameRow );
  73. // position
  74. const objectPositionRow = new UIRow();
  75. const objectPositionX = new UINumber().setPrecision( 3 ).setWidth( '50px' ).onChange( update );
  76. const objectPositionY = new UINumber().setPrecision( 3 ).setWidth( '50px' ).onChange( update );
  77. const objectPositionZ = new UINumber().setPrecision( 3 ).setWidth( '50px' ).onChange( update );
  78. objectPositionRow.add( new UIText( strings.getKey( 'sidebar/object/position' ) ).setClass( 'Label' ) );
  79. objectPositionRow.add( objectPositionX, objectPositionY, objectPositionZ );
  80. container.add( objectPositionRow );
  81. // rotation
  82. const objectRotationRow = new UIRow();
  83. const objectRotationX = new UINumber().setStep( 10 ).setNudge( 0.1 ).setUnit( '°' ).setWidth( '50px' ).onChange( update );
  84. const objectRotationY = new UINumber().setStep( 10 ).setNudge( 0.1 ).setUnit( '°' ).setWidth( '50px' ).onChange( update );
  85. const objectRotationZ = new UINumber().setStep( 10 ).setNudge( 0.1 ).setUnit( '°' ).setWidth( '50px' ).onChange( update );
  86. objectRotationRow.add( new UIText( strings.getKey( 'sidebar/object/rotation' ) ).setClass( 'Label' ) );
  87. objectRotationRow.add( objectRotationX, objectRotationY, objectRotationZ );
  88. container.add( objectRotationRow );
  89. // scale
  90. const objectScaleRow = new UIRow();
  91. const objectScaleX = new UINumber( 1 ).setPrecision( 3 ).setWidth( '50px' ).onChange( update );
  92. const objectScaleY = new UINumber( 1 ).setPrecision( 3 ).setWidth( '50px' ).onChange( update );
  93. const objectScaleZ = new UINumber( 1 ).setPrecision( 3 ).setWidth( '50px' ).onChange( update );
  94. objectScaleRow.add( new UIText( strings.getKey( 'sidebar/object/scale' ) ).setClass( 'Label' ) );
  95. objectScaleRow.add( objectScaleX, objectScaleY, objectScaleZ );
  96. container.add( objectScaleRow );
  97. // fov
  98. const objectFovRow = new UIRow();
  99. const objectFov = new UINumber().onChange( update );
  100. objectFovRow.add( new UIText( strings.getKey( 'sidebar/object/fov' ) ).setClass( 'Label' ) );
  101. objectFovRow.add( objectFov );
  102. container.add( objectFovRow );
  103. // left
  104. const objectLeftRow = new UIRow();
  105. const objectLeft = new UINumber().onChange( update );
  106. objectLeftRow.add( new UIText( strings.getKey( 'sidebar/object/left' ) ).setClass( 'Label' ) );
  107. objectLeftRow.add( objectLeft );
  108. container.add( objectLeftRow );
  109. // right
  110. const objectRightRow = new UIRow();
  111. const objectRight = new UINumber().onChange( update );
  112. objectRightRow.add( new UIText( strings.getKey( 'sidebar/object/right' ) ).setClass( 'Label' ) );
  113. objectRightRow.add( objectRight );
  114. container.add( objectRightRow );
  115. // top
  116. const objectTopRow = new UIRow();
  117. const objectTop = new UINumber().onChange( update );
  118. objectTopRow.add( new UIText( strings.getKey( 'sidebar/object/top' ) ).setClass( 'Label' ) );
  119. objectTopRow.add( objectTop );
  120. container.add( objectTopRow );
  121. // bottom
  122. const objectBottomRow = new UIRow();
  123. const objectBottom = new UINumber().onChange( update );
  124. objectBottomRow.add( new UIText( strings.getKey( 'sidebar/object/bottom' ) ).setClass( 'Label' ) );
  125. objectBottomRow.add( objectBottom );
  126. container.add( objectBottomRow );
  127. // near
  128. const objectNearRow = new UIRow();
  129. const objectNear = new UINumber().onChange( update );
  130. objectNearRow.add( new UIText( strings.getKey( 'sidebar/object/near' ) ).setClass( 'Label' ) );
  131. objectNearRow.add( objectNear );
  132. container.add( objectNearRow );
  133. // far
  134. const objectFarRow = new UIRow();
  135. const objectFar = new UINumber().onChange( update );
  136. objectFarRow.add( new UIText( strings.getKey( 'sidebar/object/far' ) ).setClass( 'Label' ) );
  137. objectFarRow.add( objectFar );
  138. container.add( objectFarRow );
  139. // intensity
  140. const objectIntensityRow = new UIRow();
  141. const objectIntensity = new UINumber().onChange( update );
  142. objectIntensityRow.add( new UIText( strings.getKey( 'sidebar/object/intensity' ) ).setClass( 'Label' ) );
  143. objectIntensityRow.add( objectIntensity );
  144. container.add( objectIntensityRow );
  145. // color
  146. const objectColorRow = new UIRow();
  147. const objectColor = new UIColor().onInput( update );
  148. objectColorRow.add( new UIText( strings.getKey( 'sidebar/object/color' ) ).setClass( 'Label' ) );
  149. objectColorRow.add( objectColor );
  150. container.add( objectColorRow );
  151. // ground color
  152. const objectGroundColorRow = new UIRow();
  153. const objectGroundColor = new UIColor().onInput( update );
  154. objectGroundColorRow.add( new UIText( strings.getKey( 'sidebar/object/groundcolor' ) ).setClass( 'Label' ) );
  155. objectGroundColorRow.add( objectGroundColor );
  156. container.add( objectGroundColorRow );
  157. // distance
  158. const objectDistanceRow = new UIRow();
  159. const objectDistance = new UINumber().setRange( 0, Infinity ).onChange( update );
  160. objectDistanceRow.add( new UIText( strings.getKey( 'sidebar/object/distance' ) ).setClass( 'Label' ) );
  161. objectDistanceRow.add( objectDistance );
  162. container.add( objectDistanceRow );
  163. // angle
  164. const objectAngleRow = new UIRow();
  165. const objectAngle = new UINumber().setPrecision( 3 ).setRange( 0, Math.PI / 2 ).onChange( update );
  166. objectAngleRow.add( new UIText( strings.getKey( 'sidebar/object/angle' ) ).setClass( 'Label' ) );
  167. objectAngleRow.add( objectAngle );
  168. container.add( objectAngleRow );
  169. // penumbra
  170. const objectPenumbraRow = new UIRow();
  171. const objectPenumbra = new UINumber().setRange( 0, 1 ).onChange( update );
  172. objectPenumbraRow.add( new UIText( strings.getKey( 'sidebar/object/penumbra' ) ).setClass( 'Label' ) );
  173. objectPenumbraRow.add( objectPenumbra );
  174. container.add( objectPenumbraRow );
  175. // decay
  176. const objectDecayRow = new UIRow();
  177. const objectDecay = new UINumber().setRange( 0, Infinity ).onChange( update );
  178. objectDecayRow.add( new UIText( strings.getKey( 'sidebar/object/decay' ) ).setClass( 'Label' ) );
  179. objectDecayRow.add( objectDecay );
  180. container.add( objectDecayRow );
  181. // shadow
  182. const objectShadowRow = new UIRow();
  183. objectShadowRow.add( new UIText( strings.getKey( 'sidebar/object/shadow' ) ).setClass( 'Label' ) );
  184. const objectCastShadow = new UIBoolean( false, strings.getKey( 'sidebar/object/cast' ) ).onChange( update );
  185. objectShadowRow.add( objectCastShadow );
  186. const objectReceiveShadow = new UIBoolean( false, strings.getKey( 'sidebar/object/receive' ) ).onChange( update );
  187. objectShadowRow.add( objectReceiveShadow );
  188. container.add( objectShadowRow );
  189. // shadow intensity
  190. const objectShadowIntensityRow = new UIRow();
  191. objectShadowIntensityRow.add( new UIText( strings.getKey( 'sidebar/object/shadowIntensity' ) ).setClass( 'Label' ) );
  192. const objectShadowIntensity = new UINumber( 0 ).setRange( 0, 1 ).onChange( update );
  193. objectShadowIntensityRow.add( objectShadowIntensity );
  194. container.add( objectShadowIntensityRow );
  195. // shadow bias
  196. const objectShadowBiasRow = new UIRow();
  197. objectShadowBiasRow.add( new UIText( strings.getKey( 'sidebar/object/shadowBias' ) ).setClass( 'Label' ) );
  198. const objectShadowBias = new UINumber( 0 ).setPrecision( 5 ).setStep( 0.0001 ).setNudge( 0.00001 ).onChange( update );
  199. objectShadowBiasRow.add( objectShadowBias );
  200. container.add( objectShadowBiasRow );
  201. // shadow normal offset
  202. const objectShadowNormalBiasRow = new UIRow();
  203. objectShadowNormalBiasRow.add( new UIText( strings.getKey( 'sidebar/object/shadowNormalBias' ) ).setClass( 'Label' ) );
  204. const objectShadowNormalBias = new UINumber( 0 ).onChange( update );
  205. objectShadowNormalBiasRow.add( objectShadowNormalBias );
  206. container.add( objectShadowNormalBiasRow );
  207. // shadow radius
  208. const objectShadowRadiusRow = new UIRow();
  209. objectShadowRadiusRow.add( new UIText( strings.getKey( 'sidebar/object/shadowRadius' ) ).setClass( 'Label' ) );
  210. const objectShadowRadius = new UINumber( 1 ).onChange( update );
  211. objectShadowRadiusRow.add( objectShadowRadius );
  212. container.add( objectShadowRadiusRow );
  213. // visible
  214. const objectVisibleRow = new UIRow();
  215. const objectVisible = new UICheckbox().onChange( update );
  216. objectVisibleRow.add( new UIText( strings.getKey( 'sidebar/object/visible' ) ).setClass( 'Label' ) );
  217. objectVisibleRow.add( objectVisible );
  218. container.add( objectVisibleRow );
  219. // frustumCulled
  220. const objectFrustumCulledRow = new UIRow();
  221. const objectFrustumCulled = new UICheckbox().onChange( update );
  222. objectFrustumCulledRow.add( new UIText( strings.getKey( 'sidebar/object/frustumcull' ) ).setClass( 'Label' ) );
  223. objectFrustumCulledRow.add( objectFrustumCulled );
  224. container.add( objectFrustumCulledRow );
  225. // renderOrder
  226. const objectRenderOrderRow = new UIRow();
  227. const objectRenderOrder = new UIInteger().setWidth( '50px' ).onChange( update );
  228. objectRenderOrderRow.add( new UIText( strings.getKey( 'sidebar/object/renderorder' ) ).setClass( 'Label' ) );
  229. objectRenderOrderRow.add( objectRenderOrder );
  230. container.add( objectRenderOrderRow );
  231. // user data
  232. const objectUserDataRow = new UIRow();
  233. const objectUserData = new UITextArea().setWidth( '150px' ).setHeight( '40px' ).setFontSize( '12px' ).onChange( update );
  234. objectUserData.onKeyUp( function () {
  235. try {
  236. JSON.parse( objectUserData.getValue() );
  237. objectUserData.dom.classList.add( 'success' );
  238. objectUserData.dom.classList.remove( 'fail' );
  239. } catch ( error ) {
  240. objectUserData.dom.classList.remove( 'success' );
  241. objectUserData.dom.classList.add( 'fail' );
  242. }
  243. } );
  244. objectUserDataRow.add( new UIText( strings.getKey( 'sidebar/object/userdata' ) ).setClass( 'Label' ) );
  245. objectUserDataRow.add( objectUserData );
  246. container.add( objectUserDataRow );
  247. // Export JSON
  248. const exportJson = new UIButton( strings.getKey( 'sidebar/object/export' ) );
  249. exportJson.setMarginLeft( '120px' );
  250. exportJson.onClick( function () {
  251. const object = editor.selected;
  252. let output = object.toJSON();
  253. try {
  254. output = JSON.stringify( output, null, '\t' );
  255. output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
  256. } catch ( e ) {
  257. output = JSON.stringify( output );
  258. }
  259. editor.utils.save( new Blob( [ output ] ), `${ objectName.getValue() || 'object' }.json` );
  260. } );
  261. container.add( exportJson );
  262. // Animations
  263. container.add( new SidebarObjectAnimation( editor ) );
  264. //
  265. function update() {
  266. const object = editor.selected;
  267. if ( object !== null ) {
  268. const newPosition = new THREE.Vector3( objectPositionX.getValue(), objectPositionY.getValue(), objectPositionZ.getValue() );
  269. if ( object.position.distanceTo( newPosition ) >= 0.01 ) {
  270. editor.execute( new SetPositionCommand( editor, object, newPosition ) );
  271. }
  272. const newRotation = new THREE.Euler( objectRotationX.getValue() * THREE.MathUtils.DEG2RAD, objectRotationY.getValue() * THREE.MathUtils.DEG2RAD, objectRotationZ.getValue() * THREE.MathUtils.DEG2RAD );
  273. if ( new THREE.Vector3().setFromEuler( object.rotation ).distanceTo( new THREE.Vector3().setFromEuler( newRotation ) ) >= 0.01 ) {
  274. editor.execute( new SetRotationCommand( editor, object, newRotation ) );
  275. }
  276. const newScale = new THREE.Vector3( objectScaleX.getValue(), objectScaleY.getValue(), objectScaleZ.getValue() );
  277. if ( object.scale.distanceTo( newScale ) >= 0.01 ) {
  278. editor.execute( new SetScaleCommand( editor, object, newScale ) );
  279. }
  280. if ( object.fov !== undefined && Math.abs( object.fov - objectFov.getValue() ) >= 0.01 ) {
  281. editor.execute( new SetValueCommand( editor, object, 'fov', objectFov.getValue() ) );
  282. object.updateProjectionMatrix();
  283. }
  284. if ( object.left !== undefined && Math.abs( object.left - objectLeft.getValue() ) >= 0.01 ) {
  285. editor.execute( new SetValueCommand( editor, object, 'left', objectLeft.getValue() ) );
  286. object.updateProjectionMatrix();
  287. }
  288. if ( object.right !== undefined && Math.abs( object.right - objectRight.getValue() ) >= 0.01 ) {
  289. editor.execute( new SetValueCommand( editor, object, 'right', objectRight.getValue() ) );
  290. object.updateProjectionMatrix();
  291. }
  292. if ( object.top !== undefined && Math.abs( object.top - objectTop.getValue() ) >= 0.01 ) {
  293. editor.execute( new SetValueCommand( editor, object, 'top', objectTop.getValue() ) );
  294. object.updateProjectionMatrix();
  295. }
  296. if ( object.bottom !== undefined && Math.abs( object.bottom - objectBottom.getValue() ) >= 0.01 ) {
  297. editor.execute( new SetValueCommand( editor, object, 'bottom', objectBottom.getValue() ) );
  298. object.updateProjectionMatrix();
  299. }
  300. if ( object.near !== undefined && Math.abs( object.near - objectNear.getValue() ) >= 0.01 ) {
  301. editor.execute( new SetValueCommand( editor, object, 'near', objectNear.getValue() ) );
  302. if ( object.isOrthographicCamera ) {
  303. object.updateProjectionMatrix();
  304. }
  305. }
  306. if ( object.far !== undefined && Math.abs( object.far - objectFar.getValue() ) >= 0.01 ) {
  307. editor.execute( new SetValueCommand( editor, object, 'far', objectFar.getValue() ) );
  308. if ( object.isOrthographicCamera ) {
  309. object.updateProjectionMatrix();
  310. }
  311. }
  312. if ( object.intensity !== undefined && Math.abs( object.intensity - objectIntensity.getValue() ) >= 0.01 ) {
  313. editor.execute( new SetValueCommand( editor, object, 'intensity', objectIntensity.getValue() ) );
  314. }
  315. if ( object.color !== undefined && object.color.getHex() !== objectColor.getHexValue() ) {
  316. editor.execute( new SetColorCommand( editor, object, 'color', objectColor.getHexValue() ) );
  317. }
  318. if ( object.groundColor !== undefined && object.groundColor.getHex() !== objectGroundColor.getHexValue() ) {
  319. editor.execute( new SetColorCommand( editor, object, 'groundColor', objectGroundColor.getHexValue() ) );
  320. }
  321. if ( object.distance !== undefined && Math.abs( object.distance - objectDistance.getValue() ) >= 0.01 ) {
  322. editor.execute( new SetValueCommand( editor, object, 'distance', objectDistance.getValue() ) );
  323. }
  324. if ( object.angle !== undefined && Math.abs( object.angle - objectAngle.getValue() ) >= 0.01 ) {
  325. editor.execute( new SetValueCommand( editor, object, 'angle', objectAngle.getValue() ) );
  326. }
  327. if ( object.penumbra !== undefined && Math.abs( object.penumbra - objectPenumbra.getValue() ) >= 0.01 ) {
  328. editor.execute( new SetValueCommand( editor, object, 'penumbra', objectPenumbra.getValue() ) );
  329. }
  330. if ( object.decay !== undefined && Math.abs( object.decay - objectDecay.getValue() ) >= 0.01 ) {
  331. editor.execute( new SetValueCommand( editor, object, 'decay', objectDecay.getValue() ) );
  332. }
  333. if ( object.visible !== objectVisible.getValue() ) {
  334. editor.execute( new SetValueCommand( editor, object, 'visible', objectVisible.getValue() ) );
  335. }
  336. if ( object.frustumCulled !== objectFrustumCulled.getValue() ) {
  337. editor.execute( new SetValueCommand( editor, object, 'frustumCulled', objectFrustumCulled.getValue() ) );
  338. }
  339. if ( object.renderOrder !== objectRenderOrder.getValue() ) {
  340. editor.execute( new SetValueCommand( editor, object, 'renderOrder', objectRenderOrder.getValue() ) );
  341. }
  342. if ( object.castShadow !== undefined && object.castShadow !== objectCastShadow.getValue() ) {
  343. editor.execute( new SetValueCommand( editor, object, 'castShadow', objectCastShadow.getValue() ) );
  344. }
  345. if ( object.receiveShadow !== objectReceiveShadow.getValue() ) {
  346. if ( object.material !== undefined ) object.material.needsUpdate = true;
  347. editor.execute( new SetValueCommand( editor, object, 'receiveShadow', objectReceiveShadow.getValue() ) );
  348. }
  349. if ( object.shadow !== undefined ) {
  350. if ( object.shadow.intensity !== objectShadowIntensity.getValue() ) {
  351. editor.execute( new SetShadowValueCommand( editor, object, 'intensity', objectShadowIntensity.getValue() ) );
  352. }
  353. if ( object.shadow.bias !== objectShadowBias.getValue() ) {
  354. editor.execute( new SetShadowValueCommand( editor, object, 'bias', objectShadowBias.getValue() ) );
  355. }
  356. if ( object.shadow.normalBias !== objectShadowNormalBias.getValue() ) {
  357. editor.execute( new SetShadowValueCommand( editor, object, 'normalBias', objectShadowNormalBias.getValue() ) );
  358. }
  359. if ( object.shadow.radius !== objectShadowRadius.getValue() ) {
  360. editor.execute( new SetShadowValueCommand( editor, object, 'radius', objectShadowRadius.getValue() ) );
  361. }
  362. }
  363. try {
  364. const userData = JSON.parse( objectUserData.getValue() );
  365. if ( JSON.stringify( object.userData ) != JSON.stringify( userData ) ) {
  366. editor.execute( new SetValueCommand( editor, object, 'userData', userData ) );
  367. }
  368. } catch ( exception ) {
  369. console.warn( exception );
  370. }
  371. }
  372. }
  373. function updateRows( object ) {
  374. const properties = {
  375. 'fov': objectFovRow,
  376. 'left': objectLeftRow,
  377. 'right': objectRightRow,
  378. 'top': objectTopRow,
  379. 'bottom': objectBottomRow,
  380. 'near': objectNearRow,
  381. 'far': objectFarRow,
  382. 'intensity': objectIntensityRow,
  383. 'color': objectColorRow,
  384. 'groundColor': objectGroundColorRow,
  385. 'distance': objectDistanceRow,
  386. 'angle': objectAngleRow,
  387. 'penumbra': objectPenumbraRow,
  388. 'decay': objectDecayRow,
  389. 'castShadow': objectShadowRow,
  390. 'receiveShadow': objectReceiveShadow,
  391. 'shadow': [ objectShadowIntensityRow, objectShadowBiasRow, objectShadowNormalBiasRow, objectShadowRadiusRow ]
  392. };
  393. for ( const property in properties ) {
  394. const uiElement = properties[ property ];
  395. if ( Array.isArray( uiElement ) === true ) {
  396. for ( let i = 0; i < uiElement.length; i ++ ) {
  397. uiElement[ i ].setDisplay( object[ property ] !== undefined ? '' : 'none' );
  398. }
  399. } else {
  400. uiElement.setDisplay( object[ property ] !== undefined ? '' : 'none' );
  401. }
  402. }
  403. //
  404. if ( object.isLight ) {
  405. objectReceiveShadow.setDisplay( 'none' );
  406. }
  407. if ( object.isAmbientLight || object.isHemisphereLight ) {
  408. objectShadowRow.setDisplay( 'none' );
  409. }
  410. }
  411. function updateTransformRows( object ) {
  412. if ( object.isLight ) {
  413. objectRotationRow.setDisplay( 'none' );
  414. objectScaleRow.setDisplay( 'none' );
  415. } else {
  416. objectRotationRow.setDisplay( '' );
  417. objectScaleRow.setDisplay( '' );
  418. }
  419. }
  420. // events
  421. signals.objectSelected.add( function ( object ) {
  422. if ( object !== null ) {
  423. container.setDisplay( 'block' );
  424. updateRows( object );
  425. updateUI( object );
  426. } else {
  427. container.setDisplay( 'none' );
  428. }
  429. } );
  430. signals.objectChanged.add( function ( object ) {
  431. if ( object !== editor.selected ) return;
  432. updateUI( object );
  433. } );
  434. signals.refreshSidebarObject3D.add( function ( object ) {
  435. if ( object !== editor.selected ) return;
  436. updateUI( object );
  437. } );
  438. function updateUI( object ) {
  439. objectType.setValue( object.type );
  440. objectUUID.setValue( object.uuid );
  441. objectName.setValue( object.name );
  442. objectPositionX.setValue( object.position.x );
  443. objectPositionY.setValue( object.position.y );
  444. objectPositionZ.setValue( object.position.z );
  445. objectRotationX.setValue( object.rotation.x * THREE.MathUtils.RAD2DEG );
  446. objectRotationY.setValue( object.rotation.y * THREE.MathUtils.RAD2DEG );
  447. objectRotationZ.setValue( object.rotation.z * THREE.MathUtils.RAD2DEG );
  448. objectScaleX.setValue( object.scale.x );
  449. objectScaleY.setValue( object.scale.y );
  450. objectScaleZ.setValue( object.scale.z );
  451. if ( object.fov !== undefined ) {
  452. objectFov.setValue( object.fov );
  453. }
  454. if ( object.left !== undefined ) {
  455. objectLeft.setValue( object.left );
  456. }
  457. if ( object.right !== undefined ) {
  458. objectRight.setValue( object.right );
  459. }
  460. if ( object.top !== undefined ) {
  461. objectTop.setValue( object.top );
  462. }
  463. if ( object.bottom !== undefined ) {
  464. objectBottom.setValue( object.bottom );
  465. }
  466. if ( object.near !== undefined ) {
  467. objectNear.setValue( object.near );
  468. }
  469. if ( object.far !== undefined ) {
  470. objectFar.setValue( object.far );
  471. }
  472. if ( object.intensity !== undefined ) {
  473. objectIntensity.setValue( object.intensity );
  474. }
  475. if ( object.color !== undefined ) {
  476. objectColor.setHexValue( object.color.getHexString() );
  477. }
  478. if ( object.groundColor !== undefined ) {
  479. objectGroundColor.setHexValue( object.groundColor.getHexString() );
  480. }
  481. if ( object.distance !== undefined ) {
  482. objectDistance.setValue( object.distance );
  483. }
  484. if ( object.angle !== undefined ) {
  485. objectAngle.setValue( object.angle );
  486. }
  487. if ( object.penumbra !== undefined ) {
  488. objectPenumbra.setValue( object.penumbra );
  489. }
  490. if ( object.decay !== undefined ) {
  491. objectDecay.setValue( object.decay );
  492. }
  493. if ( object.castShadow !== undefined ) {
  494. objectCastShadow.setValue( object.castShadow );
  495. }
  496. if ( object.receiveShadow !== undefined ) {
  497. objectReceiveShadow.setValue( object.receiveShadow );
  498. }
  499. if ( object.shadow !== undefined ) {
  500. objectShadowIntensity.setValue( object.shadow.intensity );
  501. objectShadowBias.setValue( object.shadow.bias );
  502. objectShadowNormalBias.setValue( object.shadow.normalBias );
  503. objectShadowRadius.setValue( object.shadow.radius );
  504. }
  505. objectVisible.setValue( object.visible );
  506. objectFrustumCulled.setValue( object.frustumCulled );
  507. objectRenderOrder.setValue( object.renderOrder );
  508. try {
  509. objectUserData.setValue( JSON.stringify( object.userData, null, ' ' ) );
  510. } catch ( error ) {
  511. console.log( error );
  512. }
  513. objectUserData.setBorderColor( 'transparent' );
  514. objectUserData.setBackgroundColor( '' );
  515. updateTransformRows( object );
  516. }
  517. return container;
  518. }
  519. export { SidebarObject };