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:
@@ -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
|
||||
@@ -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
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
Reference in New Issue
Block a user