Browse Source

Add UnitBox:set_light()

Daniele Bartolini 9 years ago
parent
commit
f6cbbcde2d

+ 10 - 1
samples/core/editors/level_editor/level_editor.lua

@@ -338,6 +338,15 @@ function UnitBox:draw()
 	end
 	end
 end
 end
 
 
+function UnitBox:set_light(type, range, intensity, angle, color)
+	local light = RenderWorld.light_instances(LevelEditor._rw, self._unit_id)
+	RenderWorld.light_set_type(LevelEditor._rw, self._unit_id, type)
+	RenderWorld.light_set_color(LevelEditor._rw, self._unit_id, color)
+	RenderWorld.light_set_range(LevelEditor._rw, self._unit_id, range)
+	RenderWorld.light_set_intensity(LevelEditor._rw, self._unit_id, intensity)
+	RenderWorld.light_set_spot_angle(LevelEditor._rw, self._unit_id, angle)
+end
+
 SoundObject = class(SoundObject)
 SoundObject = class(SoundObject)
 
 
 function SoundObject:init(world, id, name, range, volume, loop)
 function SoundObject:init(world, id, name, range, volume, loop)
@@ -1517,7 +1526,7 @@ end
 function LevelEditor:add_camera_component(id, component_id, projection, fov, far_range, near_range)
 function LevelEditor:add_camera_component(id, component_id, projection, fov, far_range, near_range)
 	local unit_box = self._objects[id]
 	local unit_box = self._objects[id]
 	local unit_id = unit_box:unit_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());
+	World.camera_create(self._world, unit_id, projection, fov, far_range, near_range, unit_box:world_pose());
 end
 end
 
 
 function LevelEditor:move_object(id, pos, rot, scale)
 function LevelEditor:move_object(id, pos, rot, scale)

+ 11 - 0
tools/api/level_editor_api.vala

@@ -194,6 +194,17 @@ namespace Crown
 				);
 				);
 		}
 		}
 
 
+		public string set_light(Guid id, string type, double range, double intensity, double spot_angle, Vector3 color)
+		{
+			return @"LevelEditor._objects[\"%s\"]:set_light(\"%s\", %f, %f, %f, %s)".printf(id.to_string()
+				, type
+				, range
+				, intensity
+				, spot_angle
+				, Lua.quaternion({color.x, color.y, color.z, 1.0})
+				);
+		}
+
 		public string set_placeable(PlaceableType type, string name)
 		public string set_placeable(PlaceableType type, string name)
 		{
 		{
 			return "LevelEditor:set_placeable(\"%s\", \"%s\")".printf((type == PlaceableType.UNIT ? "unit" : "sound"), name);
 			return "LevelEditor:set_placeable(\"%s\", \"%s\")".printf((type == PlaceableType.UNIT ? "unit" : "sound"), name);

+ 12 - 0
tools/level_editor/level.vala

@@ -368,6 +368,18 @@ namespace Crown
 			do_move_objects(new Guid[] { id }, new Vector3[] { pos }, new Quaternion[] { rot }, new Vector3[] { scl });
 			do_move_objects(new Guid[] { id }, new Vector3[] { pos }, new Quaternion[] { rot }, new Vector3[] { scl });
 		}
 		}
 
 
+		public void set_light(Guid unit_id, Guid component_id, string type, double range, double intensity, double spot_angle, Vector3 color)
+		{
+			set_component_property(unit_id, component_id, "data.type",       type);
+			set_component_property(unit_id, component_id, "data.range",      range);
+			set_component_property(unit_id, component_id, "data.intensity",  intensity);
+			set_component_property(unit_id, component_id, "data.spot_angle", spot_angle);
+			set_component_property(unit_id, component_id, "data.color",      color);
+			set_component_property(unit_id, component_id, "type", "light");
+
+			_client.send_script(LevelEditorApi.set_light(unit_id, type, range, intensity, spot_angle, color));
+		}
+
 		public void duplicate_selected_objects()
 		public void duplicate_selected_objects()
 		{
 		{
 			if (_selection.size > 0)
 			if (_selection.size > 0)

+ 9 - 7
tools/level_editor/properties_view.vala

@@ -146,12 +146,14 @@ namespace Crown
 
 
 		private void on_value_changed()
 		private void on_value_changed()
 		{
 		{
-			_level.set_component_property(_unit_id, _component_id, "data.type",       _type.value);
-			_level.set_component_property(_unit_id, _component_id, "data.range",      _range.value);
-			_level.set_component_property(_unit_id, _component_id, "data.intensity",  _intensity.value);
-			_level.set_component_property(_unit_id, _component_id, "data.spot_angle", _spot_angle.value);
-			_level.set_component_property(_unit_id, _component_id, "data.color",      _color.value);
-			_level.set_component_property(_unit_id, _component_id, "type", "light");
+			_level.set_light(_unit_id
+				, _component_id
+				, _type.value
+				, _range.value
+				, _intensity.value
+				, _spot_angle.value*(Math.PI/180.0)
+				, _color.value
+				);
 		}
 		}
 
 
 		public override void update()
 		public override void update()
@@ -165,7 +167,7 @@ namespace Crown
 			_type.value       = type;
 			_type.value       = type;
 			_range.value      = range;
 			_range.value      = range;
 			_intensity.value  = intensity;
 			_intensity.value  = intensity;
-			_spot_angle.value = spot_angle;
+			_spot_angle.value = spot_angle*(180.0/Math.PI);
 			_color.value      = color;
 			_color.value      = color;
 		}
 		}
 	}
 	}