Godot Version
4.6.2
Question
I added a custom ResourceFormatLoader to load .mesh files as the RBXSpecialMesh class (Roblox Version 1.0 Mesh class) and it works. The only issue is that Godot also tries to read the mesh file with ResourceLoaderBinary, which causes a “Unrecognized binary resource file“ error to appear.
Also note that this error only pops up while testing in a scene, and not while in the editor
Here is the code for resource loader:
Variant ResourceFormatRBXSpecialMesh::_load(const String &p_path, const String &p_original_path, bool p_use_sub_threads, int32_t p_cache_mode) const {
ERR_FAIL_COND_V_MSG(!FileAccess::file_exists(p_path), Ref<RBXSpecialMesh>(), "ERROR: File not found!");
Ref<RBXSpecialMesh> mesh = memnew(RBXSpecialMesh);
mesh->load_from_file(p_path);
return mesh;
}
PackedStringArray ResourceFormatRBXSpecialMesh::_get_recognized_extensions() const {
PackedStringArray exts;
exts.push_back("mesh");
return exts;
}
bool ResourceFormatRBXSpecialMesh::_handles_type(const StringName &p_type) const {
return ClassDB::is_parent_class(p_type, "RBXSpecialMesh");
}
String ResourceFormatRBXSpecialMesh::_get_resource_type(const String& p_path) const {
return "RBXSpecialMesh";
}
And the test script:
extends MeshInstance3D
@onready var swordMesh := load(“res://Models/sword.mesh”)
var swordMaterial : StandardMaterial3D = preload(“res://Materials/SwordMaterial.tres”)
func _ready() → void:
var mesh_data := swordMesh
swordMesh.get_version()mesh_data.surface_set_material(0, swordMaterial)
mesh = mesh_data