Bläddra i källkod

Add sprite and camera components creation

Daniele Bartolini 9 år sedan
förälder
incheckning
355867caed

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

@@ -1502,12 +1502,24 @@ function LevelEditor:add_mesh_component(id, component_id, mesh_resource, geometr
 	RenderWorld.mesh_create(self._rw, unit_id, mesh_resource, geometry_name, material_resource, visible, unit_box:world_pose())
 end
 
+function LevelEditor:add_sprite_component(id, component_id, sprite_resource, material_resource, visible)
+	local unit_box = self._objects[id]
+	local unit_id = unit_box:unit_id();
+	RenderWorld.sprite_create(self.rw, unit_id, sprite_resource, material_resource, visible, unit_box:world_pose())
+end
+
 function LevelEditor:add_light_component(id, component_id, type, range, intensity, spot_angle, color)
 	local unit_box = self._objects[id]
 	local unit_id = unit_box:unit_id()
 	RenderWorld.light_create(self._rw, unit_id, type, range, intensity, spot_angle, color, unit_box:world_pose())
 end
 
+function LevelEditor:add_camera_component(id, component_id, projection, fov, far_range, near_range)
+	local unit_box = self._objects[id]
+	local unit_id = unit_box:unit_id();
+	World.camera_create(self.rw, unit_id, projection, fov, far_range, near_range, unit_box:world_pose());
+end
+
 function LevelEditor:move_object(id, pos, rot, scale)
 	local unit_box = self._objects[id]
 	unit_box:set_local_position(pos)

+ 21 - 0
tools/api/level_editor_api.vala

@@ -152,6 +152,27 @@ namespace Crown
 				);
 		}
 
+		public string add_sprite_component(Guid id, Guid component_id, string sprite_resource, string material_resource, bool visible)
+		{
+			return "LevelEditor:add_sprite_component(\"%s\", \"%s\", \"%s\", \"%s\", %s)".printf(id.to_string()
+				, component_id.to_string()
+				, sprite_resource
+				, material_resource
+				, Lua.bool(visible)
+				);
+		}
+
+		public string add_camera_component(Guid id, Guid component_id, string projection, double fov, double far_range, double near_range)
+		{
+			return "LevelEditor:add_camera_component(\"%s\", \"%s\", \"%s\", %f, %f, %f)".printf(id.to_string()
+				, component_id.to_string()
+				, projection
+				, fov
+				, far_range
+				, near_range
+				);
+		}
+
 		public string add_light_component(Guid id, Guid component_id, string type, double range, double intensity, double spot_angle, Vector3 color)
 		{
 			return "LevelEditor:add_light_component(\"%s\", \"%s\", \"%s\", %f, %f, %f, %s)".printf(id.to_string()

+ 21 - 0
tools/level_editor/level.vala

@@ -128,6 +128,16 @@ namespace Crown
 						);
 					sb.append(s);
 				}
+				if (has_component(unit_id, "sprite_renderer", ref component_id))
+				{
+					string s = LevelEditorApi.add_sprite_component(unit_id
+						, component_id
+						, (string)get_component_property(unit_id, component_id, "data.sprite_resource")
+						, (string)get_component_property(unit_id, component_id, "data.material")
+						, (bool)  get_component_property(unit_id, component_id, "data.visible")
+						);
+					sb.append(s);
+				}
 				if (has_component(unit_id, "light", ref component_id))
 				{
 					string s = LevelEditorApi.add_light_component(unit_id
@@ -140,6 +150,17 @@ namespace Crown
 						);
 					sb.append(s);
 				}
+				if (has_component(unit_id, "camera", ref component_id))
+				{
+					string s = LevelEditorApi.add_camera_component(unit_id
+						, component_id
+						, (string)get_component_property(unit_id, component_id, "data.projection")
+						, (double)get_component_property(unit_id, component_id, "data.fov")
+						, (double)get_component_property(unit_id, component_id, "data.far_range")
+						, (double)get_component_property(unit_id, component_id, "data.near_range")
+						);
+					sb.append(s);
+				}
 			}
 		}