render-texture.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. 'use strict';
  2. const { updateElementReadonly } = require('../utils/assets');
  3. const texture = require('./texture/texture');
  4. const insertTemplate = /* html */`
  5. <ui-prop>
  6. <ui-label slot="label" value="Width"></ui-label>
  7. <ui-num-input slot="content" class="width-input" min="1" step="1"></ui-num-input>
  8. </ui-prop>
  9. <ui-prop>
  10. <ui-label slot="label" value="Height"></ui-label>
  11. <ui-num-input slot="content" class="height-input" min="1" step="1"></ui-num-input>
  12. </ui-prop>
  13. `;
  14. exports.template = texture.template.replace('<!-- dont delete, for insert -->', insertTemplate);
  15. exports.style = texture.style;
  16. exports.$ = Object.assign({}, texture.$, {
  17. widthInput: '.width-input',
  18. heightInput: '.height-input',
  19. });
  20. const Elements = Object.assign({}, texture.Elements, {
  21. width: {
  22. ready() {
  23. const panel = this;
  24. panel.$.widthInput.addEventListener('change', (event) => {
  25. panel.userDataList.forEach((userData) => {
  26. userData.width = event.target.value;
  27. });
  28. panel.dispatch('change');
  29. });
  30. panel.$.widthInput.addEventListener('confirm', () => {
  31. panel.dispatch('snapshot');
  32. });
  33. },
  34. update() {
  35. const panel = this;
  36. panel.$.widthInput.value = panel.userData.width;
  37. panel.updateInvalid(panel.$.widthInput, 'width');
  38. updateElementReadonly.call(panel, panel.$.widthInput);
  39. },
  40. },
  41. height: {
  42. ready() {
  43. const panel = this;
  44. panel.$.heightInput.addEventListener('change', (event) => {
  45. panel.userDataList.forEach((userData) => {
  46. userData.height = event.target.value;
  47. });
  48. panel.dispatch('change');
  49. });
  50. panel.$.heightInput.addEventListener('confirm', () => {
  51. panel.dispatch('snapshot');
  52. });
  53. },
  54. update() {
  55. const panel = this;
  56. panel.$.heightInput.value = panel.userData.height;
  57. panel.updateInvalid(panel.$.heightInput, 'height');
  58. updateElementReadonly.call(panel, panel.$.heightInput);
  59. },
  60. },
  61. });
  62. exports.ready = function() {
  63. for (const prop in Elements) {
  64. const element = Elements[prop];
  65. if (element.ready) {
  66. element.ready.call(this);
  67. }
  68. }
  69. };
  70. exports.methods = Object.assign({}, texture.methods, {
  71. async apply() {
  72. await Editor.Message.request('scene', 'apply-render-texture', this.asset.uuid, this.userData);
  73. },
  74. });
  75. exports.update = function(assetList, metaList) {
  76. this.assetList = assetList;
  77. this.metaList = metaList;
  78. this.asset = this.assetList[0];
  79. this.meta = this.metaList[0];
  80. this.userData = this.meta.userData;
  81. this.userDataList = this.metaList.map((item) => item.userData);
  82. for (const prop in Elements) {
  83. const element = Elements[prop];
  84. if (element.update) {
  85. element.update.call(this);
  86. }
  87. }
  88. };