Explorar o código

tools: import FBX node names

Daniele Bartolini hai 3 meses
pai
achega
6a0ccdb078
Modificáronse 2 ficheiros con 9 adicións e 3 borrados
  1. 1 0
      docs/changelog.rst
  2. 8 3
      tools/resource/mesh_resource_fbx.vala

+ 1 - 0
docs/changelog.rst

@@ -8,6 +8,7 @@ Changelog
 
 * Tools: added the ability to search any kind of resources in the Project Browser. As a consequence, the old Resource Chooser dialog has been removed.
 * Tools: double-clicking an object in the Level Tree will now frame it in the Editor Viewport.
+* Tools: units created via the FBX importer will now be named according to their corresponding node's name.
 * Runtime: added an end-of-options marker to stop the runtime from parsing game-specific command line options.
 * Lua: added ``Device.build()`` to retrieve the runtime's build configuration.
 * Lua: added ``PhysicsWorld.actor_debug_draw()`` and ``PhysicsWorld.mover_debug_draw()``.

+ 8 - 3
tools/resource/mesh_resource_fbx.vala

@@ -343,11 +343,13 @@ public class FBXImporter
 		Vector3 pos = vector3(node.local_transform.translation);
 		Quaternion rot = quaternion(node.local_transform.rotation);
 		Vector3 scl = vector3(node.local_transform.scale);
+		string editor_name = node.name.data.length == 0 ? OBJECT_NAME_UNNAMED : (string)node.name.data;
 
 		// Create mesh_renderer.
 		if (node.mesh != null) {
 			Unit unit = Unit(db, unit_id);
 			db.create(unit_id, OBJECT_TYPE_UNIT);
+			db.set_object_name(unit_id, editor_name);
 
 			// Create transform.
 			{
@@ -361,7 +363,7 @@ public class FBXImporter
 				unit.set_component_property_vector3   (component_id, "data.position", pos);
 				unit.set_component_property_quaternion(component_id, "data.rotation", rot);
 				unit.set_component_property_vector3   (component_id, "data.scale", scl);
-				unit.set_component_property_string    (component_id, "data.name", (string)node.name.data);
+				unit.set_component_property_string    (component_id, "data.name", editor_name);
 			}
 
 			if (node.mesh.num_faces > 0) {
@@ -379,7 +381,7 @@ public class FBXImporter
 					if (imported_materials.has_key(mesh_instance_material))
 						material_name = imported_materials[mesh_instance_material];
 
-					unit.set_component_property_string(component_id, "data.geometry_name", (string)node.name.data);
+					unit.set_component_property_string(component_id, "data.geometry_name", editor_name);
 					unit.set_component_property_string(component_id, "data.material", material_name);
 					unit.set_component_property_string(component_id, "data.mesh_resource", resource_name);
 					unit.set_component_property_bool  (component_id, "data.visible", true);
@@ -396,7 +398,7 @@ public class FBXImporter
 
 					unit.set_component_property_string(component_id, "data.shape", "mesh");
 					unit.set_component_property_string(component_id, "data.scene", resource_name);
-					unit.set_component_property_string(component_id, "data.name", (string)node.name.data);
+					unit.set_component_property_string(component_id, "data.name", editor_name);
 				}
 
 				// Create actor.
@@ -420,6 +422,7 @@ public class FBXImporter
 
 			Unit unit = Unit(db, unit_id);
 			unit.create("core/units/light");
+			db.set_object_name(unit_id, editor_name);
 			unit.set_local_position(pos);
 			unit.set_local_rotation(rot);
 			unit.set_local_scale(scl);
@@ -440,6 +443,7 @@ public class FBXImporter
 
 			Unit unit = Unit(db, unit_id);
 			unit.create("core/units/camera");
+			db.set_object_name(unit_id, editor_name);
 			unit.set_local_position(pos);
 			unit.set_local_rotation(rot);
 			unit.set_local_scale(scl);
@@ -456,6 +460,7 @@ public class FBXImporter
 		} else {
 			Unit unit = Unit(db, unit_id);
 			db.create(unit_id, OBJECT_TYPE_UNIT);
+			db.set_object_name(unit_id, editor_name);
 
 			// Create transform.
 			Guid component_id;