Certainly! Here is the corrected code with proper English quotation marks for use in Blender:
python
import bpy
import math
# Set default parameters
default_light_count = 3
default_light_power = 200 # in Watts
default_light_angle = 45.0 # in degrees
# Create lights and set properties
def create_lights(selected_obj, light_count, light_power, light_angle):
# Remove existing lights
for obj in bpy.context.scene.objects:
if "light_obj" in obj.name:
bpy.data.objects.remove(obj, do_unlink=True)
# Create lights for the selected object
for i in range(light_count):
angle_rad = math.radians(light_angle)
# Calculate light position
radius = max(selected_obj.dimensions)
x = selected_obj.location.x + radius * math.sin(2 * math.pi * i / light_count) * math.cos(angle_rad)
y = selected_obj.location.y + radius * math.cos(2 * math.pi * i / light_count) * math.cos(angle_rad)
z = selected_obj.location.z + radius * math.sin(angle_rad)
# Create light data object
light_data = bpy.data.lights.new(name="Light.%d" % i, type='AREA')
light_data.energy = light_power
light_data.shape = 'RECTANGLE'
light_data.size = 0.5
light_data.size_y = 0.1
light_object = bpy.data.objects.new(name="light_obj.%d" % i, object_data=light_data)
bpy.context.collection.objects.link(light_object)
# Set light position
light_object.location = (x, y, z)
# Point light towards the object
light_object.rotation_euler = light_object.rotation_euler.to_quaternion().to_euler()
look_at(light_object, selected_obj.location)
def look_at(obj, target):
""" Make the light object point towards the target """
direction = target - obj.location
rot_quat = direction.to_track_quat('-Z', 'Y')
obj.rotation_euler = rot_quat.to_euler()
class OBJECT_OT_create_three_point_lighting(bpy.types.Operator):
"""Create Three Point Lighting"""
bl_idname = "object.create_three_point_lighting"
bl_label = "Create Three Point Lighting"
bl_options = {'REGISTER', 'UNDO'}
light_count: bpy.props.IntProperty(name="Number of Lights", default=default_light_count, min=1, max=10)
light_power: bpy.props.FloatProperty(name="Light Power (W)", default=default_light_power, min=0)
light_angle: bpy.props.FloatProperty(name="Light Normal Height", default=default_light_angle, min=0, max=90)
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
selected_obj = context.active_object
create_lights(selected_obj, self.light_count, self.light_power, self.light_angle)
return {'FINISHED'}
# Register/Unregister classes
def register():
bpy.utils.register_class(OBJECT_OT_create_three_point_lighting)
def unregister():
bpy.utils.unregister_class(OBJECT_OT_create_three_point_lighting)
if __name__ == "__main__":
register()
# Add panel to UI for operation
bpy.types.VIEW3D_MT_object.append(lambda self, context: self.layout.operator(OBJECT_OT_create_three_point_lighting.bl_idname))
Ensure you copy and paste this code into a new text file in Blender's text editor. Then, you can run the script by pressing the Run Script button. If the operation is successful, you'll find the "Create Three Point Lighting" option in the "Object" menu in the 3D View, and you can use it with any selected object.
Here is the updated script with all punctuation and quotation marks converted to standard English, which should work in Blender's Python environment:
python
import bpy
import math
# Set default parameters
default_light_count = 3
default_light_power = 200 # in Watts
default_light_angle = 45.0 # in degrees
# Create lights and set properties
def create_lights(selected_obj, light_count, light_power, light_angle):
# Remove existing lights
for obj in bpy.context.scene.objects:
if 'light_obj' in obj.name:
bpy.data.objects.remove(obj, do_unlink=True)
# Create lights for the selected object
for i in range(light_count):
angle_rad = math.radians(light_angle)
# Calculate light position
radius = max(selected_obj.dimensions)
x = selected_obj.location.x + radius * math.sin(2 * math.pi * i / light_count) * math.cos(angle_rad)
y = selected_obj.location.y + radius * math.cos(2 * math.pi * i / light_count) * math.cos(angle_rad)
z = selected_obj.location.z + radius * math.sin(angle_rad)
# Create light data object
light_data = bpy.data.lights.new(name='Light.%d' % i, type='AREA')
light_data.energy = light_power
light_data.shape = 'RECTANGLE'
light_data.size = 0.5
light_data.size_y = 0.1
light_object = bpy.data.objects.new(name='light_obj.%d' % i, object_data=light_data)
bpy.context.collection.objects.link(light_object)
# Set light position
light_object.location = (x, y, z)
# Point light towards the object
light_object.rotation_euler = light_object.rotation_euler.to_quaternion().to_euler()
look_at(light_object, selected_obj.location)
def look_at(obj, target):
""" Make the light object point towards the target """
direction = target - obj.location
rot_quat = direction.to_track_quat('-Z', 'Y')
obj.rotation_euler = rot_quat.to_euler()
class OBJECT_OT_create_three_point_lighting(bpy.types.Operator):
"""Create Three Point Lighting"""
bl_idname = 'object.create_three_point_lighting'
bl_label = 'Create Three Point Lighting'
bl_options = {'REGISTER', 'UNDO'}
light_count: bpy.props.IntProperty(name='Number of Lights', default=default_light_count, min=1, max=10)
light_power: bpy.props.FloatProperty(name='Light Power (W)', default=default_light_power, min=0)
light_angle: bpy.props.FloatProperty(name='Light Normal Height', default=default_light_angle, min=0, max=90)
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
selected_obj = context.active_object
create_lights(selected_obj, self.light_count, self.light_power, self.light_angle)
return {'FINISHED'}
# Register/Unregister classes
def register():
bpy.utils.register_class(OBJECT_OT_create_three_point_lighting)
def unregister():
bpy.utils.unregister_class(OBJECT_OT_create_three_point_lighting)
if __name__ == '__main__':
register()
# Add panel to UI for operation
bpy.types.VIEW3D_MT_object.append(lambda self, context: self.layout.operator(OBJECT_OT_create_three_point_lighting.bl_idname))
Make sure to copy and paste this script into Blender's text editor and then run it. The script is now fully standardized with English text and punctuation, which should be fully compatible with Blender's Python interpreter.