blender, python, sphere behavior Blender 2.8, python, article. It is a continuation. What I did today was cube placement, lighting placement, camera placement, and coloring. The movement of the sphere and the movement of the cylinder by specifying the key frame. It took some time to color the sphere. It seems that you can see that four numbers are arranged as R, G, B, alpha, but I do not know. I have posted a 1 second video blender 2.8, python. Video 1 second, 33kB on twitter. The image quality remains rough at 400px * 300px.
import bpy
# nh06 (Move cylinders and spheres with keyframe applications)
#Existing mesh, light, camera,Delete all
for item in bpy.data.objects:
bpy.data.objects.remove(item)
#Cube original script---- http://tips.hecomi.com/entry/20120818/1345307205
START = 0
END = 100
N = 3
# Add color cubes
for x in range(0, N):
for y in range(0, N):
for z in range(0, N):
# Add a color cube
bpy.ops.mesh.primitive_cube_add( location=(x*3, y*3, z*3) )
#obj = bpy.context.scene.objects.active #(old blender2.7script)
obj = bpy.context.view_layer.objects.active
#mat.diffuse_color = (x/N, y/N, z/N)#(old blender2.7script)
mat = bpy.data.materials.new('Cube')
mat.diffuse_color = (x/N, y/N, z/N, 0)
#mat.use_transparency = True #(This line is 2.Not tried in 8)
#mat.alpha = 0.6 #(This line is 2.Not tried in 8)
obj.data.materials.append(mat)
# new camera
bpy.ops.object.add(radius=1.0, type='CAMERA', enter_editmode=False, align='WORLD', location=(20.0, -6.0, 8.0), rotation=(1.4, 0.0, 1.2))
#new lamps (source stack overflow Can you add a light source in blender using python)
# create light datablock, set attributes
light_data = bpy.data.lights.new(name="light_2.80", type='POINT')
light_data.energy = 3000
# create new object with our light datablock
light_object = bpy.data.objects.new(name="light_2.80", 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 = (5, -4, 10)
# update scene, if needed
dg = bpy.context.evaluated_depsgraph_get()
dg.update()
#Background world- surface - background
bpy.data.worlds["World"].node_tree.nodes["Background"].inputs[0].default_value = (0.01, 0.15, 0.25, 1)
bpy.data.worlds["World"].node_tree.nodes["Background"].inputs[1].default_value = 0.7
#=====
# ================
#cylinder move(nh02 Motion application)
bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = 30
bpy.context.scene.frame_current = 10
# MOVE Cylinder mesh with KEY FRAME
bpy.ops.mesh.primitive_cylinder_add(rotation=(-0.8, 0.0, 0.0))
bpy.context.scene.frame_current = 1 # set frame to 1
cdnow = bpy.context.object # get new object just created
cdnow.location = (1,-1,1) # set the location
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.context.scene.frame_current = 10 # set frame to 10
cdnow.location = (1,7,7)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.context.scene.frame_current = 20 # set frame to 20
cdnow.location = (8,6,3)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.context.scene.frame_current = 30 # set frame to 30
cdnow.location = (1,-1,1)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
# ==================
# MOVE UV Sphere mesh with KEY FRAME (# Add UV Sphere)
bpy.ops.mesh.primitive_uv_sphere_add (segments=32, ring_count=16, radius=1.0, calc_uvs=True, enter_editmode=False, align='WORLD', location=(4.0, -2.0, 6.0), rotation=(0.0, 0.0, 0.0))
mat = bpy.data.materials.new('Sphere')
obj = bpy.context.view_layer.objects.active
mat.diffuse_color = (0.8, 0.8, 0.1, 0.4) # sphere color (R,G,B,Alpha)
obj.data.materials.append(mat)
bpy.context.scene.frame_current = 1 # set frame to 1
cdnow = bpy.context.object # get new object just created
cdnow.location = (4.0, -2.0, 6.0) # set the location
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.context.scene.frame_current = 15 # set frame to 15
cdnow.location = (4.0, 1.0, 7.0)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.context.scene.frame_current = 22 # set frame to 22
cdnow.location = (4,3,4)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.context.scene.frame_current = 30 # set frame to 30
cdnow.location = (4.0, -2.0, 6.0)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
# ==================
Recommended Posts