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