Results 1 to 19 of 19
  1. #1

    [PlugIn] 3-Way Lighting Script

    Hello out there,

    I am pretty much new in the Blender World, coming from Web-Development mainly and got yesterday into Blender Scripting, so I can present you here my first Plugin:

    TriLightning.png

    3-Way Lighting


    • Adds 3 Lamps from different, customizable Angles to the Scene
    • Placement is related to the Keyobject (Must be selected!) and the active Camera
    • You can set Contrast, Height, Distance, LampType and also the Baseenergy
    • Contrast: 0-100%: The Percentage of the Baseenergy which the Background+Filllight has
      -100%-0: Opposite effect, here the Keylight gets the percentage of the Baseenergy


    The other options should be pretty much clear, please keep in mind that you have to select an Object when adding this, since it uses it for the Distance calculation and such.

    Where can I add the Tri-Lighting?

    Object Mode -> Object Tools -> "Add Tri-Lighting"

    How to Install:

    Drag it in your Addons Folder and activate over "Object -> Tri-Lighting"

    What you can do?

    Give me some Feedback and also some Feature Ideas!

    Thanks also to the people from #blender and #blendercoders for the Ideas and coding help!

    Best Regards,
    Daniel
    Attached Files Attached Files
    Last edited by Schalla; 17-Sep-13 at 19:11. Reason: New Version



  2. #2
    thnx a lot
    can i bsurf your gstretch, baby?
    blog site | fb page
    addons: dyntopo plus, ice-tools-pro



  3. #3
    You're welcome! Any feedback so far?



  4. #4
    thanks a lot for this Little gem ;-)



  5. #5
    Member didli's Avatar
    Join Date
    Apr 2007
    Location
    Paris, France
    Posts
    9
    For a first, it's great. A little gem, indeed. Do you happen to know this one in this forum ?
    http://blenderartist.org/forum/showt...Script/page27&



  6. #6
    Thank you for creating this add on. It's performed flawlessly, and has saved me a ton of set-up time.



  7. #7
    Member
    Join Date
    Sep 2012
    Posts
    2,454
    Thank you but doesn't run anymore.
    Got an error on 2.72 RC1:
    Traceback (most recent call last):
    File "C:\Programi\b272\2.72\scripts\modules\addon_utils .py", line 312, in enable
    mod.register()
    File "C:\Users\se\AppData\Roaming\Blender Foundation\Blender\2.72\scripts\addons\trilighting .py", line 159, in register
    bpy.types.VIEW3D_PT_tools_objectmode.append(panel_ func)
    AttributeError: 'RNA_Types' object has no attribute 'VIEW3D_PT_tools_objectmode'



  8. #8
    Member
    Join Date
    Sep 2012
    Posts
    2,454
    Problem persists in official 2.72...



  9. #9
    Member
    Join Date
    Jan 2014
    Location
    Dresden
    Posts
    677
    Fix it for 2.72

    need a new notation for location

    old one: bpy.types.VIEW3D_PT_tools_objectmode.append(panel_ func)
    new one: bpy.types.VIEW3D_PT_tools_object.append(panel_func )
    better: bpy.types.VIEW3D_PT_tools_add_object.append(panel_ func)

    Code:
    bl_info = {
        "name": "Tri-Lighting Creator",
        "category": "Object",
        "author": "Daniel Schalla",
        "version": (1, 0),
        "blender": (2, 68, 0),
        "location": "Object Mode > Toolbar > Create > Add Primitiv > Add Tri-Lighting",
        "description": "Add 3 Point Lighting to selected Object"
    }
    
    
    import bpy
    import mathutils
    from bpy.props import *
    import math
    
    
    class TriLighting(bpy.types.Operator):
        """TriL ightning"""
        bl_idname = "object.trilighting"        # unique identifier for buttons and menu items to reference.
        bl_label = "Tri-Lighting Creator"         # display name in the interface.
        bl_options = {'REGISTER', 'UNDO'}  # enable undo for the operator.
    
        height = bpy.props.FloatProperty(name="Height", default=5)
        distance = bpy.props.FloatProperty(name="Distance",default=5,min=0.1,subtype="DISTANCE")
        energy = bpy.props.IntProperty(name="Base Energy",default=3,min=1)
        contrast = bpy.props.IntProperty(name="Contrast",default=50,min=-100,max=100,subtype="PERCENTAGE")
        leftangle = bpy.props.IntProperty(name="Left Angle", default=26, min=1, max=90, subtype="ANGLE")
        rightangle = bpy.props.IntProperty(name="Right Angle", default=45, min=1, max=90, subtype="ANGLE")
        backangle = bpy.props.IntProperty(name="Back Angle", default=235, min=90, max=270, subtype="ANGLE")
    
    
        Light_Type_List = [('POINT','Point','Point Light'),
                            ('SUN','Sun','Sun Light'),
                            ('SPOT','Spot','Spot Light'),
                            ('HEMI','Hemi','Hemi Light'),
                            ('AREA','Area','Area Light')]
        primarytype = EnumProperty( attr='tl_type',
                name='Key Type',
                description='Choose the type off Key Light you would like',
                items = Light_Type_List, default = 'HEMI')
    
        secondarytype = EnumProperty( attr='tl_type',
                name='Fill+Back Type',
                description='Choose the type off secondary Light you would like',
                items = Light_Type_List, default = 'POINT')
    
    
        def execute(self, context):
            scene = context.scene
            view = context.space_data
            if view.type == 'VIEW_3D' and not view.lock_camera_and_layers:
                camera = view.camera
            else:
                camera = scene.camera
    
            if (camera is None):
    
                cam_data= bpy.data.cameras.new(name='Camera')
                cam_obj = bpy.data.objects.new(name='Camera',object_data=cam_data)
                scene.objects.link(cam_obj)
                scene.camera=cam_obj
                bpy.ops.view3d.camera_to_view()
                camera=cam_obj
                bpy.ops.view3d.viewnumpad(type='TOP')
    
            obj = bpy.context.scene.objects.active
    
            #####Calculate Energy for each Lamp
    
            if(self.contrast>0):
                keyEnergy=self.energy
                backEnergy=(self.energy/100)*abs(self.contrast)
                fillEnergy=(self.energy/100)*abs(self.contrast)
            else:
                keyEnergy=(self.energy/100)*abs(self.contrast)
                backEnergy=self.energy
                fillEnergy=self.energy
    
            print(self.contrast)
            #####Calculate Direction for each Lamp
    
            #Calculate current Distance and get Delta
            obj_position=obj.location
            cam_position=camera.location
    
            delta_position=cam_position-obj_position
            vector_length=math.sqrt((pow(delta_position.x,2)+pow(delta_position.y,2)+pow(delta_position.z,2)))
            single_vector=(1/vector_length)*delta_position
    
            #Calc back position
            singleback_vector=single_vector.copy()
            singleback_vector.x=math.cos(math.radians(self.backangle))*single_vector.x+(-math.sin(math.radians(self.backangle))*single_vector.y)
            singleback_vector.y=math.sin(math.radians(self.backangle))*single_vector.x+(math.cos(math.radians(self.backangle))*single_vector.y)
            backx=obj_position.x+self.distance*singleback_vector.x
            backy=obj_position.y+self.distance*singleback_vector.y
    
            backData = bpy.data.lamps.new(name="TriLamp-Back", type=self.secondarytype)
            backData.energy=backEnergy
    
            backLamp = bpy.data.objects.new(name="TriLamp-Back", object_data=backData)
            scene.objects.link(backLamp)
            backLamp.location = (backx, backy, self.height)
    
            trackToBack=backLamp.constraints.new(type="TRACK_TO")
            trackToBack.target=obj
            trackToBack.track_axis="TRACK_NEGATIVE_Z"
            trackToBack.up_axis="UP_Y"
    
            #Calc right position
            singleright_vector=single_vector.copy()
            singleright_vector.x=math.cos(math.radians(self.rightangle))*single_vector.x+(-math.sin(math.radians(self.rightangle))*single_vector.y)
            singleright_vector.y=math.sin(math.radians(self.rightangle))*single_vector.x+(math.cos(math.radians(self.rightangle))*single_vector.y)
            rightx=obj_position.x+self.distance*singleright_vector.x
            righty=obj_position.y+self.distance*singleright_vector.y
    
            rightData = bpy.data.lamps.new(name="TriLamp-Fill", type=self.secondarytype)
            rightData.energy=fillEnergy
            rightLamp = bpy.data.objects.new(name="TriLamp-Fill", object_data=rightData)
            scene.objects.link(rightLamp)
            rightLamp.location = (rightx, righty, self.height)
            trackToRight=rightLamp.constraints.new(type="TRACK_TO")
            trackToRight.target=obj
            trackToRight.track_axis="TRACK_NEGATIVE_Z"
            trackToRight.up_axis="UP_Y"
    
    
            #Calc left position
            singleleft_vector=single_vector.copy()
            singleleft_vector.x=math.cos(math.radians(-self.leftangle))*single_vector.x+(-math.sin(math.radians(-self.leftangle))*single_vector.y)
            singleleft_vector.y=math.sin(math.radians(-self.leftangle))*single_vector.x+(math.cos(math.radians(-self.leftangle))*single_vector.y)
            leftx=obj_position.x+self.distance*singleleft_vector.x
            lefty=obj_position.y+self.distance*singleleft_vector.y
    
            leftData = bpy.data.lamps.new(name="TriLamp-Key", type=self.primarytype)
            leftData.energy=keyEnergy
    
            leftLamp = bpy.data.objects.new(name="TriLamp-Key", object_data=leftData)
            scene.objects.link(leftLamp)
            leftLamp.location = (leftx, lefty, self.height)
            trackToLeft=leftLamp.constraints.new(type="TRACK_TO")
            trackToLeft.target=obj
            trackToLeft.track_axis="TRACK_NEGATIVE_Z"
            trackToLeft.up_axis="UP_Y"
    
    
            return {'FINISHED'}
    
    
    def panel_func(self, context):
    
        self.scn = context.scene
        self.layout.label(text="Tri-Lighting:")
        self.layout.operator("object.trilighting", text="Add Tri-Lighting")
    
    
    def register():
        bpy.utils.register_class(TriLighting)
        bpy.types.VIEW3D_PT_tools_add_object.append(panel_func)
    
    def unregister():
        bpy.utils.unregister_class(TriLighting)
        bpy.types.VIEW3D_PT_tools_add_object.remove(panel_func)
    
    if __name__ == "__main__":
        register()
    Last edited by mkbreuer; 17-Oct-14 at 20:57.



  10. #10
    mkbreuer, is your script above the script for the addon that will work in2.72? Do we simply paste what is above in the text editor and save it as a trilighting.py file?



  11. #11
    Member
    Join Date
    Jan 2014
    Location
    Dresden
    Posts
    677
    Originally Posted by bkjernisted View Post
    mkbreuer, is your script above the script for the addon that will work in2.72? Do we simply paste what is above in the text editor and save it as a trilighting.py file?
    Hi bkjernisted

    Sorry i forgot the close bracket on the top of the script.

    You can copy and past Schallas script into the blender texteditor and save it, as you wrote, as a phyton script > trilighting.py file
    I only changed the location for it: Object Mode > Toolbar > Create > Add Primitiv > Add Tri-Lighting
    Last edited by mkbreuer; 17-Oct-14 at 20:57.



  12. #12
    Member
    Join Date
    Sep 2012
    Posts
    2,454
    Thank you. Works OK!



  13. #13
    Member
    Join Date
    May 2007
    Location
    Florence (Italy)
    Posts
    119
    Hello, I tried the addon and I get this error
    "Traceback (most recent call last):
    File "C:\Users\afranx\AppData\Roaming\Blender Foundation\Blender\2.72\scripts\addons\trilighting .py", line 84, in execute
    obj_position=obj.location
    AttributeError: 'NoneType' object has no attribute 'location'

    location: <unknown location>:-1"
    Can you help me?
    * win7 64, I7 3770, 8gb ram, gtx580 (3gb) + gtx550 (1gb) * Imac 27" macosx 10.5.8 *



  14. #14
    Hey there,

    I am sorry for the late response, I am not using Blender anymore since I lack time, however, I will look into the issue the next 2 weeks
    and update the script again.

    Regards,
    Schalla



  15. #15
    Member
    Join Date
    Mar 2002
    Location
    California
    Posts
    2,118
    Any chance of getting this script updated for 2.47-2.75?
    At some point in life you stop being the man you are and start being the man you always wanted to be. ------ Bruce Springsteen.



  16. #16



  17. #17
    Member
    Join Date
    Mar 2002
    Location
    California
    Posts
    2,118
    Mete I know that this is an old tread but I am reinstalling blender on a new machine. The link that you gave in the last post gives a 404 error
    At some point in life you stop being the man you are and start being the man you always wanted to be. ------ Bruce Springsteen.



  18. #18
    Member Meta-Androcto's Avatar
    Join Date
    Aug 2006
    Location
    australia
    Posts
    4,024
    SHABA1
    hi, just so happens the addon is in Blender 2.79 Advanced Objects Addon.
    You can get this by using a nightly build of Blender, or just wait a while longer for 2.79 to be released



  19. #19
    Member
    Join Date
    Mar 2002
    Location
    California
    Posts
    2,118
    Thanks Meta. Now that I have a halfway decent machine on which to run blender. I think I will wait for the new release
    At some point in life you stop being the man you are and start being the man you always wanted to be. ------ Bruce Springsteen.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •