Files
mtgodot-poc/README.md
T
Claude f4917a2b3b Fix cull mode + isolate head-collapse to a libgr2 curve bug
Rendering fixes (real):
- m2_material shaders: cull_disabled -> cull_back (inside-of-mesh faces were
  z-winning and darkening/hiding the head under the ShaderMaterial path).
- drop `* COLOR` from the shader (meshes carry no ARRAY_COLOR).

Animation: convert gr2 global poses to Godot *local* bone poses and set via
set_bone_pose (was set_bone_global_pose). MTGODOT_VERIFY=1 confirms
get_bone_global_pose(i) == conv(world[i]) for all 75 bones (<=2.6e-5).

Head/upper-armor collapse on dance_1 is NOT a Godot-route bug:
- reproduced identically in xrender-poc's bgfx demo at the same anim/t
- reproduced by the new MTGODOT_CPUSKIN=1 reference path (same LBS math as
  xrender's validated skin_mesh)
- `general/wait` / `run` render correctly in all three
=> upstream libgr2 Curve::eval (degree-2 quaternion B-spline) vs Granny.
Demo default animation switched to general/wait; documented in MIDREVIEW §4
and README. Debug scaffolding gated behind MTGODOT_VERIFY / MTGODOT_CPUSKIN.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WaHYEY9rwLWt21PULiYjeJ
2026-08-29 10:47:01 +09:00

138 lines
6.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# mtgodot-poc
「**Godot 4 + 自研资源 loader**」跨平台方案的渲染 Demoroute ①)。
用一个 C++ GDExtension 复用 [`xrender-poc`](../xrender-poc) 的 `libgr2`,把 Metin2 的
`.gr2` 骨骼资源渲染进 Godot,用 Godot 内置渲染器。
`xrender-poc`(自研引擎 + bgfx RHI)是**两条并行的跨平台基座候选**,共用 `libgr2`
判定分两阶段:
| 阶段 | 平台 | 里程碑 | 产出 |
|---|---|---|---|
| **Phase 1**(当前) | macOS | M0' · M1 · M2 · M2.5 | 中期评审(不下 go/no-go |
| Phase 2 | iOS · Android | M3 | go / no-go |
完整计划见 [`docs/GODOT-POC-PLAN.md`](docs/GODOT-POC-PLAN.md)。
---
## 现状
- [x] **M0'** — 脚手架。GDExtension 加载 + `Metin2Model` 注册 + `libgr2` 链接可调用
+ Godot 4.7 工程经 Metal Forward+ 出画。T0.4 实际 `export` 待装 4.7.1 导出模板。
- [x] **M1** — 静态渲染。`gr2``Skeleton3D` + `ArrayMesh` + `Skin` + 材质。
`warrior_cheongrin`75 骨 / 5 表面 / 3324 顶点)正立、朝 +Z、贴图正确
`test/golden/m1-bindpose.png`)。多骨架:`warrior_lord`(v6,74)、`assassin`(v6,95,17 表面)、
`shaman_lord`(**v7**,93) 均正确加载渲染。
- [x] **M2** — 骨骼动画。`Metin2AnimPlayer` `_process``gr2::sample_pose`(跨文件)
→ 逐骨 `Skeleton3D.set_bone_pose`(局部),Godot GPU 蒙皮。`general/wait` 头 / 护甲
对齐正确(`test/golden/m2-wait.png`);`get_bone_global_pose` vs `conv(world)` 全骨 ≤2.6e-5
CPU-LBS 参考路径(`MTGODOT_CPUSKIN=1`)与 GPU 蒙皮一致;`selfcheck` 0 NaN。
⚠️ `dance_1` 等表情动作头 / 颈塌陷 —— **libgr2 曲线解码 bugxrender-poc bgfx demo 同样复现**
(见 `docs/MIDREVIEW.md` §4)。
- [~] **M2.5** — 材质与观感保真。`ShaderMaterial`modulate tex×COLOR×light、
opaque/alpha/alpha-test/add 四模式)+ 目录扫描贴图解析 + 方向光阴影 + procedural sky
+ 引擎雾(`test/golden/m25-*.png`)。**门禁未闭**:多材质槽 → 贴图/混合的精确映射需
给 libgr2 加材质 API(见 `docs/GODOT-POC-PLAN.md` §M2.5 T2.5.6 差距清单)。
- [~] **中期评审** — [`docs/MIDREVIEW.md`](docs/MIDREVIEW.md)。结论:桥接层工程量小、
风险基本出清,**建议进入 Phase 2**。收尾 3 项:`compare.py` 对拍、`dump_materials`
Granny 对拍闭合 M2.5 门禁、前台/真机性能重测。
50 角色压力采样:`test/godot-macos-stress.json`(后台窗口 30fps 节流,仅构建成本
~165ms/角色 和 100 角色破顶到 52ms 是可信信号)。
---
## 环境
| 组件 | 版本 / 位置 | 说明 |
|---|---|---|
| Godot | **4.7.1**`/opt/homebrew/bin/godot`Homebrew cask | 编辑器 + headless |
| godot-cpp | submodule `extension/godot-cpp` @ `master`pin `101ae38` | master 默认 targets Godot 4.7 API`GODOTCPP_DEFAULT_API_VERSION=4.7`);无 `4.6/4.7` 分支,只有 bundled `extension_api-4-7.json` |
| Xcode | 26.4.1 | macOS 构建 |
| CMake | 已装;**不需要 SCons** | godot-cpp 走 CMake 路径 |
| libgr2 | `../xrender-poc/libgr2`sibling-dir 引用) | 见下「libgr2 依赖」 |
**导出模板**M0' T0.4 / 真正 export 才需要):编辑器内 `Editor → Manage Export Templates → Download`,或 `godot --headless --install-export-templates`。~600MB,版本须与编辑器一致(4.7.1)。
---
## 构建
```bash
git submodule update --init --recursive # 拉 godot-cpp(首次)
./build.sh # Debug;产物 → project/bin/libmtgodot.macos.template_debug.dylib
./build.sh Release # template_release
```
首次会编译 godot-cpp(几分钟)。
## 运行
```bash
# 编辑器打开
godot -e --path project
# headless 冒烟测试(验证 GDExtension 加载 + 类注册)
godot --headless --path project --quit-after 3
# 跑一个真实 gr2 过 libgr2(可选)
MTGODOT_PROBE_GR2="$PWD/../m2dev-client-main/assets/PC/ymir work/pc/warrior/warrior_cheongrin.gr2" \
godot --headless --path project --quit-after 3
```
控制台出现 `[mtgodot] Metin2Model registered OK — libgr2 linked; ...` = M0' 的 T0.1/T0.2 通过。
窗口内:拖拽 = 轨道,滚轮 = 缩放,`F2` = 截图(→ `user://`)。
---
## libgr2 依赖
M0' 直接用 **sibling-directory 引用**`extension/CMakeLists.txt`
`XRENDER_POC_DIR` 默认 `../../xrender-poc``add_subdirectory``libgr2`
两个 repo 都在 `.../mt/` 下时开箱即用。
换机 / CI 时二选一:
- `git submodule add <xrender-poc url> third_party/xrender-poc` 后传 `-DXRENDER_POC_DIR=third_party/xrender-poc`
- vendor 一份 `libgr2/` 进本仓库
> ⚠️ 本仓库依赖 `../xrender-poc/libgr2` 里新增的 `dump_materials()`
> `src/gr2_material.cpp` + `include/gr2/gr2.h` + `CMakeLists.txt` 三处,纯附加)。
> 该改动目前只在 xrender-poc 工作树里,**未提交**(那个仓库无提交历史,保持原样)。
> 需要时由 xrender-poc 的维护者按其流程纳入。
`formats/`msa/msm)到 **M2** 才需要,届时同样方式接入。
---
## 目录
```
mtgodot-poc/
CMakeLists.txt 顶层(macOS only 守卫)
build.sh 便捷构建
extension/
CMakeLists.txt mtgodot SHARED + godot-cpp + libgr2
godot-cpp/ submodule @ master
src/
register_types.{h,cpp} GDExtension 入口,注册 Metin2Model
metin2_model.{h,cpp} M0' 占位节点(证明类注册 + libgr2 链接)
project/ Godot 4.7 工程
project.godot
main.tscn 根 Node3D + main.gd
main.gd M0' harness:建 env/light/cam/cube + 探测扩展
assets/.gdignore 让 Godot 不 import .gr2/.dds
bin/mtgodot.gdextension 扩展描述符(dylib 构建产物落这里)
export_presets.cfg macOS preset
docs/
GODOT-POC-PLAN.md 开发计划(M0'M4 + 风险 + 验收)
steps/ (按需)
test/golden/ 对拍截图(M1 起)
```
## 授权
`libgr2` 全自研,不含 Granny SDK 代码。本仓库内部研究用途,不对外公开。