Sidebar.Object.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  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 objectScaleLock = new UICheckbox( true ).setPosition( 'absolute' ).setLeft( '75px' );
  90. var objectScaleX = new UINumber( 1 ).setPrecision( 3 ).setWidth( '50px' ).onChange( updateScaleX );
  91. var objectScaleY = new UINumber( 1 ).setPrecision( 3 ).setWidth( '50px' ).onChange( updateScaleY );
  92. var objectScaleZ = new UINumber( 1 ).setPrecision( 3 ).setWidth( '50px' ).onChange( updateScaleZ );
  93. objectScaleRow.add( new UIText( strings.getKey( 'sidebar/object/scale' ) ).setWidth( '90px' ) );
  94. objectScaleRow.add( objectScaleLock );
  95. objectScaleRow.add( objectScaleX, objectScaleY, objectScaleZ );
  96. container.add( objectScaleRow );
  97. // fov
  98. var objectFovRow = new UIRow();
  99. var objectFov = new UINumber().onChange( update );
  100. objectFovRow.add( new UIText( strings.getKey( 'sidebar/object/fov' ) ).setWidth( '90px' ) );
  101. objectFovRow.add( objectFov );
  102. container.add( objectFovRow );
  103. // left
  104. var objectLeftRow = new UIRow();
  105. var objectLeft = new UINumber().onChange( update );
  106. objectLeftRow.add( new UIText( strings.getKey( 'sidebar/object/left' ) ).setWidth( '90px' ) );
  107. objectLeftRow.add( objectLeft );
  108. container.add( objectLeftRow );
  109. // right
  110. var objectRightRow = new UIRow();
  111. var objectRight = new UINumber().onChange( update );
  112. objectRightRow.add( new UIText( strings.getKey( 'sidebar/object/right' ) ).setWidth( '90px' ) );
  113. objectRightRow.add( objectRight );
  114. container.add( objectRightRow );
  115. // top
  116. var objectTopRow = new UIRow();
  117. var objectTop = new UINumber().onChange( update );
  118. objectTopRow.add( new UIText( strings.getKey( 'sidebar/object/top' ) ).setWidth( '90px' ) );
  119. objectTopRow.add( objectTop );
  120. container.add( objectTopRow );
  121. // bottom
  122. var objectBottomRow = new UIRow();
  123. var objectBottom = new UINumber().onChange( update );
  124. objectBottomRow.add( new UIText( strings.getKey( 'sidebar/object/bottom' ) ).setWidth( '90px' ) );
  125. objectBottomRow.add( objectBottom );
  126. container.add( objectBottomRow );
  127. // near
  128. var objectNearRow = new UIRow();
  129. var objectNear = new UINumber().onChange( update );
  130. objectNearRow.add( new UIText( strings.getKey( 'sidebar/object/near' ) ).setWidth( '90px' ) );
  131. objectNearRow.add( objectNear );
  132. container.add( objectNearRow );
  133. // far
  134. var objectFarRow = new UIRow();
  135. var objectFar = new UINumber().onChange( update );
  136. objectFarRow.add( new UIText( strings.getKey( 'sidebar/object/far' ) ).setWidth( '90px' ) );
  137. objectFarRow.add( objectFar );
  138. container.add( objectFarRow );
  139. // intensity
  140. var objectIntensityRow = new UIRow();
  141. var objectIntensity = new UINumber().setRange( 0, Infinity ).onChange( update );
  142. objectIntensityRow.add( new UIText( strings.getKey( 'sidebar/object/intensity' ) ).setWidth( '90px' ) );
  143. objectIntensityRow.add( objectIntensity );
  144. container.add( objectIntensityRow );
  145. // color
  146. var objectColorRow = new UIRow();
  147. var objectColor = new UIColor().onChange( update );
  148. objectColorRow.add( new UIText( strings.getKey( 'sidebar/object/color' ) ).setWidth( '90px' ) );
  149. objectColorRow.add( objectColor );
  150. container.add( objectColorRow );
  151. // ground color
  152. var objectGroundColorRow = new UIRow();
  153. var objectGroundColor = new UIColor().onChange( update );
  154. objectGroundColorRow.add( new UIText( strings.getKey( 'sidebar/object/groundcolor' ) ).setWidth( '90px' ) );
  155. objectGroundColorRow.add( objectGroundColor );
  156. container.add( objectGroundColorRow );
  157. // distance
  158. var objectDistanceRow = new UIRow();
  159. var objectDistance = new UINumber().setRange( 0, Infinity ).onChange( update );
  160. objectDistanceRow.add( new UIText( strings.getKey( 'sidebar/object/distance' ) ).setWidth( '90px' ) );
  161. objectDistanceRow.add( objectDistance );
  162. container.add( objectDistanceRow );
  163. // angle
  164. var objectAngleRow = new UIRow();
  165. var objectAngle = new UINumber().setPrecision( 3 ).setRange( 0, Math.PI / 2 ).onChange( update );
  166. objectAngleRow.add( new UIText( strings.getKey( 'sidebar/object/angle' ) ).setWidth( '90px' ) );
  167. objectAngleRow.add( objectAngle );
  168. container.add( objectAngleRow );
  169. // penumbra
  170. var objectPenumbraRow = new UIRow();
  171. var objectPenumbra = new UINumber().setRange( 0, 1 ).onChange( update );
  172. objectPenumbraRow.add( new UIText( strings.getKey( 'sidebar/object/penumbra' ) ).setWidth( '90px' ) );
  173. objectPenumbraRow.add( objectPenumbra );
  174. container.add( objectPenumbraRow );
  175. // decay
  176. var objectDecayRow = new UIRow();
  177. var objectDecay = new UINumber().setRange( 0, Infinity ).onChange( update );
  178. objectDecayRow.add( new UIText( strings.getKey( 'sidebar/object/decay' ) ).setWidth( '90px' ) );
  179. objectDecayRow.add( objectDecay );
  180. container.add( objectDecayRow );
  181. // shadow
  182. var objectShadowRow = new UIRow();
  183. objectShadowRow.add( new UIText( strings.getKey( 'sidebar/object/shadow' ) ).setWidth( '90px' ) );
  184. var objectCastShadow = new UIBoolean( false, strings.getKey( 'sidebar/object/cast' ) ).onChange( update );
  185. objectShadowRow.add( objectCastShadow );
  186. var objectReceiveShadow = new UIBoolean( false, strings.getKey( 'sidebar/object/receive' ) ).onChange( update );
  187. objectShadowRow.add( objectReceiveShadow );
  188. container.add( objectShadowRow );
  189. // shadow bias
  190. var objectShadowBiasRow = new UIRow();
  191. objectShadowBiasRow.add( new UIText( strings.getKey( 'sidebar/object/shadowBias' ) ).setWidth( '90px' ) );
  192. var objectShadowBias = new UINumber( 0 ).setPrecision( 5 ).setStep( 0.0001 ).setNudge( 0.00001 ).onChange( update );
  193. objectShadowBiasRow.add( objectShadowBias );
  194. container.add( objectShadowBiasRow );
  195. // shadow normal offset
  196. var objectShadowNormalBiasRow = new UIRow();
  197. objectShadowNormalBiasRow.add( new UIText( strings.getKey( 'sidebar/object/shadowNormalBias' ) ).setWidth( '90px' ) );
  198. var objectShadowNormalBias = new UINumber( 0 ).onChange( update );
  199. objectShadowNormalBiasRow.add( objectShadowNormalBias );
  200. container.add( objectShadowNormalBiasRow );
  201. // shadow radius
  202. var objectShadowRadiusRow = new UIRow();
  203. objectShadowRadiusRow.add( new UIText( strings.getKey( 'sidebar/object/shadowRadius' ) ).setWidth( '90px' ) );
  204. var objectShadowRadius = new UINumber( 1 ).onChange( update );
  205. objectShadowRadiusRow.add( objectShadowRadius );
  206. container.add( objectShadowRadiusRow );
  207. // visible
  208. var objectVisibleRow = new UIRow();
  209. var objectVisible = new UICheckbox().onChange( update );
  210. objectVisibleRow.add( new UIText( strings.getKey( 'sidebar/object/visible' ) ).setWidth( '90px' ) );
  211. objectVisibleRow.add( objectVisible );
  212. container.add( objectVisibleRow );
  213. // frustumCulled
  214. var objectFrustumCulledRow = new UIRow();
  215. var objectFrustumCulled = new UICheckbox().onChange( update );
  216. objectFrustumCulledRow.add( new UIText( strings.getKey( 'sidebar/object/frustumcull' ) ).setWidth( '90px' ) );
  217. objectFrustumCulledRow.add( objectFrustumCulled );
  218. container.add( objectFrustumCulledRow );
  219. // renderOrder
  220. var objectRenderOrderRow = new UIRow();
  221. var objectRenderOrder = new UIInteger().setWidth( '50px' ).onChange( update );
  222. objectRenderOrderRow.add( new UIText( strings.getKey( 'sidebar/object/renderorder' ) ).setWidth( '90px' ) );
  223. objectRenderOrderRow.add( objectRenderOrder );
  224. container.add( objectRenderOrderRow );
  225. // user data
  226. var objectUserDataRow = new UIRow();
  227. var objectUserData = new UITextArea().setWidth( '150px' ).setHeight( '40px' ).setFontSize( '12px' ).onChange( update );
  228. objectUserData.onKeyUp( function () {
  229. try {
  230. JSON.parse( objectUserData.getValue() );
  231. objectUserData.dom.classList.add( 'success' );
  232. objectUserData.dom.classList.remove( 'fail' );
  233. } catch ( error ) {
  234. objectUserData.dom.classList.remove( 'success' );
  235. objectUserData.dom.classList.add( 'fail' );
  236. }
  237. } );
  238. objectUserDataRow.add( new UIText( strings.getKey( 'sidebar/object/userdata' ) ).setWidth( '90px' ) );
  239. objectUserDataRow.add( objectUserData );
  240. container.add( objectUserDataRow );
  241. //
  242. function updateScaleX() {
  243. var object = editor.selected;
  244. if ( objectScaleLock.getValue() === true ) {
  245. var scale = objectScaleX.getValue() / object.scale.x;
  246. objectScaleY.setValue( objectScaleY.getValue() * scale );
  247. objectScaleZ.setValue( objectScaleZ.getValue() * scale );
  248. }
  249. update();
  250. }
  251. function updateScaleY() {
  252. var object = editor.selected;
  253. if ( objectScaleLock.getValue() === true ) {
  254. var scale = objectScaleY.getValue() / object.scale.y;
  255. objectScaleX.setValue( objectScaleX.getValue() * scale );
  256. objectScaleZ.setValue( objectScaleZ.getValue() * scale );
  257. }
  258. update();
  259. }
  260. function updateScaleZ() {
  261. var object = editor.selected;
  262. if ( objectScaleLock.getValue() === true ) {
  263. var scale = objectScaleZ.getValue() / object.scale.z;
  264. objectScaleX.setValue( objectScaleX.getValue() * scale );
  265. objectScaleY.setValue( objectScaleY.getValue() * scale );
  266. }
  267. update();
  268. }
  269. function update() {
  270. var object = editor.selected;
  271. if ( object !== null ) {
  272. var newPosition = new THREE.Vector3( objectPositionX.getValue(), objectPositionY.getValue(), objectPositionZ.getValue() );
  273. if ( object.position.distanceTo( newPosition ) >= 0.01 ) {
  274. editor.execute( new SetPositionCommand( editor, object, newPosition ) );
  275. }
  276. var newRotation = new THREE.Euler( objectRotationX.getValue() * THREE.MathUtils.DEG2RAD, objectRotationY.getValue() * THREE.MathUtils.DEG2RAD, objectRotationZ.getValue() * THREE.MathUtils.DEG2RAD );
  277. if ( object.rotation.toVector3().distanceTo( newRotation.toVector3() ) >= 0.01 ) {
  278. editor.execute( new SetRotationCommand( editor, object, newRotation ) );
  279. }
  280. var newScale = new THREE.Vector3( objectScaleX.getValue(), objectScaleY.getValue(), objectScaleZ.getValue() );
  281. if ( object.scale.distanceTo( newScale ) >= 0.01 ) {
  282. editor.execute( new SetScaleCommand( editor, object, newScale ) );
  283. }
  284. if ( object.fov !== undefined && Math.abs( object.fov - objectFov.getValue() ) >= 0.01 ) {
  285. editor.execute( new SetValueCommand( editor, object, 'fov', objectFov.getValue() ) );
  286. object.updateProjectionMatrix();
  287. }
  288. if ( object.left !== undefined && Math.abs( object.left - objectLeft.getValue() ) >= 0.01 ) {
  289. editor.execute( new SetValueCommand( editor, object, 'left', objectLeft.getValue() ) );
  290. object.updateProjectionMatrix();
  291. }
  292. if ( object.right !== undefined && Math.abs( object.right - objectRight.getValue() ) >= 0.01 ) {
  293. editor.execute( new SetValueCommand( editor, object, 'right', objectRight.getValue() ) );
  294. object.updateProjectionMatrix();
  295. }
  296. if ( object.top !== undefined && Math.abs( object.top - objectTop.getValue() ) >= 0.01 ) {
  297. editor.execute( new SetValueCommand( editor, object, 'top', objectTop.getValue() ) );
  298. object.updateProjectionMatrix();
  299. }
  300. if ( object.bottom !== undefined && Math.abs( object.bottom - objectBottom.getValue() ) >= 0.01 ) {
  301. editor.execute( new SetValueCommand( editor, object, 'bottom', objectBottom.getValue() ) );
  302. object.updateProjectionMatrix();
  303. }
  304. if ( object.near !== undefined && Math.abs( object.near - objectNear.getValue() ) >= 0.01 ) {
  305. editor.execute( new SetValueCommand( editor, object, 'near', objectNear.getValue() ) );
  306. if ( object.isOrthographicCamera ) {
  307. object.updateProjectionMatrix();
  308. }
  309. }
  310. if ( object.far !== undefined && Math.abs( object.far - objectFar.getValue() ) >= 0.01 ) {
  311. editor.execute( new SetValueCommand( editor, object, 'far', objectFar.getValue() ) );
  312. if ( object.isOrthographicCamera ) {
  313. object.updateProjectionMatrix();
  314. }
  315. }
  316. if ( object.intensity !== undefined && Math.abs( object.intensity - objectIntensity.getValue() ) >= 0.01 ) {
  317. editor.execute( new SetValueCommand( editor, object, 'intensity', objectIntensity.getValue() ) );
  318. }
  319. if ( object.color !== undefined && object.color.getHex() !== objectColor.getHexValue() ) {
  320. editor.execute( new SetColorCommand( editor, object, 'color', objectColor.getHexValue() ) );
  321. }
  322. if ( object.groundColor !== undefined && object.groundColor.getHex() !== objectGroundColor.getHexValue() ) {
  323. editor.execute( new SetColorCommand( editor, object, 'groundColor', objectGroundColor.getHexValue() ) );
  324. }
  325. if ( object.distance !== undefined && Math.abs( object.distance - objectDistance.getValue() ) >= 0.01 ) {
  326. editor.execute( new SetValueCommand( editor, object, 'distance', objectDistance.getValue() ) );
  327. }
  328. if ( object.angle !== undefined && Math.abs( object.angle - objectAngle.getValue() ) >= 0.01 ) {
  329. editor.execute( new SetValueCommand( editor, object, 'angle', objectAngle.getValue() ) );
  330. }
  331. if ( object.penumbra !== undefined && Math.abs( object.penumbra - objectPenumbra.getValue() ) >= 0.01 ) {
  332. editor.execute( new SetValueCommand( editor, object, 'penumbra', objectPenumbra.getValue() ) );
  333. }
  334. if ( object.decay !== undefined && Math.abs( object.decay - objectDecay.getValue() ) >= 0.01 ) {
  335. editor.execute( new SetValueCommand( editor, object, 'decay', objectDecay.getValue() ) );
  336. }
  337. if ( object.visible !== objectVisible.getValue() ) {
  338. editor.execute( new SetValueCommand( editor, object, 'visible', objectVisible.getValue() ) );
  339. }
  340. if ( object.frustumCulled !== objectFrustumCulled.getValue() ) {
  341. editor.execute( new SetValueCommand( editor, object, 'frustumCulled', objectFrustumCulled.getValue() ) );
  342. }
  343. if ( object.renderOrder !== objectRenderOrder.getValue() ) {
  344. editor.execute( new SetValueCommand( editor, object, 'renderOrder', objectRenderOrder.getValue() ) );
  345. }
  346. if ( object.castShadow !== undefined && object.castShadow !== objectCastShadow.getValue() ) {
  347. editor.execute( new SetValueCommand( editor, object, 'castShadow', objectCastShadow.getValue() ) );
  348. }
  349. if ( object.receiveShadow !== undefined && object.receiveShadow !== objectReceiveShadow.getValue() ) {
  350. if ( object.material !== undefined ) object.material.needsUpdate = true;
  351. editor.execute( new SetValueCommand( editor, object, 'receiveShadow', objectReceiveShadow.getValue() ) );
  352. }
  353. if ( object.shadow !== undefined ) {
  354. if ( object.shadow.bias !== objectShadowBias.getValue() ) {
  355. editor.execute( new SetValueCommand( editor, object.shadow, 'bias', objectShadowBias.getValue() ) );
  356. }
  357. if ( object.shadow.normalBias !== objectShadowNormalBias.getValue() ) {
  358. editor.execute( new SetValueCommand( editor, object.shadow, 'normalBias', objectShadowNormalBias.getValue() ) );
  359. }
  360. if ( object.shadow.radius !== objectShadowRadius.getValue() ) {
  361. editor.execute( new SetValueCommand( editor, object.shadow, 'radius', objectShadowRadius.getValue() ) );
  362. }
  363. }
  364. try {
  365. var userData = JSON.parse( objectUserData.getValue() );
  366. if ( JSON.stringify( object.userData ) != JSON.stringify( userData ) ) {
  367. editor.execute( new SetValueCommand( editor, object, 'userData', userData ) );
  368. }
  369. } catch ( exception ) {
  370. console.warn( exception );
  371. }
  372. }
  373. }
  374. function updateRows( object ) {
  375. var properties = {
  376. 'fov': objectFovRow,
  377. 'left': objectLeftRow,
  378. 'right': objectRightRow,
  379. 'top': objectTopRow,
  380. 'bottom': objectBottomRow,
  381. 'near': objectNearRow,
  382. 'far': objectFarRow,
  383. 'intensity': objectIntensityRow,
  384. 'color': objectColorRow,
  385. 'groundColor': objectGroundColorRow,
  386. 'distance': objectDistanceRow,
  387. 'angle': objectAngleRow,
  388. 'penumbra': objectPenumbraRow,
  389. 'decay': objectDecayRow,
  390. 'castShadow': objectShadowRow,
  391. 'receiveShadow': objectReceiveShadow,
  392. 'shadow': [ objectShadowBiasRow, objectShadowNormalBiasRow, objectShadowRadiusRow ]
  393. };
  394. for ( var property in properties ) {
  395. var uiElement = properties[ property ];
  396. if ( Array.isArray( uiElement ) === true ) {
  397. for ( var i = 0; i < uiElement.length; i ++ ) {
  398. uiElement[ i ].setDisplay( object[ property ] !== undefined ? '' : 'none' );
  399. }
  400. } else {
  401. uiElement.setDisplay( object[ property ] !== undefined ? '' : 'none' );
  402. }
  403. }
  404. }
  405. function updateTransformRows( object ) {
  406. if ( object.isLight ||
  407. ( object.isObject3D && object.userData.targetInverse ) ) {
  408. objectRotationRow.setDisplay( 'none' );
  409. objectScaleRow.setDisplay( 'none' );
  410. } else {
  411. objectRotationRow.setDisplay( '' );
  412. objectScaleRow.setDisplay( '' );
  413. }
  414. }
  415. // events
  416. signals.objectSelected.add( function ( object ) {
  417. if ( object !== null ) {
  418. container.setDisplay( 'block' );
  419. updateRows( object );
  420. updateUI( object );
  421. } else {
  422. container.setDisplay( 'none' );
  423. }
  424. } );
  425. signals.objectChanged.add( function ( object ) {
  426. if ( object !== editor.selected ) return;
  427. updateUI( object );
  428. } );
  429. signals.refreshSidebarObject3D.add( function ( object ) {
  430. if ( object !== editor.selected ) return;
  431. updateUI( object );
  432. } );
  433. function updateUI( object ) {
  434. objectType.setValue( object.type );
  435. objectUUID.setValue( object.uuid );
  436. objectName.setValue( object.name );
  437. objectPositionX.setValue( object.position.x );
  438. objectPositionY.setValue( object.position.y );
  439. objectPositionZ.setValue( object.position.z );
  440. objectRotationX.setValue( object.rotation.x * THREE.MathUtils.RAD2DEG );
  441. objectRotationY.setValue( object.rotation.y * THREE.MathUtils.RAD2DEG );
  442. objectRotationZ.setValue( object.rotation.z * THREE.MathUtils.RAD2DEG );
  443. objectScaleX.setValue( object.scale.x );
  444. objectScaleY.setValue( object.scale.y );
  445. objectScaleZ.setValue( object.scale.z );
  446. if ( object.fov !== undefined ) {
  447. objectFov.setValue( object.fov );
  448. }
  449. if ( object.left !== undefined ) {
  450. objectLeft.setValue( object.left );
  451. }
  452. if ( object.right !== undefined ) {
  453. objectRight.setValue( object.right );
  454. }
  455. if ( object.top !== undefined ) {
  456. objectTop.setValue( object.top );
  457. }
  458. if ( object.bottom !== undefined ) {
  459. objectBottom.setValue( object.bottom );
  460. }
  461. if ( object.near !== undefined ) {
  462. objectNear.setValue( object.near );
  463. }
  464. if ( object.far !== undefined ) {
  465. objectFar.setValue( object.far );
  466. }
  467. if ( object.intensity !== undefined ) {
  468. objectIntensity.setValue( object.intensity );
  469. }
  470. if ( object.color !== undefined ) {
  471. objectColor.setHexValue( object.color.getHexString() );
  472. }
  473. if ( object.groundColor !== undefined ) {
  474. objectGroundColor.setHexValue( object.groundColor.getHexString() );
  475. }
  476. if ( object.distance !== undefined ) {
  477. objectDistance.setValue( object.distance );
  478. }
  479. if ( object.angle !== undefined ) {
  480. objectAngle.setValue( object.angle );
  481. }
  482. if ( object.penumbra !== undefined ) {
  483. objectPenumbra.setValue( object.penumbra );
  484. }
  485. if ( object.decay !== undefined ) {
  486. objectDecay.setValue( object.decay );
  487. }
  488. if ( object.castShadow !== undefined ) {
  489. objectCastShadow.setValue( object.castShadow );
  490. }
  491. if ( object.receiveShadow !== undefined ) {
  492. objectReceiveShadow.setValue( object.receiveShadow );
  493. }
  494. if ( object.shadow !== undefined ) {
  495. objectShadowBias.setValue( object.shadow.bias );
  496. objectShadowNormalBias.setValue( object.shadow.normalBias );
  497. objectShadowRadius.setValue( object.shadow.radius );
  498. }
  499. objectVisible.setValue( object.visible );
  500. objectFrustumCulled.setValue( object.frustumCulled );
  501. objectRenderOrder.setValue( object.renderOrder );
  502. try {
  503. objectUserData.setValue( JSON.stringify( object.userData, null, ' ' ) );
  504. } catch ( error ) {
  505. console.log( error );
  506. }
  507. objectUserData.setBorderColor( 'transparent' );
  508. objectUserData.setBackgroundColor( '' );
  509. updateTransformRows( object );
  510. }
  511. return container;
  512. }
  513. export { SidebarObject };
粤ICP备19079148号