Metin2 game client (P0–P11) + mobile asset pipeline
Networked client on the existing Godot 4.7 + libgr2 renderer:
- net: m2dev wire protocol (libsodium KX + XChaCha20), auth/select/game
phases, EntityStore world model, ~all GC/CG headers. char create/delete,
private shop / mall / cube, SHOP_GC_START_EX, guild, party (+ CG_PARTY_SET_STATE),
quests, dragon soul, refine, safebox, exchange.
- UI: in-game windows migrated 1:1 from the reference uiscript/root .py —
char status (/stat), inventory+equipment, select-item ([SELECT_ITEM] quest
token), system-option + game-option + ESC system menu, private-shop 39-grid,
party info board, shop tabs, atlas, minimap, quickbar, chat, …
- EterGrnLib polish: GR2 material blend/two-sided, LOD crossfade, motion-event
dispatch, contact shadow, ray-AABB picking, weapon grip pre-transform.
Portable asset IO (A1) — all extension/libgr2/formats/mtproto reads routed
through godot::FileAccess (res:// PCK works on iOS/Android); standalone-lib
*_path() kept for the non-Godot CTests. AssetResolver + PropertyRegistry
switched to a baked index (bake_asset_index.gd) instead of std::filesystem.
Mobile builds: build-{android,ios}.sh, export-android.sh, pack-assets.sh,
gen-debug-keystore.sh. Assets ship as a zip mounted at runtime by
project/asset_pack.gd (adb push now; HTTP download is a drop-in later).
ctest 10/10, 34 GDScript suites, macOS/iOS/Android all build.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013EJxkHiNKS4kybHS3XKyAJ
This commit is contained in:
@@ -18,6 +18,19 @@ using namespace godot;
|
||||
|
||||
namespace mtgodot {
|
||||
|
||||
gr2::Mat4 mul4x3(const gr2::Mat4 &A, const gr2::Mat4 &B) {
|
||||
gr2::Mat4 R{};
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int k = 0; k < 3; ++k)
|
||||
R[i * 4 + k] = A[i * 4 + 0] * B[0 * 4 + k] + A[i * 4 + 1] * B[1 * 4 + k] +
|
||||
A[i * 4 + 2] * B[2 * 4 + k];
|
||||
}
|
||||
for (int k = 0; k < 3; ++k)
|
||||
R[12 + k] = A[12] * B[k] + A[13] * B[4 + k] + A[14] * B[8 + k] + B[12 + k];
|
||||
R[15] = 1.0f;
|
||||
return R;
|
||||
}
|
||||
|
||||
Transform3D gr2_to_godot(const gr2::Mat4 &m) {
|
||||
// gr2 row-major, row-vector: basis columns are (m0,m1,m2),(m4,m5,m6),(m8,m9,m10);
|
||||
// translation is the 4th row (m12,m13,m14).
|
||||
@@ -71,18 +84,59 @@ Ref<Skin> build_skin(const gr2::Skeleton &sk) {
|
||||
return skin;
|
||||
}
|
||||
|
||||
Ref<ArrayMesh> build_mesh(const gr2::FileInfo &fi, bool flip_winding, AABB &out_bounds) {
|
||||
std::vector<RenderPart> build_parts(const gr2::FileInfo &fi) {
|
||||
std::vector<RenderPart> parts;
|
||||
for (int mi = 0; mi < (int)fi.meshes.size(); ++mi) {
|
||||
const gr2::Mesh &m = fi.meshes[mi];
|
||||
if (m.vertices.empty() || m.indices.empty()) {
|
||||
continue;
|
||||
}
|
||||
const uint32_t total = (uint32_t)m.indices.size();
|
||||
if (m.tri_groups.size() <= 1) {
|
||||
RenderPart p;
|
||||
p.mesh = mi;
|
||||
p.mat_index = m.tri_groups.empty() ? -1 : m.tri_groups[0].material_index;
|
||||
p.idx_first = 0;
|
||||
p.idx_count = total;
|
||||
parts.push_back(p);
|
||||
continue;
|
||||
}
|
||||
for (int g = 0; g < (int)m.tri_groups.size(); ++g) {
|
||||
const gr2::TriGroup &tg = m.tri_groups[g];
|
||||
if (tg.tri_count <= 0) {
|
||||
continue;
|
||||
}
|
||||
uint32_t first = (uint32_t)(tg.tri_first < 0 ? 0 : tg.tri_first) * 3u;
|
||||
uint32_t count = (uint32_t)tg.tri_count * 3u;
|
||||
if (first >= total) {
|
||||
continue;
|
||||
}
|
||||
if (first + count > total) {
|
||||
count = total - first;
|
||||
}
|
||||
RenderPart p;
|
||||
p.mesh = mi;
|
||||
p.group = g;
|
||||
p.mat_index = tg.material_index;
|
||||
p.idx_first = first;
|
||||
p.idx_count = count;
|
||||
parts.push_back(p);
|
||||
}
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
|
||||
Ref<ArrayMesh> build_mesh(const gr2::FileInfo &fi, const std::vector<RenderPart> &parts,
|
||||
bool flip_winding, AABB &out_bounds) {
|
||||
Ref<ArrayMesh> am;
|
||||
am.instantiate();
|
||||
am->set_name("ArrayMesh");
|
||||
|
||||
bool have_bounds = false;
|
||||
|
||||
for (size_t mi = 0; mi < fi.meshes.size(); ++mi) {
|
||||
const gr2::Mesh &m = fi.meshes[mi];
|
||||
if (m.vertices.empty() || m.indices.empty()) {
|
||||
continue;
|
||||
}
|
||||
// vertex arrays are per gr2 mesh; multiple parts of one mesh reuse them.
|
||||
for (const RenderPart &part : parts) {
|
||||
const gr2::Mesh &m = fi.meshes[part.mesh];
|
||||
const int vcount = (int)m.vertices.size();
|
||||
|
||||
PackedVector3Array pos;
|
||||
@@ -144,18 +198,23 @@ Ref<ArrayMesh> build_mesh(const gr2::FileInfo &fi, bool flip_winding, AABB &out_
|
||||
}
|
||||
}
|
||||
|
||||
// indices: this part's sub-range of mesh.indices only
|
||||
const uint32_t ib = part.idx_first;
|
||||
const uint32_t ic = (part.idx_count && part.idx_first + part.idx_count <= m.indices.size())
|
||||
? part.idx_count
|
||||
: (uint32_t)m.indices.size() - ib;
|
||||
PackedInt32Array idx;
|
||||
idx.resize((int)m.indices.size());
|
||||
idx.resize((int)ic);
|
||||
int32_t *idx_w = idx.ptrw();
|
||||
if (flip_winding) {
|
||||
for (size_t t = 0; t + 2 < m.indices.size(); t += 3) {
|
||||
idx_w[t + 0] = (int)m.indices[t + 0];
|
||||
idx_w[t + 1] = (int)m.indices[t + 2];
|
||||
idx_w[t + 2] = (int)m.indices[t + 1];
|
||||
for (uint32_t t = 0; t + 2 < ic; t += 3) {
|
||||
idx_w[t + 0] = (int)m.indices[ib + t + 0];
|
||||
idx_w[t + 1] = (int)m.indices[ib + t + 2];
|
||||
idx_w[t + 2] = (int)m.indices[ib + t + 1];
|
||||
}
|
||||
} else {
|
||||
for (size_t t = 0; t < m.indices.size(); ++t) {
|
||||
idx_w[t] = (int)m.indices[t];
|
||||
for (uint32_t t = 0; t < ic; ++t) {
|
||||
idx_w[t] = (int)m.indices[ib + t];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,8 +228,11 @@ Ref<ArrayMesh> build_mesh(const gr2::FileInfo &fi, bool flip_winding, AABB &out_
|
||||
arrays[Mesh::ARRAY_INDEX] = idx;
|
||||
|
||||
am->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arrays);
|
||||
am->surface_set_name(am->get_surface_count() - 1,
|
||||
m.name.empty() ? String("surf_") + itos((int)mi) : String(m.name.c_str()));
|
||||
String nm = m.name.empty() ? String("surf_") + itos(part.mesh) : String(m.name.c_str());
|
||||
if (part.group >= 0) {
|
||||
nm += String("#") + itos(part.group);
|
||||
}
|
||||
am->surface_set_name(am->get_surface_count() - 1, nm);
|
||||
}
|
||||
|
||||
if (!have_bounds) {
|
||||
|
||||
Reference in New Issue
Block a user