Explorar o código

tools: add initial SET_MESH action

Daniele Bartolini %!s(int64=6) %!d(string=hai) anos
pai
achega
4832321455

+ 6 - 0
samples/core/editors/level_editor/level_editor.lua

@@ -368,6 +368,12 @@ function UnitBox:set_light(type, range, intensity, angle, color)
 	RenderWorld.light_set_spot_angle(LevelEditor._rw, self._unit_id, angle)
 end
 
+function UnitBox:set_mesh(instance_id, material, visible)
+	local mesh_component = RenderWorld.mesh_instances(LevelEditor._rw, self._unit_id)
+	RenderWorld.mesh_set_material(LevelEditor._rw, mesh_component, material)
+	RenderWorld.mesh_set_visible(LevelEditor._rw, mesh_component, visible)
+end
+
 function UnitBox:set_sprite(material, layer, depth, visible)
 	RenderWorld.sprite_set_material(LevelEditor._rw, self._unit_id, material)
 	RenderWorld.sprite_set_layer(LevelEditor._rw, self._unit_id, layer)

+ 9 - 0
tools/api/engine_api.vala

@@ -288,6 +288,15 @@ namespace Crown
 				);
 		}
 
+		public string set_mesh(Guid id, double instance_id, string material, bool visible)
+		{
+			return @"LevelEditor._objects[\"%s\"]:set_mesh(%f, \"%s\", %s)".printf(id.to_string()
+				, instance_id
+				, material
+				, Lua.bool(visible)
+				);
+		}
+
 		public string set_sprite(Guid id, string material, double layer, double depth, bool visible)
 		{
 			return @"LevelEditor._objects[\"%s\"]:set_sprite(\"%s\", %f, %f, %s)".printf(id.to_string()

+ 1 - 0
tools/level_editor/action_type.vala

@@ -15,6 +15,7 @@ namespace Crown
 		DUPLICATE_OBJECTS,
 		OBJECT_SET_EDITOR_NAME,
 		SET_LIGHT,
+		SET_MESH,
 		SET_SPRITE,
 		SET_SOUND
 	}

+ 32 - 0
tools/level_editor/level.vala

@@ -299,6 +299,20 @@ namespace Crown
 			_client.send_script(LevelEditorApi.set_light(unit_id, type, range, intensity, spot_angle, color));
 		}
 
+		public void set_mesh(Guid unit_id, Guid component_id, string mesh_resource, string geometry, string material, bool visible)
+		{
+			_db.add_restore_point((int)ActionType.SET_MESH, new Guid[] { unit_id });
+
+			Unit unit = new Unit(_db, unit_id, _prefabs);
+			unit.set_component_property_string(component_id, "data.mesh_resource", mesh_resource);
+			unit.set_component_property_string(component_id, "data.geometry_name", geometry);
+			unit.set_component_property_string(component_id, "data.material", material);
+			unit.set_component_property_bool  (component_id, "data.visible", visible);
+			unit.set_component_property_string(component_id, "type", "mesh_renderer");
+
+			_client.send_script(LevelEditorApi.set_mesh(unit_id, 0 /*instance_id*/, material, visible));
+		}
+
 		public void set_sprite(Guid unit_id, Guid component_id, double layer, double depth, string material, string sprite_resource, bool visible)
 		{
 			_db.add_restore_point((int)ActionType.SET_SPRITE, new Guid[] { unit_id });
@@ -656,6 +670,24 @@ namespace Crown
 				}
 				break;
 
+			case (int)ActionType.SET_MESH:
+				{
+					Guid unit_id = data[0];
+					Guid component_id = GUID_ZERO;
+
+					Unit unit = new Unit(_db, unit_id, _prefabs);
+					unit.has_component("mesh_renderer", ref component_id);
+
+					_client.send_script(LevelEditorApi.set_mesh(unit_id
+						, 0/*instance_id*/
+						, unit.get_component_property_string(component_id, "data.material")
+						, unit.get_component_property_bool  (component_id, "data.visible")
+						));
+					// FIXME: Hack to force update the properties view
+					selection_changed(_selection);
+				}
+				break;
+
 			case (int)ActionType.SET_SPRITE:
 				{
 					Guid unit_id = data[0];