Sidebar.Object.js 21 KB

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