XChart 图表框架落地(P0–P17):格线单一作者、面板一行状态、矢量场
此前整个 XChart 特性一直没有提交(分期 P0–P12 的代码与素材都还在工作区里)。这一批一并入库, 并含本轮 P13–P17 的改动(规范 Documentation/XChart-RenderFramework.md 新增 §22–§25): - P13:格线只剩一个作者——线框工具不再有"画格线 / 发布格线插槽"的代码路径;BG Cube Grid(原 MeshBg) 是唯一作者,且"画上去的线=发布给轴线的那份比例数组";插槽板新增 Unpublish(说得出"这里不再有线", 否则掩码筛掉的面会把上一轮的值留着被消费者吸走);渲染参数搬进元素表 (DeclareDefaultElements / AddDefaultElement + XChartElementTable 按类型去重,只在第一次读到表时补); 图上「立方体外观」那组字段删除、公共属性转发到元素表;面板逐行点名脚本注册的工具。 - P14 / P15:数据窗口文案收敛(行末 `-`、标题 `X [0]`、长说明退回 tooltip、范围页三行不再被压扁); 元素块收成一行状态 `▼ 名称 √ R… D… [↑][↓][-]`;**注册序由类型定死、只显示不给输入控件, 绘制序与元素在表里的位置绑定**(§24.5,他 2026-10-25 澄清);默认元素让删也让关; EnsureSpace 改成每次重建后都跑(删掉"空间"不再等于整张图空掉)。 - P17:矢量场——维数不够时不再静默不画(元素配置报需求,面板与报表同时印"需求/现有"); 相对/绝对两种读法收进纯算术 XChartVectorFieldMath;连续绘制(互斥显示把"相对/绝对"藏起来); 颜色维(色相走 0..256 色环,饱和/明度/不透明 0..1,不透明度不算硬需求);新增螺旋矢量场测试数据。 数据口径按他澄清修正为:前三维=坐标、一支箭头=相邻两条记录、第 4~7 维是颜色(§25、CHANGELOG 修正行)。 判据:编译门三臂 + 3 支对照绿;离线探针 436 项 0 失败;p4_control 55 支臂各红在自己点名的断言上; p2_control / pool_family / generator_gate / hierarchy_gate 在同一棵交付树上复跑。 (证据脚本与日志在包外的 .ximage-gate/,未入本仓库。)
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XericUI.XChart.Mesh
|
||||
{
|
||||
/// <summary>
|
||||
/// 矢量场(箭头)的<b>纯算术</b>:一条记录的两组三维怎么变成一支箭头,以及一组颜色维怎么变成颜色。
|
||||
/// 单独拎出来是因为这两条是"看图看不出来"的判据——
|
||||
/// 他 2026-10-25 现场:"我把它添加进来了,之后它并没有显示出来",以及"相对和绝对就是这两种区别"。
|
||||
/// 读数与算式放在一起,离线探针才能逐条钉住(规范 §25)。
|
||||
/// </summary>
|
||||
public static class XChartVectorFieldMath
|
||||
{
|
||||
/// <summary>
|
||||
/// 末端位置。<paramref name="mode"/>=<see cref="XChartArrowVectorMode.Absolute"/> 时
|
||||
/// <paramref name="second"/> 是<b>方向矢量</b>本身(起点 + 方向×倍率);
|
||||
/// =<see cref="XChartArrowVectorMode.Relative"/> 时它是<b>第二个点</b>(起点 + 差向量×倍率)。
|
||||
/// 两种读法在同一个数据上画出来是两幅不同的图:前者"刺猬",后者"首尾相接"。
|
||||
/// </summary>
|
||||
public static Vector3 Tip(XChartArrowVectorMode mode, Vector3 first, Vector3 second, float scale)
|
||||
{
|
||||
Vector3 direction = mode == XChartArrowVectorMode.Relative ? second - first : second;
|
||||
return first + direction * scale;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读一组颜色维:<paramref name="hue"/> 按 <b>0..256 的色环</b>(256 与 0 是同一个颜色,
|
||||
/// 取模,所以 300 也读得动),饱和度/明度/不透明度按 0..1 夹住。
|
||||
///
|
||||
/// <para><b>任何一个不是有限数就拒绝</b>(返回 false,调用方退回单色):
|
||||
/// NaN 经取模与 HSV 换算会得到一个看着像"黑色块"的东西——那不是数据的意思,
|
||||
/// 是我们在替它编一个颜色(同 §14.1 的"宁可这一帧不画")。</para>
|
||||
/// </summary>
|
||||
public static bool TryColor(float hue, float saturation, float value, float alpha, out Color color)
|
||||
{
|
||||
color = Color.white;
|
||||
if (!IsFinite(hue) || !IsFinite(saturation) || !IsFinite(value) || !IsFinite(alpha)) return false;
|
||||
|
||||
color = HsvToRgb(Mathf.Repeat(hue / 256f, 1f), Mathf.Clamp01(saturation), Mathf.Clamp01(value));
|
||||
color.a = Mathf.Clamp01(alpha);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool IsFinite(float value)
|
||||
=> !float.IsNaN(value) && !float.IsInfinity(value);
|
||||
|
||||
/// <summary>
|
||||
/// HSV → RGB(h∈[0,1),s/v∈[0,1])。
|
||||
/// <b>自己写而不是调 <c>Color.HSVToRGB</c></b>:后者是引擎侧的静态调用,
|
||||
/// 离线探针(mono + CoreModule)里跑不起来,而这条换算恰恰是要离线钉住的(规范 §25)。
|
||||
/// </summary>
|
||||
private static Color HsvToRgb(float h, float s, float v)
|
||||
{
|
||||
if (s <= 0f) return new Color(v, v, v, 1f);
|
||||
|
||||
float sector = h * 6f;
|
||||
int index = Mathf.FloorToInt(sector) % 6;
|
||||
if (index < 0) index += 6;
|
||||
float f = sector - Mathf.Floor(sector);
|
||||
|
||||
float p = v * (1f - s);
|
||||
float q = v * (1f - s * f);
|
||||
float t = v * (1f - s * (1f - f));
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0: return new Color(v, t, p, 1f);
|
||||
case 1: return new Color(q, v, p, 1f);
|
||||
case 2: return new Color(p, v, t, 1f);
|
||||
case 3: return new Color(p, q, v, 1f);
|
||||
case 4: return new Color(t, p, v, 1f);
|
||||
default: return new Color(v, p, q, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user