fbx.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. 'use strict';
  2. const { updateElementReadonly, updateElementInvalid, getPropValue, setPropValue } = require('../../utils/assets');
  3. exports.template = /* html */`
  4. <div class="container">
  5. <ui-prop>
  6. <ui-label slot="label" value="i18n:ENGINE.assets.fbx.animationBakeRate.name" tooltip="i18n:ENGINE.assets.fbx.animationBakeRate.title"></ui-label>
  7. <ui-select slot="content" class="animationBakeRate-select">
  8. <option value="0">0</option>
  9. <option value="24">24</option>
  10. <option value="25">25</option>
  11. <option value="30">30</option>
  12. <option value="60">60</option>
  13. </ui-select>
  14. </ui-prop>
  15. <ui-prop>
  16. <ui-label slot="label" value="i18n:ENGINE.assets.fbx.preferLocalTimeSpan.name" tooltip="i18n:ENGINE.assets.fbx.preferLocalTimeSpan.title"></ui-label>
  17. <ui-checkbox slot="content" class="preferLocalTimeSpan-checkbox"></ui-checkbox>
  18. </ui-prop>
  19. <ui-prop class="smart-material-prop">
  20. <ui-label slot="label" value="i18n:ENGINE.assets.fbx.smartMaterialEnabled.name" tooltip="i18n:ENGINE.assets.fbx.smartMaterialEnabled.title"></ui-label>
  21. <ui-checkbox slot="content" class="smartMaterialEnabled-checkbox"></ui-checkbox>
  22. <div class="warn-words">
  23. <ui-label value="i18n:ENGINE.assets.fbx.smartMaterialEnabled.warn"></ui-label>
  24. </div>
  25. </ui-prop>
  26. <ui-section class="legacy">
  27. <ui-label slot="header" value="i18n:ENGINE.assets.fbx.legacyOptions"></ui-label>
  28. <div class="legacy-importer">
  29. <ui-prop>
  30. <ui-label slot="label" value="i18n:ENGINE.assets.fbx.legacyFbxImporter.name" tooltip="i18n:ENGINE.assets.fbx.legacyFbxImporter.title"></ui-label>
  31. <ui-checkbox slot="content" class="legacyFbxImporter-checkbox"></ui-checkbox>
  32. </ui-prop>
  33. <div class="warn-words">
  34. <ui-label value="i18n:ENGINE.assets.fbx.legacyFbxImporter.warn"></ui-label>
  35. </div>
  36. </div>
  37. </ui-section>
  38. </div>
  39. `;
  40. exports.style = /* css */`
  41. ui-prop { margin-right: 4px; }
  42. ui-section.config { margin-right: 0; }
  43. .warn-words {
  44. color: var(--color-warn-fill);
  45. }
  46. .legacy-importer {
  47. display: none;
  48. margin-top: 10px;
  49. }
  50. .smart-material-prop .warn-words {
  51. display: none;
  52. }
  53. .smart-material-prop[readonly] .warn-words {
  54. display: block;
  55. margin-top: 4px;
  56. line-height: 20px;
  57. }
  58. `;
  59. exports.$ = {
  60. container: '.container',
  61. legacy: '.legacy',
  62. legacyImporter: '.legacy-importer',
  63. legacyFbxImporterCheckbox: '.legacyFbxImporter-checkbox',
  64. animationBakeRateSelect: '.animationBakeRate-select',
  65. preferLocalTimeSpanCheckbox: '.preferLocalTimeSpan-checkbox',
  66. smartMaterialEnabledCheckbox: '.smartMaterialEnabled-checkbox',
  67. smartMaterialEnabledProp: '.smart-material-prop',
  68. };
  69. /**
  70. * attribute corresponds to the edit element
  71. */
  72. const Elements = {
  73. legacy: {
  74. async ready() {
  75. const panel = this;
  76. const legacyFbxImporter = await Editor.Profile.getProject('project', 'fbx.legacyFbxImporter.visible');
  77. if (legacyFbxImporter) {
  78. panel.$.legacyImporter.style.display = "block";
  79. }
  80. if (!legacyFbxImporter) {
  81. panel.$.legacy.style.display = "none";
  82. }
  83. },
  84. },
  85. legacyFbxImporter: {
  86. ready() {
  87. const panel = this;
  88. panel.$.animationBakeRateSelect.children[0].innerText = Editor.I18n.t('ENGINE.assets.fbx.animationBakeRate.auto');
  89. panel.$.legacyFbxImporterCheckbox.addEventListener('change', panel.setProp.bind(panel, 'legacyFbxImporter', 'boolean'));
  90. panel.$.legacyFbxImporterCheckbox.addEventListener('confirm', () => {
  91. panel.dispatch('snapshot');
  92. });
  93. },
  94. update() {
  95. const panel = this;
  96. panel.$.legacyFbxImporterCheckbox.value = getPropValue.call(panel, panel.meta.userData.legacyFbxImporter, false);
  97. updateElementInvalid.call(panel, panel.$.legacyFbxImporterCheckbox, 'legacyFbxImporter');
  98. updateElementReadonly.call(panel, panel.$.legacyFbxImporterCheckbox);
  99. },
  100. },
  101. animationBakeRate: {
  102. ready() {
  103. const panel = this;
  104. panel.$.animationBakeRateSelect.addEventListener('change', panel.setProp.bind(panel, 'fbx.animationBakeRate', 'number'));
  105. panel.$.animationBakeRateSelect.addEventListener('confirm', () => {
  106. panel.dispatch('snapshot');
  107. });
  108. },
  109. update() {
  110. const panel = this;
  111. let defaultValue = 0;
  112. if (panel.meta.userData.fbx) {
  113. defaultValue = getPropValue.call(panel, panel.meta.userData.fbx.animationBakeRate, defaultValue);
  114. }
  115. panel.$.animationBakeRateSelect.value = defaultValue;
  116. updateElementInvalid.call(panel, panel.$.animationBakeRateSelect, 'fbx.animationBakeRate');
  117. updateElementReadonly.call(panel, panel.$.animationBakeRateSelect);
  118. },
  119. },
  120. preferLocalTimeSpan: {
  121. ready() {
  122. const panel = this;
  123. panel.$.preferLocalTimeSpanCheckbox.addEventListener('change', panel.setProp.bind(panel, 'fbx.preferLocalTimeSpan', 'boolean'));
  124. panel.$.preferLocalTimeSpanCheckbox.addEventListener('confirm', () => {
  125. panel.dispatch('snapshot');
  126. });
  127. },
  128. update() {
  129. const panel = this;
  130. let defaultValue = true;
  131. if (panel.meta.userData.fbx) {
  132. defaultValue = getPropValue.call(panel, panel.meta.userData.fbx.preferLocalTimeSpan, defaultValue);
  133. }
  134. panel.$.preferLocalTimeSpanCheckbox.value = defaultValue;
  135. updateElementInvalid.call(panel, panel.$.preferLocalTimeSpanCheckbox, 'fbx.preferLocalTimeSpan');
  136. updateElementReadonly.call(panel, panel.$.preferLocalTimeSpanCheckbox);
  137. },
  138. },
  139. smartMaterialEnabled: {
  140. ready() {
  141. const panel = this;
  142. panel.$.smartMaterialEnabledCheckbox.addEventListener('change', panel.setProp.bind(panel, 'fbx.smartMaterialEnabled', 'boolean'));
  143. panel.$.smartMaterialEnabledCheckbox.addEventListener('confirm', () => {
  144. panel.dispatch('snapshot');
  145. });
  146. },
  147. async update() {
  148. const panel = this;
  149. const laboratoryExpectedValue = await Editor.Profile.getProject('project', 'fbx.material.smart');
  150. if (!laboratoryExpectedValue) {
  151. panel.$.smartMaterialEnabledProp.setAttribute('readonly', '');
  152. } else {
  153. panel.$.smartMaterialEnabledProp.removeAttribute('readonly');
  154. }
  155. let defaultValue = false;
  156. if (panel.meta.userData.fbx) {
  157. defaultValue = getPropValue.call(panel, panel.meta.userData.fbx.smartMaterialEnabled, defaultValue);
  158. }
  159. panel.$.smartMaterialEnabledCheckbox.value = defaultValue;
  160. updateElementInvalid.call(panel, panel.$.smartMaterialEnabledCheckbox, 'fbx.smartMaterialEnabled');
  161. updateElementReadonly.call(panel, panel.$.smartMaterialEnabledCheckbox);
  162. },
  163. },
  164. };
  165. exports.methods = {
  166. setProp(prop, type, event) {
  167. setPropValue.call(this, prop, type, event);
  168. this.dispatch('change');
  169. this.dispatch('track', { tab: 'fbx', prop, value: event.target.value });
  170. },
  171. };
  172. exports.ready = function() {
  173. for (const prop in Elements) {
  174. const element = Elements[prop];
  175. if (element.ready) {
  176. element.ready.call(this);
  177. }
  178. }
  179. };
  180. exports.update = async function(assetList, metaList) {
  181. this.assetList = assetList;
  182. this.metaList = metaList;
  183. this.asset = assetList[0];
  184. this.meta = metaList[0];
  185. for (const prop in Elements) {
  186. const element = Elements[prop];
  187. if (element.update) {
  188. await element.update.call(this);
  189. }
  190. }
  191. };
  192. exports.close = function() {
  193. for (const prop in Elements) {
  194. const element = Elements[prop];
  195. if (element.close) {
  196. element.close.call(this);
  197. }
  198. }
  199. };