P3-04 · @saier/core:收割 shodo → CalligraphyEngine
- Phase / ID: P3 / P3-04
- Depends on: P3-02、P3-03、P1-03(
BrushEngine接口) - Files:
packages/core/src/brush/CalligraphyEngine.ts、packages/shodo/src/{stroke-engine,tablet}.ts(来源)、test/ - Effort: M
- Status: 🟡(兑现"收割 shodo",见 overview 修正 #3)
Context
packages/shodo 已有可用的毛笔笔迹数学:4 点滑动平均(≈stabilizer)、velocity→笔锋粗细曲线、加速度出锋 taper、以及可序列化回放格式。把这些算法抽进 core,作为 BrushEngine 的一个实现 CalligraphyEngine,render 到 surface(而非 shodo 现在的「每 dab 一个 Sprite」)。
Steps
- 从
stroke-engine.ts抽取:buffer 平滑(并入 P3-02 的 moving-average)、velocity → brushSize曲线(pressureVelocity那套)、endStroke的加速度出锋 → 并入 P3-03 的 taperOut。 CalligraphyEngine implements BrushEngine:addPoint用 velocity 驱动 size(毛笔特性:快则细、顿则粗),endStroke出锋;dab 交 backend 渲染。- 去随机:
_drawStroke里的Math.random()抖动改成可注入 seed(确定性,见 Testing)。 - 从
tablet.ts抽取可序列化笔迹格式({X,Y,T,P}+ 操作流)→ 暂存为core/format/的草案,供 P8 复用。 site/shodo.vuedemo 切到新CalligraphyEngine(验证收割未丢手感)。
Acceptance
- [ ]
CalligraphyEngine在同一BrushEngine接口下可与SimpleBrushEngine互换。 - [ ] 毛笔特性可见:快笔细、顿笔粗、收尾出锋。
- [ ] 确定性:seed 固定时同输入 → 同像素(替换掉
Math.random()后可测)。 - [ ]
/shododemo 仍可写、手感不劣于现状。
Out of scope
- libmypaint /
.myb(→ P9);纸纹 / 湿边(→ P7)。