Przeglądaj źródła

tools: fix importing FBX files with funny extension

Fixes: #264
Daniele Bartolini 1 rok temu
rodzic
commit
8787afdcfc

+ 2 - 10
src/resource/mesh.cpp

@@ -237,16 +237,8 @@ namespace mesh
 			RETURN_IF_ERROR(sjson::parse_string(source, obj["source"]), opts);
 
 			RETURN_IF_FILE_MISSING(source.c_str(), opts);
-			if (source.has_suffix(".fbx")) {
-				Buffer fbx_buf = opts.read(source.c_str());
-				return fbx::parse(m, fbx_buf, opts);
-			}
-
-			RETURN_IF_FALSE(false
-				, opts
-				, "Unknown source mesh '%s'"
-				, source.c_str()
-				);
+			Buffer fbx_buf = opts.read(source.c_str());
+			return fbx::parse(m, fbx_buf, opts);
 		} else {
 			return mesh::parse(m, buf, opts);
 		}

+ 3 - 2
tools/resource/mesh_resource.vala

@@ -203,9 +203,10 @@ namespace MeshResource
 		SList<string> fbx_filenames = new SList<string>();
 		SList<string> mesh_filenames = new SList<string>();
 		foreach (unowned string filename_i in filenames) {
-			if (filename_i.has_suffix(".fbx"))
+			string fi = filename_i.down();
+			if (fi.has_suffix(".fbx"))
 				fbx_filenames.append(filename_i);
-			else if (filename_i.has_suffix(".mesh"))
+			else if (fi.has_suffix(".mesh"))
 				mesh_filenames.append(filename_i);
 			else
 				assert(false);

+ 10 - 8
tools/resource/mesh_resource_fbx.vala

@@ -15,14 +15,13 @@ public static int get_destination_file(out GLib.File destination_file
 	return 0;
 }
 
-public static int get_resource_name(out string resource_name
+public static int get_resource_path(out string resource_path
 	, GLib.File destination_file
 	, Project project
 	)
 {
 	string resource_filename = project.resource_filename(destination_file.get_path());
-	string resource_path = ResourceId.normalize(resource_filename);
-	resource_name = ResourceId.name(resource_path);
+	resource_path = ResourceId.normalize(resource_filename);
 	return 0;
 }
 
@@ -176,9 +175,10 @@ public class FBXImportDialog : Gtk.Window
 
 		_options = new FBXImportOptions();
 		GLib.File file_dst;
-		string resource_name;
+		string resource_path;
 		get_destination_file(out file_dst, destination_dir, File.new_for_path(_filenames[0]));
-		get_resource_name(out resource_name, file_dst, _project);
+		get_resource_path(out resource_path, file_dst, _project);
+		string resource_name = ResourceId.name(resource_path);
 		_options_path = _project.absolute_path(resource_name) + ".importer_settings";
 		try {
 			_options.decode(SJSON.load_from_path(_options_path));
@@ -395,13 +395,15 @@ public class FBXImporter
 	public static ImportResult do_import(FBXImportOptions options, Project project, string destination_dir, Gee.ArrayList<string> filenames)
 	{
 		foreach (string filename_i in filenames) {
-			string resource_name;
+			string resource_path;
+			string resource_type;
 			GLib.File file_dst;
 			GLib.File file_src = File.new_for_path(filename_i);
 			if (get_destination_file(out file_dst, destination_dir, file_src) != 0)
 				return ImportResult.ERROR;
-			if (get_resource_name(out resource_name, file_dst, project) != 0)
+			if (get_resource_path(out resource_path, file_dst, project) != 0)
 				return ImportResult.ERROR;
+			string resource_name = ResourceId.name(resource_path);
 
 			// Copy FBX file.
 			try {
@@ -615,7 +617,7 @@ public class FBXImporter
 
 			Guid mesh_id = Guid.new_guid();
 			db.create(mesh_id, OBJECT_TYPE_MESH);
-			db.set_property_string(mesh_id, "source", resource_name + ".fbx");
+			db.set_property_string(mesh_id, "source", resource_path);
 			db.save(project.absolute_path(resource_name) + ".mesh", mesh_id);
 		}