Sidebar.Object.js 22 KB

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