Sidebar.Object.js 22 KB

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