render-pipeline.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. 'use strict';
  2. exports.template = /* html */`
  3. <section class="asset-render-pipeline">
  4. <ui-prop class="dump-prop" type="dump"></ui-prop>
  5. <ui-label class="multiple-warn-tip" value="i18n:ENGINE.assets.multipleWarning"></ui-label>
  6. </section>
  7. `;
  8. exports.style = /* css */`
  9. .asset-render-pipeline {
  10. padding-right: 4px;
  11. }
  12. .asset-render-pipeline[multiple-invalid] > *:not(.multiple-warn-tip) {
  13. display: none!important;
  14. }
  15. .asset-render-pipeline[multiple-invalid] > .multiple-warn-tip {
  16. display: block;
  17. }
  18. .asset-render-pipeline .multiple-warn-tip {
  19. display: none;
  20. text-align: center;
  21. color: var(--color-focus-contrast-weakest);
  22. margin-top: 8px;
  23. }
  24. `;
  25. exports.$ = {
  26. container: '.asset-render-pipeline',
  27. prop: '.dump-prop',
  28. };
  29. exports.methods = {
  30. record() {
  31. return JSON.stringify(this.pipeline);
  32. },
  33. async restore(record) {
  34. record = JSON.parse(record);
  35. if (!record || typeof record !== 'object') {
  36. return false;
  37. }
  38. this.pipeline = record;
  39. await this.change();
  40. return true;
  41. },
  42. async query(uuid) {
  43. return await Editor.Message.request('scene', 'query-render-pipeline', uuid);
  44. },
  45. async apply() {
  46. this.reset();
  47. await Editor.Message.request('scene', 'apply-render-pipeline', this.asset.uuid, this.pipeline);
  48. },
  49. abort() {
  50. this.reset();
  51. },
  52. reset() {
  53. /**
  54. * reset 环节只需把 uuid 清空
  55. * 会重新进入 panel.update 周期,根据 uuid 为空的条件,把 this.dirtyData.origin 重新填充
  56. */
  57. this.dirtyData.uuid = '';
  58. },
  59. async change() {
  60. this.pipeline = await Editor.Message.request('scene', 'change-render-pipeline', this.pipeline);
  61. this.updateInterface();
  62. this.setDirtyData();
  63. this.dispatch('change');
  64. },
  65. snapshot() {
  66. this.dispatch('snapshot');
  67. },
  68. updateInterface() {
  69. this.LoopUpdateReadonly(this.pipeline);
  70. this.$.prop.render(this.pipeline);
  71. },
  72. LoopUpdateReadonly(obj) {
  73. if (this.asset.readonly) {
  74. if (obj && 'readonly' in obj && 'value' in obj) {
  75. obj.readonly = true;
  76. if (typeof obj.value === 'object') {
  77. for (const key in obj.value) {
  78. this.LoopUpdateReadonly(obj.value[key]);
  79. }
  80. }
  81. }
  82. }
  83. },
  84. setDirtyData() {
  85. this.dirtyData.realtime = JSON.stringify(this.pipeline);
  86. if (!this.dirtyData.origin) {
  87. this.dirtyData.origin = this.dirtyData.realtime;
  88. }
  89. },
  90. isDirty() {
  91. const isDirty = this.dirtyData.origin !== this.dirtyData.realtime;
  92. return isDirty;
  93. },
  94. };
  95. exports.ready = function() {
  96. this.$.container.addEventListener('change-dump', this.change.bind(this));
  97. this.$.container.addEventListener('confirm-dump', this.snapshot.bind(this));
  98. // Used to determine whether the material has been modified in isDirty()
  99. this.dirtyData = {
  100. uuid: '',
  101. origin: '',
  102. realtime: '',
  103. };
  104. };
  105. exports.update = async function(assetList, metaList) {
  106. this.assetList = assetList;
  107. this.metaList = metaList;
  108. this.meta = this.metaList[0];
  109. this.asset = this.assetList[0];
  110. if (assetList.length > 1) {
  111. this.$.container.setAttribute('multiple-invalid', '');
  112. return;
  113. } else {
  114. this.$.container.removeAttribute('multiple-invalid');
  115. }
  116. if (this.dirtyData.uuid !== this.asset.uuid) {
  117. this.dirtyData.uuid = this.asset.uuid;
  118. this.dirtyData.origin = '';
  119. }
  120. this.pipeline = await this.query(this.asset.uuid);
  121. this.updateInterface();
  122. this.setDirtyData();
  123. };
  124. exports.close = function() {
  125. // Used to determine whether the material has been modified in isDirty()
  126. this.dirtyData = {
  127. uuid: '',
  128. origin: '',
  129. realtime: '',
  130. };
  131. };