Blender 2.9, Python background light color test

It is a test with blender, python, background light color, RGB hexadecimal specification. The cube is illuminated with a background light and three spotlights. Examples of colors are aquamarine # 7fffd4, papayawhip # ffefd5 powderblue # b0e0e6 darkkhaki # bdb76b Impression that the area can be used. Today there is no camera movement and only still images without videos. bpy_bkg_col_m.png

Of the three images, the upper one is 0.1 times the background light, the second is 0.9 times, and the third is 0.5 times.

import bpy

# ========= DELETE ALL mesh, light, camera =========
for item in bpy.data.objects:
    bpy.data.objects.remove(item)
# =========

def hex_to_rgb( hex_value ):
    b = (hex_value & 0xFF) / 255.0
    g = ((hex_value >> 8) & 0xFF) / 255.0
    r = ((hex_value >> 16) & 0xFF) / 255.0
    return r, g, b
h = 0xb0e0e6
# aquamarine #7fffd4,  papayawhip #ffefd5  powderblue #b0e0e6 darkkhaki #bdb76b

#bpy.data.worlds["World"].node_tree.nodes["Background"].inputs[0].default_value = (R, G, B, 1)
bpy.data.worlds["World"].node_tree.nodes["Background"].inputs[0].default_value = (*hex_to_rgb(h), 1)
bpy.data.worlds["World"].node_tree.nodes["Background"].inputs[1].default_value = 0.5

for i in range(5):
    for j in range(5):
        for k in range(5):
            bpy.ops.mesh.primitive_cube_add(size=0.5, enter_editmode=False, align='WORLD', location=(i, j, k), scale=(1, 1, 1))
            obj = bpy.context.view_layer.objects.active
            mat = bpy.data.materials.new('Cube')
            r1=0.1+ 0.15*i
            g1=0.1+ 0.15*j
            b1=0.1+ 0.15*k
            mat.diffuse_color = (r1, g1, b1, 0) #====== random BROWN COLOR
            obj.data.materials.append(mat)

# new lamps ( stack overflow Can you add a light source in blender using python)
# =============="light_spot3"
# create light datablock, set attributes
light_data = bpy.data.lights.new(name="light_spot3", type='SPOT')
light_data.energy = 2000
# create new object with our light datablock
light_object = bpy.data.objects.new(name="light_spot3", object_data=light_data)
# link light object
bpy.context.collection.objects.link(light_object)
# make it active 
bpy.context.view_layer.objects.active = light_object
#change location
light_object.location = (2, -2, 3)
light_object.delta_rotation_euler = (1.6, 0, 0) #Look straight down at zero zero zero.
# update scene, if needed
dg = bpy.context.evaluated_depsgraph_get() 
dg.update()

# =============="light_spot2"
# create light datablock, set attributes
light_data = bpy.data.lights.new(name="light_spot2", type='SPOT')
light_data.energy = 2000
# create new object with our light datablock
light_object = bpy.data.objects.new(name="light_spot2", object_data=light_data)
# link light object
bpy.context.collection.objects.link(light_object)
# make it active 
bpy.context.view_layer.objects.active = light_object
#change location
light_object.location = (2, -4, 8)
light_object.delta_rotation_euler = (1.5, 0, 0) #Look straight down at zero zero zero.
# update scene, if needed
dg = bpy.context.evaluated_depsgraph_get() 
dg.update()
# ============== "light_spot1"
# create light datablock, set attributes
light_data = bpy.data.lights.new(name="light_spot1", type='SPOT')
light_data.energy = 3000
# create new object with our light datablock
light_object1 = bpy.data.objects.new(name="light_spot1", object_data=light_data)
# link light object
bpy.context.collection.objects.link(light_object1)
# make it active 
bpy.context.view_layer.objects.active = light_object1
#change location
light_object1.location = (5, -5, 8)
light_object1.delta_rotation_euler = (1.3, 0, 0.3) #Look straight down at zero zero zero.
# update scene, if needed
dg = bpy.context.evaluated_depsgraph_get() 
dg.update()
# ================

bpy.ops.object.camera_add(enter_editmode=False, align='VIEW', location=(6, -6, 11), rotation=(45/180*3.14, -15/180*3.14, 45/180*3.14))

Recommended Posts

Blender 2.9, Python background light color test
blender, python, spiral staircase, color
Blender 2.9, Python, hexadecimal color specification
Blender 2.8, Python, light Spot lighting
Blender 2.9 Python Extrude extrude
Python Integrity Test
Blender 2.8, Python, camera movement, random number color specification
Primality test by Python
Primality test with Python
Python basics 8 numpy test
Python test package memo
Primality test with python
Run Blender with python
blender, python, sphere behavior
Fill the background with a single color with OpenCV2 + Python
Blender 2.8, Python Cube Scaling
Operate Blender with Python
[ev3dev × Python] Color sensor
python tag integration test
[Blender x Python] Blender Python tips (11/100)
python unit test template
Light blue with AtCoder @Python
Algorithm in Python (primality test)
Blender 2.9, Python Buildings, Cars, Videos
[Python] Adjusting the color bar
Blender 2.9, Python Odd Even Building
Python template for Codeforces-manual test-
Python debug and test module
Blender Python API in Houdini (Python 3)
Generate 8 * 8 (64) cubes in Blender Python
Set python test in jenkins
Color extraction with Python + OpenCV solved the mystery of the green background