M0' scaffold: Godot 4.7 + GDExtension + libgr2 wired up (macOS)

- extension/: godot-cpp submodule (master, API 4.7), Metin2Model node
  registered, links xrender-poc/libgr2 via sibling-dir reference.
- project/: Godot 4.7 project — orbit camera + DirectionalLight3D (shadows)
  + WorldEnvironment/procedural sky + placeholder cube; main.gd probes the
  extension and can run libgr2 on a real .gr2 (MTGODOT_PROBE_GR2).
- build.sh one-shot build into project/bin/.
- docs/GODOT-POC-PLAN.md (phased: Phase 1 macOS -> M0'/M1/M2/M2.5).

Verified on this machine:
  [mtgodot] Metin2Model registered OK — libgr2 linked
  probe_gr2(warrior_cheongrin.gr2) -> gr2 OK: format_version=6 sections=8
  Metal Forward+ renders the scene (test/golden/m0-scaffold.png).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WaHYEY9rwLWt21PULiYjeJ
This commit is contained in:
Claude
2026-08-29 09:09:55 +09:00
commit c52b8657c4
21 changed files with 839 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
# mtgodot GDExtension — M0' skeleton (registers Metin2Model, links libgr2).
# --- godot-cpp (submodule @ master) ---
# master has no per-minor branch; it ships bundled extension_api-4-*.json.
# Pin to 4.7 to match the installed editor (4.7.1; patch-level ABI is compatible).
set(GODOTCPP_API_VERSION "4.7" CACHE STRING "Target Godot API version" FORCE)
add_subdirectory(godot-cpp)
# --- libgr2 from the sibling xrender-poc repo ---
# M0': plain sibling-directory reference (both repos live under .../mt/).
# For a portable checkout, either git-submodule xrender-poc or vendor libgr2,
# then pass -DXRENDER_POC_DIR=/path/to/xrender-poc.
set(XRENDER_POC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../xrender-poc"
CACHE PATH "Path to the xrender-poc repo (provides libgr2)")
if(NOT EXISTS "${XRENDER_POC_DIR}/libgr2/CMakeLists.txt")
message(FATAL_ERROR
"libgr2 not found at '${XRENDER_POC_DIR}/libgr2'. "
"Pass -DXRENDER_POC_DIR=/path/to/xrender-poc")
endif()
add_subdirectory("${XRENDER_POC_DIR}/libgr2" "${CMAKE_CURRENT_BINARY_DIR}/libgr2")
# --- the extension shared library ---
add_library(mtgodot SHARED
src/register_types.cpp
src/metin2_model.cpp
)
target_compile_features(mtgodot PRIVATE cxx_std_20)
target_link_libraries(mtgodot PRIVATE godot::cpp xrender::libgr2)
# Drop the dylib straight into the Godot project where the .gdextension expects it:
# project/bin/libmtgodot.macos.template_debug.dylib (Debug)
# project/bin/libmtgodot.macos.template_release.dylib (Release)
set_target_properties(mtgodot PROPERTIES
PREFIX "lib"
OUTPUT_NAME "mtgodot.macos.$<IF:$<CONFIG:Release>,template_release,template_debug>"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/project/bin"
)
Submodule extension/godot-cpp added at 101ae38034
+39
View File
@@ -0,0 +1,39 @@
#include "metin2_model.h"
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
#include <string>
#include <gr2/gr2.h> // libgr2 (xrender-poc)
using namespace godot;
namespace mtgodot {
Metin2Model::Metin2Model() = default;
Metin2Model::~Metin2Model() = default;
void Metin2Model::_bind_methods() {
ClassDB::bind_method(D_METHOD("libgr2_info"), &Metin2Model::libgr2_info);
ClassDB::bind_method(D_METHOD("probe_gr2", "path"), &Metin2Model::probe_gr2);
}
String Metin2Model::libgr2_info() const {
// Forces a reference to a libgr2 symbol so the link is real, not dead-stripped.
return String("libgr2 linked; gr2::Magic enum size=") + itos((int)sizeof(gr2::Magic));
}
String Metin2Model::probe_gr2(const String &path) const {
gr2::LoadError err;
const std::string p(path.utf8().get_data());
auto file = gr2::File::load_path(p, &err);
if (!file) {
return vformat("gr2 load FAILED [%s]: %s",
String(err.stage.c_str()), String(err.message.c_str()));
}
return vformat("gr2 OK: format_version=%d sections=%d",
(int)file->format_version(), (int)file->sections().size());
}
} // namespace mtgodot
+31
View File
@@ -0,0 +1,31 @@
#pragma once
#include <godot_cpp/classes/node3d.hpp>
#include <godot_cpp/variant/string.hpp>
namespace mtgodot {
// M0' placeholder node.
//
// Purpose at this milestone: prove the GDExtension registers a class the Godot
// editor can instantiate, and that libgr2 is linked in and callable from here.
// M1 replaces the body with real Skeleton3D / ArrayMesh construction
// (see docs/GODOT-POC-PLAN.md §M1).
class Metin2Model : public godot::Node3D {
GDCLASS(Metin2Model, godot::Node3D)
public:
Metin2Model();
~Metin2Model() override;
// One-line tag proving libgr2 symbols resolved at link time.
godot::String libgr2_info() const;
// Parse a .gr2 with libgr2 and report a couple of counts (no scene build yet).
godot::String probe_gr2(const godot::String &path) const;
protected:
static void _bind_methods();
};
} // namespace mtgodot
+33
View File
@@ -0,0 +1,33 @@
#include "register_types.h"
#include <gdextension_interface.h>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>
#include "metin2_model.h"
using namespace godot;
void initialize_mtgodot_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
GDREGISTER_CLASS(mtgodot::Metin2Model);
}
void uninitialize_mtgodot_module(ModuleInitializationLevel p_level) {
(void)p_level;
}
extern "C" {
GDExtensionBool GDE_EXPORT mtgodot_library_init(
GDExtensionInterfaceGetProcAddress p_get_proc_address,
const GDExtensionClassLibraryPtr p_library,
GDExtensionInitialization *r_initialization) {
godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
init_obj.register_initializer(initialize_mtgodot_module);
init_obj.register_terminator(uninitialize_mtgodot_module);
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
return init_obj.init();
}
}
+6
View File
@@ -0,0 +1,6 @@
#pragma once
#include <godot_cpp/core/class_db.hpp>
void initialize_mtgodot_module(godot::ModuleInitializationLevel p_level);
void uninitialize_mtgodot_module(godot::ModuleInitializationLevel p_level);