Sidebar.Object.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  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 { SetShadowValueCommand } from './commands/SetShadowValueCommand.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 ( error ) {
  256. output = JSON.stringify( output );
  257. }
  258. editor.utils.save( new Blob( [ output ] ), `${ objectName.getValue() || 'object' }.json` );
  259. } );
  260. container.add( exportJson );
  261. //
  262. function update() {
  263. const object = editor.selected;
  264. if ( object !== null ) {
  265. const newPosition = new THREE.Vector3( objectPositionX.getValue(), objectPositionY.getValue(), objectPositionZ.getValue() );
  266. if ( object.position.distanceTo( newPosition ) >= 0.01 ) {
  267. editor.execute( new SetPositionCommand( editor, object, newPosition ) );
  268. }
  269. const newRotation = new THREE.Euler( objectRotationX.getValue() * THREE.MathUtils.DEG2RAD, objectRotationY.getValue() * THREE.MathUtils.DEG2RAD, objectRotationZ.getValue() * THREE.MathUtils.DEG2RAD );
  270. if ( new THREE.Vector3().setFromEuler( object.rotation ).distanceTo( new THREE.Vector3().setFromEuler( newRotation ) ) >= 0.01 ) {
  271. editor.execute( new SetRotationCommand( editor, object, newRotation ) );
  272. }
  273. const newScale = new THREE.Vector3( objectScaleX.getValue(), objectScaleY.getValue(), objectScaleZ.getValue() );
  274. if ( object.scale.distanceTo( newScale ) >= 0.01 ) {
  275. editor.execute( new SetScaleCommand( editor, object, newScale ) );
  276. }
  277. if ( object.fov !== undefined && Math.abs( object.fov - objectFov.getValue() ) >= 0.01 ) {
  278. editor.execute( new SetValueCommand( editor, object, 'fov', objectFov.getValue() ) );
  279. object.updateProjectionMatrix();
  280. }
  281. if ( object.left !== undefined && Math.abs( object.left - objectLeft.getValue() ) >= 0.01 ) {
  282. editor.execute( new SetValueCommand( editor, object, 'left', objectLeft.getValue() ) );
  283. object.updateProjectionMatrix();
  284. }
  285. if ( object.right !== undefined && Math.abs( object.right - objectRight.getValue() ) >= 0.01 ) {
  286. editor.execute( new SetValueCommand( editor, object, 'right', objectRight.getValue() ) );
  287. object.updateProjectionMatrix();
  288. }
  289. if ( object.top !== undefined && Math.abs( object.top - objectTop.getValue() ) >= 0.01 ) {
  290. editor.execute( new SetValueCommand( editor, object, 'top', objectTop.getValue() ) );
  291. object.updateProjectionMatrix();
  292. }
  293. if ( object.bottom !== undefined && Math.abs( object.bottom - objectBottom.getValue() ) >= 0.01 ) {
  294. editor.execute( new SetValueCommand( editor, object, 'bottom', objectBottom.getValue() ) );
  295. object.updateProjectionMatrix();
  296. }
  297. if ( object.near !== undefined && Math.abs( object.near - objectNear.getValue() ) >= 0.01 ) {
  298. editor.execute( new SetValueCommand( editor, object, 'near', objectNear.getValue() ) );
  299. if ( object.isOrthographicCamera ) {
  300. object.updateProjectionMatrix();
  301. }
  302. }
  303. if ( object.far !== undefined && Math.abs( object.far - objectFar.getValue() ) >= 0.01 ) {
  304. editor.execute( new SetValueCommand( editor, object, 'far', objectFar.getValue() ) );
  305. if ( object.isOrthographicCamera ) {
  306. object.updateProjectionMatrix();
  307. }
  308. }
  309. if ( object.intensity !== undefined && Math.abs( object.intensity - objectIntensity.getValue() ) >= 0.01 ) {
  310. editor.execute( new SetValueCommand( editor, object, 'intensity', objectIntensity.getValue() ) );
  311. }
  312. if ( object.color !== undefined && object.color.getHex() !== objectColor.getHexValue() ) {
  313. editor.execute( new SetColorCommand( editor, object, 'color', objectColor.getHexValue() ) );
  314. }
  315. if ( object.groundColor !== undefined && object.groundColor.getHex() !== objectGroundColor.getHexValue() ) {
  316. editor.execute( new SetColorCommand( editor, object, 'groundColor', objectGroundColor.getHexValue() ) );
  317. }
  318. if ( object.distance !== undefined && Math.abs( object.distance - objectDistance.getValue() ) >= 0.01 ) {
  319. editor.execute( new SetValueCommand( editor, object, 'distance', objectDistance.getValue() ) );
  320. }
  321. if ( object.angle !== undefined && Math.abs( object.angle - objectAngle.getValue() ) >= 0.01 ) {
  322. editor.execute( new SetValueCommand( editor, object, 'angle', objectAngle.getValue() ) );
  323. }
  324. if ( object.penumbra !== undefined && Math.abs( object.penumbra - objectPenumbra.getValue() ) >= 0.01 ) {
  325. editor.execute( new SetValueCommand( editor, object, 'penumbra', objectPenumbra.getValue() ) );
  326. }
  327. if ( object.decay !== undefined && Math.abs( object.decay - objectDecay.getValue() ) >= 0.01 ) {
  328. editor.execute( new SetValueCommand( editor, object, 'decay', objectDecay.getValue() ) );
  329. }
  330. if ( object.visible !== objectVisible.getValue() ) {
  331. editor.execute( new SetValueCommand( editor, object, 'visible', objectVisible.getValue() ) );
  332. }
  333. if ( object.frustumCulled !== objectFrustumCulled.getValue() ) {
  334. editor.execute( new SetValueCommand( editor, object, 'frustumCulled', objectFrustumCulled.getValue() ) );
  335. }
  336. if ( object.renderOrder !== objectRenderOrder.getValue() ) {
  337. editor.execute( new SetValueCommand( editor, object, 'renderOrder', objectRenderOrder.getValue() ) );
  338. }
  339. if ( object.castShadow !== undefined && object.castShadow !== objectCastShadow.getValue() ) {
  340. editor.execute( new SetValueCommand( editor, object, 'castShadow', objectCastShadow.getValue() ) );
  341. }
  342. if ( object.receiveShadow !== objectReceiveShadow.getValue() ) {
  343. if ( object.material !== undefined ) object.material.needsUpdate = true;
  344. editor.execute( new SetValueCommand( editor, object, 'receiveShadow', objectReceiveShadow.getValue() ) );
  345. }
  346. if ( object.shadow !== undefined ) {
  347. if ( object.shadow.intensity !== objectShadowIntensity.getValue() ) {
  348. editor.execute( new SetShadowValueCommand( editor, object, 'intensity', objectShadowIntensity.getValue() ) );
  349. }
  350. if ( object.shadow.bias !== objectShadowBias.getValue() ) {
  351. editor.execute( new SetShadowValueCommand( editor, object, 'bias', objectShadowBias.getValue() ) );
  352. }
  353. if ( object.shadow.normalBias !== objectShadowNormalBias.getValue() ) {
  354. editor.execute( new SetShadowValueCommand( editor, object, 'normalBias', objectShadowNormalBias.getValue() ) );
  355. }
  356. if ( object.shadow.radius !== objectShadowRadius.getValue() ) {
  357. editor.execute( new SetShadowValueCommand( editor, object, 'radius', objectShadowRadius.getValue() ) );
  358. }
  359. }
  360. try {
  361. const userData = JSON.parse( objectUserData.getValue() );
  362. if ( JSON.stringify( object.userData ) != JSON.stringify( userData ) ) {
  363. editor.execute( new SetValueCommand( editor, object, 'userData', userData ) );
  364. }
  365. } catch ( exception ) {
  366. console.warn( exception );
  367. }
  368. }
  369. }
  370. function updateRows( object ) {
  371. const properties = {
  372. 'fov': objectFovRow,
  373. 'left': objectLeftRow,
  374. 'right': objectRightRow,
  375. 'top': objectTopRow,
  376. 'bottom': objectBottomRow,
  377. 'near': objectNearRow,
  378. 'far': objectFarRow,
  379. 'intensity': objectIntensityRow,
  380. 'color': objectColorRow,
  381. 'groundColor': objectGroundColorRow,
  382. 'distance': objectDistanceRow,
  383. 'angle': objectAngleRow,
  384. 'penumbra': objectPenumbraRow,
  385. 'decay': objectDecayRow,
  386. 'castShadow': objectShadowRow,
  387. 'receiveShadow': objectReceiveShadow,
  388. 'shadow': [ objectShadowIntensityRow, objectShadowBiasRow, objectShadowNormalBiasRow, objectShadowRadiusRow ]
  389. };
  390. for ( const property in properties ) {
  391. const uiElement = properties[ property ];
  392. if ( Array.isArray( uiElement ) === true ) {
  393. for ( let i = 0; i < uiElement.length; i ++ ) {
  394. uiElement[ i ].setDisplay( object[ property ] !== undefined ? '' : 'none' );
  395. }
  396. } else {
  397. uiElement.setDisplay( object[ property ] !== undefined ? '' : 'none' );
  398. }
  399. }
  400. //
  401. if ( object.isLight ) {
  402. objectReceiveShadow.setDisplay( 'none' );
  403. }
  404. if ( object.isAmbientLight || object.isHemisphereLight ) {
  405. objectShadowRow.setDisplay( 'none' );
  406. }
  407. }
  408. function updateTransformRows( object ) {
  409. if ( object.isLight ) {
  410. objectRotationRow.setDisplay( 'none' );
  411. objectScaleRow.setDisplay( 'none' );
  412. } else {
  413. objectRotationRow.setDisplay( '' );
  414. objectScaleRow.setDisplay( '' );
  415. }
  416. }
  417. // events
  418. signals.objectSelected.add( function ( object ) {
  419. if ( object !== null ) {
  420. container.setDisplay( 'block' );
  421. updateRows( object );
  422. updateUI( object );
  423. } else {
  424. container.setDisplay( 'none' );
  425. }
  426. } );
  427. signals.objectChanged.add( function ( object ) {
  428. if ( object !== editor.selected ) return;
  429. updateUI( object );
  430. } );
  431. signals.refreshSidebarObject3D.add( function ( object ) {
  432. if ( object !== editor.selected ) return;
  433. updateUI( object );
  434. } );
  435. function updateUI( object ) {
  436. objectType.setValue( object.type );
  437. objectUUID.setValue( object.uuid );
  438. objectName.setValue( object.name );
  439. objectPositionX.setValue( object.position.x );
  440. objectPositionY.setValue( object.position.y );
  441. objectPositionZ.setValue( object.position.z );
  442. objectRotationX.setValue( object.rotation.x * THREE.MathUtils.RAD2DEG );
  443. objectRotationY.setValue( object.rotation.y * THREE.MathUtils.RAD2DEG );
  444. objectRotationZ.setValue( object.rotation.z * THREE.MathUtils.RAD2DEG );
  445. objectScaleX.setValue( object.scale.x );
  446. objectScaleY.setValue( object.scale.y );
  447. objectScaleZ.setValue( object.scale.z );
  448. if ( object.fov !== undefined ) {
  449. objectFov.setValue( object.fov );
  450. }
  451. if ( object.left !== undefined ) {
  452. objectLeft.setValue( object.left );
  453. }
  454. if ( object.right !== undefined ) {
  455. objectRight.setValue( object.right );
  456. }
  457. if ( object.top !== undefined ) {
  458. objectTop.setValue( object.top );
  459. }
  460. if ( object.bottom !== undefined ) {
  461. objectBottom.setValue( object.bottom );
  462. }
  463. if ( object.near !== undefined ) {
  464. objectNear.setValue( object.near );
  465. }
  466. if ( object.far !== undefined ) {
  467. objectFar.setValue( object.far );
  468. }
  469. if ( object.intensity !== undefined ) {
  470. objectIntensity.setValue( object.intensity );
  471. }
  472. if ( object.color !== undefined ) {
  473. objectColor.setHexValue( object.color.getHexString() );
  474. }
  475. if ( object.groundColor !== undefined ) {
  476. objectGroundColor.setHexValue( object.groundColor.getHexString() );
  477. }
  478. if ( object.distance !== undefined ) {
  479. objectDistance.setValue( object.distance );
  480. }
  481. if ( object.angle !== undefined ) {
  482. objectAngle.setValue( object.angle );
  483. }
  484. if ( object.penumbra !== undefined ) {
  485. objectPenumbra.setValue( object.penumbra );
  486. }
  487. if ( object.decay !== undefined ) {
  488. objectDecay.setValue( object.decay );
  489. }
  490. if ( object.castShadow !== undefined ) {
  491. objectCastShadow.setValue( object.castShadow );
  492. }
  493. if ( object.receiveShadow !== undefined ) {
  494. objectReceiveShadow.setValue( object.receiveShadow );
  495. }
  496. if ( object.shadow !== undefined ) {
  497. objectShadowIntensity.setValue( object.shadow.intensity );
  498. objectShadowBias.setValue( object.shadow.bias );
  499. objectShadowNormalBias.setValue( object.shadow.normalBias );
  500. objectShadowRadius.setValue( object.shadow.radius );
  501. }
  502. objectVisible.setValue( object.visible );
  503. objectFrustumCulled.setValue( object.frustumCulled );
  504. objectRenderOrder.setValue( object.renderOrder );
  505. try {
  506. objectUserData.setValue( JSON.stringify( object.userData, null, ' ' ) );
  507. } catch ( error ) {
  508. console.log( error );
  509. }
  510. objectUserData.setBorderColor( 'transparent' );
  511. objectUserData.setBackgroundColor( '' );
  512. updateTransformRows( object );
  513. }
  514. return container;
  515. }
  516. export { SidebarObject };
粤ICP备19079148号