fix(ShaderBake): 修正离屏视图矩阵与侧栏数值不可见
- 投影矩阵是 OpenGL 约定(相机朝 -Z),而 TRS.inverse 给的是 Unity 的 +Z 朝前, 两者拼起来几何全被裁剪,表现是"渲染成功但画面全透明";视图矩阵补上 Z 镜像 - 侧栏半宽/三分之一宽的字段按内容定基宽,标题又占 ~120px,输入框被挤出可视区; 改成 flex-basis:0 + 收窄标题 + 输入区 min-width:0,并缩短过长标签 - 数值绑定改用 INotifyValueChanged<T> 按名字绑定,不再依赖跨版本会换命名空间的具体字段类型
This commit is contained in:
@@ -633,8 +633,8 @@ namespace XericUI.ShaderBake.Editor
|
|||||||
|
|
||||||
private void SetFaceFieldsEnabled(bool enabled)
|
private void SetFaceFieldsEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
IntegerField x = rootVisualElement.Q<IntegerField>("face-uv-x");
|
VisualElement x = rootVisualElement.Q<VisualElement>("face-uv-x");
|
||||||
IntegerField y = rootVisualElement.Q<IntegerField>("face-uv-y");
|
VisualElement y = rootVisualElement.Q<VisualElement>("face-uv-y");
|
||||||
if (x != null) x.SetEnabled(enabled);
|
if (x != null) x.SetEnabled(enabled);
|
||||||
if (y != null) y.SetEnabled(enabled);
|
if (y != null) y.SetEnabled(enabled);
|
||||||
}
|
}
|
||||||
@@ -856,18 +856,27 @@ namespace XericUI.ShaderBake.Editor
|
|||||||
|
|
||||||
// ── 通用绑定 ────────────────────────────────────────────
|
// ── 通用绑定 ────────────────────────────────────────────
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 一律按名字取元素、再按 INotifyValueChanged<T> 绑定,而不是 Q<FloatField> 之类。
|
||||||
|
* 同名的数字输入框在 2021.3 / 2022.1 分属 UnityEditor.UIElements 与 UnityEngine.UIElements,
|
||||||
|
* 按具体类型 Q 一旦落在另一侧就取不到:表现是数值永远空白,而且当时不一定有显眼报错。
|
||||||
|
*/
|
||||||
|
|
||||||
private void BindFloat(string name, Func<float> get, Action<float> set)
|
private void BindFloat(string name, Func<float> get, Action<float> set)
|
||||||
{
|
{
|
||||||
FloatField field = rootVisualElement.Q<FloatField>(name);
|
VisualElement field = rootVisualElement.Q<VisualElement>(name);
|
||||||
if (field == null)
|
var target = field as INotifyValueChanged<float>;
|
||||||
|
if (target == null)
|
||||||
{
|
{
|
||||||
Debug.LogError("[ShaderBake] UXML 里缺控件 " + name);
|
Debug.LogError("[ShaderBake] UXML 里缺数值控件 " + name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 延迟提交:一边打字一边回写会把光标和"0."这类中间输入搅乱,等回车/失焦再收
|
// 延迟提交:一边打字一边回写会把光标和"0."这类中间输入搅乱,等回车/失焦再收
|
||||||
field.isDelayed = true;
|
var delayedTarget = field as TextInputBaseField<float>;
|
||||||
m_Syncers.Add(() => field.SetValueWithoutNotify(get()));
|
if (delayedTarget != null)
|
||||||
field.RegisterValueChangedCallback(evt =>
|
delayedTarget.isDelayed = true;
|
||||||
|
m_Syncers.Add(() => target.SetValueWithoutNotify(get()));
|
||||||
|
field.RegisterCallback<ChangeEvent<float>>(evt =>
|
||||||
{
|
{
|
||||||
set(evt.newValue);
|
set(evt.newValue);
|
||||||
Commit();
|
Commit();
|
||||||
@@ -876,15 +885,18 @@ namespace XericUI.ShaderBake.Editor
|
|||||||
|
|
||||||
private void BindInt(string name, Func<int> get, Action<int> set)
|
private void BindInt(string name, Func<int> get, Action<int> set)
|
||||||
{
|
{
|
||||||
IntegerField field = rootVisualElement.Q<IntegerField>(name);
|
VisualElement field = rootVisualElement.Q<VisualElement>(name);
|
||||||
if (field == null)
|
var target = field as INotifyValueChanged<int>;
|
||||||
|
if (target == null)
|
||||||
{
|
{
|
||||||
Debug.LogError("[ShaderBake] UXML 里缺控件 " + name);
|
Debug.LogError("[ShaderBake] UXML 里缺整数控件 " + name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
field.isDelayed = true;
|
var delayedTarget = field as TextInputBaseField<int>;
|
||||||
m_Syncers.Add(() => field.SetValueWithoutNotify(get()));
|
if (delayedTarget != null)
|
||||||
field.RegisterValueChangedCallback(evt =>
|
delayedTarget.isDelayed = true;
|
||||||
|
m_Syncers.Add(() => target.SetValueWithoutNotify(get()));
|
||||||
|
field.RegisterCallback<ChangeEvent<int>>(evt =>
|
||||||
{
|
{
|
||||||
set(evt.newValue);
|
set(evt.newValue);
|
||||||
Commit();
|
Commit();
|
||||||
@@ -893,14 +905,15 @@ namespace XericUI.ShaderBake.Editor
|
|||||||
|
|
||||||
private void BindBool(string name, Func<bool> get, Action<bool> set)
|
private void BindBool(string name, Func<bool> get, Action<bool> set)
|
||||||
{
|
{
|
||||||
Toggle field = rootVisualElement.Q<Toggle>(name);
|
VisualElement field = rootVisualElement.Q<VisualElement>(name);
|
||||||
if (field == null)
|
var target = field as INotifyValueChanged<bool>;
|
||||||
|
if (target == null)
|
||||||
{
|
{
|
||||||
Debug.LogError("[ShaderBake] UXML 里缺控件 " + name);
|
Debug.LogError("[ShaderBake] UXML 里缺开关 " + name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_Syncers.Add(() => field.SetValueWithoutNotify(get()));
|
m_Syncers.Add(() => target.SetValueWithoutNotify(get()));
|
||||||
field.RegisterValueChangedCallback(evt =>
|
field.RegisterCallback<ChangeEvent<bool>>(evt =>
|
||||||
{
|
{
|
||||||
set(evt.newValue);
|
set(evt.newValue);
|
||||||
Commit();
|
Commit();
|
||||||
@@ -909,14 +922,15 @@ namespace XericUI.ShaderBake.Editor
|
|||||||
|
|
||||||
private void BindColor(string name, Func<Color> get, Action<Color> set)
|
private void BindColor(string name, Func<Color> get, Action<Color> set)
|
||||||
{
|
{
|
||||||
ColorField field = rootVisualElement.Q<ColorField>(name);
|
VisualElement field = rootVisualElement.Q<VisualElement>(name);
|
||||||
if (field == null)
|
var target = field as INotifyValueChanged<Color>;
|
||||||
|
if (target == null)
|
||||||
{
|
{
|
||||||
Debug.LogError("[ShaderBake] UXML 里缺控件 " + name);
|
Debug.LogError("[ShaderBake] UXML 里缺颜色控件 " + name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_Syncers.Add(() => field.SetValueWithoutNotify(get()));
|
m_Syncers.Add(() => target.SetValueWithoutNotify(get()));
|
||||||
field.RegisterValueChangedCallback(evt =>
|
field.RegisterCallback<ChangeEvent<Color>>(evt =>
|
||||||
{
|
{
|
||||||
set(evt.newValue);
|
set(evt.newValue);
|
||||||
Commit();
|
Commit();
|
||||||
|
|||||||
@@ -127,6 +127,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.detail-pane > .unity-scroll-view__content-container {
|
.detail-pane > .unity-scroll-view__content-container {
|
||||||
|
width: 100%;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,9 +168,14 @@
|
|||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* flex-basis: 0 是关键:默认 auto 会按内容宽度(标题 + 输入框)定基宽,
|
||||||
|
* 一行两栏/三栏加起来必然超过侧栏宽度,输入框被挤到可视区外——表现就是"数值文本不显示"。
|
||||||
|
*/
|
||||||
.field-half {
|
.field-half {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
flex-shrink: 1;
|
flex-shrink: 1;
|
||||||
|
flex-basis: 0;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
margin-right: 4px;
|
margin-right: 4px;
|
||||||
}
|
}
|
||||||
@@ -177,6 +183,7 @@
|
|||||||
.field-third {
|
.field-third {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
flex-shrink: 1;
|
flex-shrink: 1;
|
||||||
|
flex-basis: 0;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
margin-right: 4px;
|
margin-right: 4px;
|
||||||
}
|
}
|
||||||
@@ -184,11 +191,28 @@
|
|||||||
.field-quarter {
|
.field-quarter {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
flex-shrink: 1;
|
flex-shrink: 1;
|
||||||
|
flex-basis: 0;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
margin-right: 3px;
|
margin-right: 3px;
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 2021.3 的字段标题默认吃 120px 左右,窄栏里会把输入区压没;侧栏内统一收窄 */
|
||||||
|
.detail-content .unity-base-field__label,
|
||||||
|
.detail-content .unity-text-field__label,
|
||||||
|
.detail-content .unity-base-text-field__label {
|
||||||
|
min-width: 30px;
|
||||||
|
flex-shrink: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-content .unity-base-field__input,
|
||||||
|
.detail-content .unity-text-field__input,
|
||||||
|
.detail-content .unity-base-text-field__input {
|
||||||
|
flex-shrink: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* ── 浏览图里的选中面片高亮 ── */
|
/* ── 浏览图里的选中面片高亮 ── */
|
||||||
.face-overlay {
|
.face-overlay {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
@@ -86,9 +86,9 @@
|
|||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
<xer:IntegerField name="out-pass" label="Pass 下标" class="field-full" />
|
<xer:IntegerField name="out-pass" label="Pass 下标" class="field-full" />
|
||||||
<x:ColorField name="out-clear" label="背景色" class="field-full" />
|
<x:ColorField name="out-clear" label="背景色" class="field-full" />
|
||||||
<ui:Toggle name="out-hdr" label="HDR(浮点目标)" class="field-toggle" />
|
<ui:Toggle name="out-hdr" label="HDR" class="field-toggle" />
|
||||||
<ui:Toggle name="out-srgb" label="sRGB 存储" class="field-toggle" />
|
<ui:Toggle name="out-srgb" label="sRGB 存储" class="field-toggle" />
|
||||||
<ui:Toggle name="out-flip" label="上下翻转(读回方向不对时开)" class="field-toggle" />
|
<ui:Toggle name="out-flip" label="翻转 Y" class="field-toggle" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
|
|
||||||
@@ -102,8 +102,8 @@
|
|||||||
<xer:FloatField name="surf-size-y" label="高" class="field-half" />
|
<xer:FloatField name="surf-size-y" label="高" class="field-half" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
<ui:VisualElement class="field-row">
|
<ui:VisualElement class="field-row">
|
||||||
<xer:IntegerField name="surf-seg-x" label="面内细分列" class="field-half" />
|
<xer:IntegerField name="surf-seg-x" label="细分X" class="field-half" />
|
||||||
<xer:IntegerField name="surf-seg-y" label="面内细分行" class="field-half" />
|
<xer:IntegerField name="surf-seg-y" label="细分Y" class="field-half" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
|
|
||||||
<ui:Label class="field-note" text="面片网格(一格一张 UV 区域,向左/下扩展编号递减)" />
|
<ui:Label class="field-note" text="面片网格(一格一张 UV 区域,向左/下扩展编号递减)" />
|
||||||
@@ -152,8 +152,8 @@
|
|||||||
<ui:Label class="field-note" text="外部网格" />
|
<ui:Label class="field-note" text="外部网格" />
|
||||||
<x:ObjectField name="surf-mesh" label="网格" class="field-full" />
|
<x:ObjectField name="surf-mesh" label="网格" class="field-full" />
|
||||||
<xer:IntegerField name="surf-submesh" label="SubMesh" class="field-full" />
|
<xer:IntegerField name="surf-submesh" label="SubMesh" class="field-full" />
|
||||||
<ui:Toggle name="surf-normalize" label="缩放到面片尺寸" class="field-toggle" />
|
<ui:Toggle name="surf-normalize" label="适配尺寸" class="field-toggle" />
|
||||||
<ui:Toggle name="surf-uv-st" label="UV 再写进 _MainTex_ST" class="field-toggle" />
|
<ui:Toggle name="surf-uv-st" label="写 _MainTex_ST" class="field-toggle" />
|
||||||
<ui:VisualElement class="field-row">
|
<ui:VisualElement class="field-row">
|
||||||
<ui:Button name="surf-reset" text="面片归位" class="field-half" />
|
<ui:Button name="surf-reset" text="面片归位" class="field-half" />
|
||||||
<ui:Button name="surf-pick-scene" text="取选中物体" class="field-half" />
|
<ui:Button name="surf-pick-scene" text="取选中物体" class="field-half" />
|
||||||
|
|||||||
@@ -31,10 +31,21 @@ namespace XericUI.ShaderBake
|
|||||||
[Tooltip("相机旋转(欧拉角,度):默认朝 +Z 看,即看着放在原点、面朝 -Z 的面片")]
|
[Tooltip("相机旋转(欧拉角,度):默认朝 +Z 看,即看着放在原点、面朝 -Z 的面片")]
|
||||||
public Vector3 eulerAngles;
|
public Vector3 eulerAngles;
|
||||||
|
|
||||||
/// <summary> 视口(世界 → 相机)矩阵 </summary>
|
/// <summary>
|
||||||
|
/// 视口(世界 → 相机)矩阵。
|
||||||
|
///
|
||||||
|
/// <para><b>为什么要镜像 Z</b>:<see cref="Matrix4x4.Perspective"/> 与 <see cref="Matrix4x4.Ortho"/>
|
||||||
|
/// 沿用 OpenGL 约定——相机朝 <b>-Z</b> 看;而 <c>TRS(...).inverse</c> 给出的是 Unity 自己的
|
||||||
|
/// "朝 +Z 看"。两者直接拼起来,正前方的物体会得到负的裁剪 w(透视)或落在近远裁剪面之外(正交),
|
||||||
|
/// 整块几何被裁光,表现就是"渲染成功但画面全透明"。</para>
|
||||||
|
/// </summary>
|
||||||
public Matrix4x4 viewMatrix
|
public Matrix4x4 viewMatrix
|
||||||
{
|
{
|
||||||
get { return Matrix4x4.TRS(position, Quaternion.Euler(eulerAngles), Vector3.one).inverse; }
|
get
|
||||||
|
{
|
||||||
|
Matrix4x4 worldToLocal = Matrix4x4.TRS(position, Quaternion.Euler(eulerAngles), Vector3.one).inverse;
|
||||||
|
return Matrix4x4.Scale(new Vector3(1f, 1f, -1f)) * worldToLocal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user