From 749226eefbd29cb3084fb3ec6b52db4652b677f2 Mon Sep 17 00:00:00 2001
From: zhangxin <59186205+chichinohaha@users.noreply.github.com>
Date: Fri, 25 Mar 2022 19:07:40 +0800
Subject: [PATCH] [Bug] add fix alpha transparency artifact options and fix bug
(#10419)
* add fix alpha transparency artifact options and fix bug
add fix alpha transparency artifact options
fix bug
- Fixed an issue where events were registered more than once
* Non-transparent channels or RGBE channels are not allowed
* Update image.js
* revert set hidden to set style
---
editor/i18n/en/assets.js | 2 ++
editor/i18n/zh/assets.js | 2 ++
editor/inspector/assets/image.js | 48 ++++++++++++++++++++++++++++----
3 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/editor/i18n/en/assets.js b/editor/i18n/en/assets.js
index d6f551c241..25c18b3e12 100644
--- a/editor/i18n/en/assets.js
+++ b/editor/i18n/en/assets.js
@@ -81,6 +81,8 @@ module.exports = {
bakeOfflineMipmapsTip: 'Bake Offline Mipmaps',
flipVertical: 'Flip Vertical',
flipVerticalTip: 'Flip Vertical',
+ fixAlphaTransparencyArtifacts: 'Fix Alpha Transparency Artifacts',
+ fixAlphaTransparencyArtifactsTip: 'Fill transparent pixels with color of neareast solid pixel. These filled pixels would fix the dark halos at transparent borders of textures. Please turn on this option when you use the Alpha transparency channel in textures.',
isRGBE: 'Is RGBE',
isRGBETip: 'Is RGBE',
},
diff --git a/editor/i18n/zh/assets.js b/editor/i18n/zh/assets.js
index 6bcedb487c..815669341b 100644
--- a/editor/i18n/zh/assets.js
+++ b/editor/i18n/zh/assets.js
@@ -81,6 +81,8 @@ module.exports = {
bakeOfflineMipmapsTip: 'Bake Offline Mipmaps',
flipVertical: 'Flip Vertical',
flipVerticalTip: 'Flip Vertical',
+ fixAlphaTransparencyArtifacts: 'Fix Alpha Transparency Artifacts',
+ fixAlphaTransparencyArtifactsTip: '为全透明像素填充相邻像素的颜色,防止纹理过滤引起的黑边问题。当使用 Alpha 透明通道时,请启用此功能。',
isRGBE: 'Is RGBE',
isRGBETip: 'Is RGBE',
},
diff --git a/editor/inspector/assets/image.js b/editor/inspector/assets/image.js
index 2102016868..0d9c0e23da 100644
--- a/editor/inspector/assets/image.js
+++ b/editor/inspector/assets/image.js
@@ -1,6 +1,5 @@
'use strict';
-const { appendFileSync } = require('fs');
const path = require('path');
exports.template = `
@@ -17,6 +16,10 @@ exports.template = `
+
+
+
+
@@ -49,6 +52,8 @@ exports.$ = {
container: '.asset-image',
typeSelect: '.type-select',
flipVerticalCheckbox: '.flipVertical-checkbox',
+ fixAlphaTransparencyArtifactsCheckbox: '.fixAlphaTransparencyArtifacts-checkbox',
+ fixATAProp: '.fixATAProp',
isRGBEProp: '.isRGBE-prop',
isRGBECheckbox: '.isRGBE-checkbox',
@@ -70,7 +75,8 @@ const Elements = {
panel.dispatch('change');
// There are other properties whose updates depend on its changes attribute corresponds to the edit element
- Elements.isRGBE.update.bind(panel)();
+ Elements.isRGBE.update.call(panel);
+ Elements.fixAlphaTransparencyArtifacts.update.call(panel);
});
},
update() {
@@ -126,6 +132,38 @@ const Elements = {
panel.$.bakeOfflineMipmapsCheckbox.value = panel.meta.userData.bakeOfflineMipmaps;
},
},
+
+ fixAlphaTransparencyArtifacts: {
+ ready() {
+ const panel = this;
+ panel.$.fixAlphaTransparencyArtifactsCheckbox.addEventListener('change', (event) => {
+ panel.metaList.forEach((meta) => {
+ meta.userData.fixAlphaTransparencyArtifacts = event.target.value;
+
+ });
+ panel.dispatch('change');
+ });
+ },
+ update() {
+ const panel = this;
+
+ /** @type {HTMLElement} */
+ const fixAlphaTransparencyArtifactsCheckbox = panel.$.fixAlphaTransparencyArtifactsCheckbox;
+ /** @type {HTMLElement} */
+ const fixATAProp = panel.$.fixATAProp;
+ fixAlphaTransparencyArtifactsCheckbox.value = panel.meta.userData.fixAlphaTransparencyArtifacts;
+ const bannedTypes = ['normal map'];
+ const isCapableToFixAlphaTransparencyArtifacts = !bannedTypes.includes(panel.meta.userData.type);
+ if (isCapableToFixAlphaTransparencyArtifacts) {
+ fixATAProp.style.display = 'block';
+ panel.updateInvalid(panel.$.fixAlphaTransparencyArtifactsCheckbox, 'fixAlphaTransparencyArtifacts');
+ panel.updateReadonly(panel.$.fixAlphaTransparencyArtifactsCheckbox);
+ } else {
+ fixATAProp.style.display = 'none';
+ }
+
+ },
+ },
isRGBE: {
ready() {
const panel = this;
@@ -185,6 +223,9 @@ exports.ready = function() {
element.ready.call(this);
}
}
+ this.$.panel.addEventListener('change', () => {
+ this.dispatch('change');
+ });
};
exports.methods = {
@@ -271,8 +312,5 @@ exports.methods = {
this.$.panelName.setAttribute('value', this.meta.userData.type);
this.$.panel.setAttribute('src', path.join(__dirname, `./${asset.importer}.js`));
this.$.panel.update(assetList, metaList);
- this.$.panel.addEventListener('change', () => {
- this.dispatch('change');
- });
},
};