Dies ist ein Experiment, bei dem 3 * 5 * 5 Kugeln hergestellt werden und einige von ihnen gemäß den z-Koordinatenbedingungen ausgewählt und gefärbt werden. Wenn ich nicht sicher war, ob ich es bald tun könnte, weil es eine Erweiterung des letzten Males war, habe ich lange gebraucht, um über "Mehrfachnetzauswahl" allein nachzudenken. Nach vielen Recherchen fand ich heraus, dass es eine bequeme Möglichkeit gibt, obj.location.z anzugeben. Die in 3 Farben angegebenen Farbtöne stammen von "Bochan Dumpling / Tsubo and Confectionery". Zusätzlich zu der Methode zum Erstellen vieler Objekte und zum Auswählen eines Teils sollte es eine Methode zum Erstellen und Duplizieren eines Teils geben. Daher plane ich, dies auch beim nächsten Mal in Frage zu stellen.
Außerdem habe ich auf die Auswahl der Objektauswahl und die Aktivierung der Aktivierung hingewiesen. Aktivierung des Objekts [4. Python x Blender]. Achten Sie jedoch darauf, dass es sich um Mixer 2.7 handelt. Video 1 Sekunde auf Twitter gepostet. Mixer 2.9, Python. Animation 1 Sek. Video 1 Sekunde (Wir freuen uns über Ihr Feedback. Bitte teilen Sie uns mit, ob Sie Python-Skripte effizienter schreiben können oder ob Sie diese eine Zeile nicht benötigen.)
#bpy_nh21 (bochan dango) create spheres, select multiple spheres, assign material
import bpy
# ========= DELETE ALL mesh, light, camera, =========
for item in bpy.data.objects:
bpy.data.objects.remove(item)
# ========= 1st FLOOR height
z1f = -6 # first floor sphere height
# ============== "light_spot1" ==== HIGH
# create light datablock, set attributes
light_data = bpy.data.lights.new(name="light_spot1", type='SPOT')
light_data.energy = 700
# 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, -7, 4+z1f)
light_object1.delta_rotation_euler = (1.3, 0, -0.3) #Schauen Sie direkt auf Null Null Null.
# update scene, if needed
dg = bpy.context.evaluated_depsgraph_get()
dg.update()
# ============== "light_spot2" ==== HIGH
# create light datablock, set attributes
light_data = bpy.data.lights.new(name="light_spot1", type='SPOT')
light_data.energy = 2000
# 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 = (10, -7, 7+z1f)
light_object1.delta_rotation_euler = (1.3, 0, 0.3) #Schauen Sie direkt auf Null Null Null.
# update scene, if needed
dg = bpy.context.evaluated_depsgraph_get()
dg.update()
#bpy.ops.object.camera_add(enter_editmode=False, align='VIEW', location=(10, -10, 8), rotation=(1.2, 0, 0.5)) # (fixed CAMERA)
# ==== hex COLOR CODE to R,G,B
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
# ==== spheres 5*5*3
for x in range (5):
for y in range (5):
for z in range (3):
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, align='WORLD', location=(x*2, y*2, z*2+z1f), scale=(1, 1, 1))
for obj in bpy.data.objects: #scan every object
obj.select_set(False) # deselect all
# ==== select (obj.location.z) lowest 5*5
for obj in bpy.data.objects: #scan every object, select multiple objects with Z
loc_z = (obj.location.z)
if loc_z == z1f:
obj.select_set(True)
# ==== set material 1st floor
h = 0x8b4513 #saddlebrown#8b4513
for x in bpy.context.selected_objects:
obj = x.data
mat1 = bpy.data.materials.new('Brown')
mat1.diffuse_color = (*hex_to_rgb(h), 0)
obj.materials.append(mat1)
for obj in bpy.data.objects: #scan every object
obj.select_set(False) # deselect all
# ==== select with z 2nd floor
for obj in bpy.data.objects: #scan every object, select multiple objects with Z
loc_z = (obj.location.z)
if loc_z == z1f+2:
obj.select_set(True)
bpy.data.objects['light_spot1'].select_set(False)
# ==== set material 2nd floor
h = 0xffdead #navajowhite#ffdead
for x in bpy.context.selected_objects:
obj = x.data
mat2 = bpy.data.materials.new('n_white')
mat2.diffuse_color = (*hex_to_rgb(h), 0)
obj.materials.append(mat2)
for obj in bpy.data.objects: #scan every object
obj.select_set(False) # deselect all
# ==== select with z 3rd floor
for obj in bpy.data.objects: #scan every object, select multiple objects with Z
loc_z = (obj.location.z)
if loc_z == z1f+4:
obj.select_set(True)
bpy.data.objects['light_spot1'].select_set(False)
# ==== set material 3rd floor
h = 0x808000 #olive#808000
for x in bpy.context.selected_objects:
obj = x.data
mat3 = bpy.data.materials.new('olive')
mat3.diffuse_color = (*hex_to_rgb(h), 0)
obj.materials.append(mat3)
for obj in bpy.data.objects: #scan every object
obj.select_set(False) # deselect all
# ====== add a camera, camera movement (bpy_nh13)
bpy.ops.curve.primitive_bezier_circle_add(enter_editmode=False, align='WORLD', location=(0, 0, 0))
bpy.context.object.scale[0] = 12
bpy.context.object.scale[1] = 12
bpy.ops.object.empty_add(type='CUBE', align='WORLD', location=(0, 0, 0))
bpy.ops.object.camera_add(enter_editmode=False, align='VIEW', location=(0, 0, 0), rotation=(0, 0, 0))
bpy.data.objects['Empty'].select_set(True)
bpy.data.objects['Camera'].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects['Empty']
bpy.ops.object.parent_set(type='OBJECT')
bpy.data.objects['Camera'].select_set(False)
bpy.data.objects['Empty'].select_set(True)
bpy.ops.object.constraint_add(type='FOLLOW_PATH')
bpy.context.object.constraints["Follow Path"].target = bpy.data.objects["BezierCircle"]
bpy.context.object.constraints["Follow Path"].use_curve_follow = True
bpy.context.object.constraints["Follow Path"].use_fixed_location = True
bpy.data.objects['Empty'].select_set(False)
bpy.data.objects['Camera'].select_set(True)
bpy.ops.object.constraint_add(type='TRACK_TO')
bpy.context.object.constraints["Track To"].target = bpy.data.objects["Sphere.032"]
bpy.context.object.constraints["Track To"].up_axis = 'UP_Y'
bpy.context.object.constraints["Track To"].track_axis = 'TRACK_NEGATIVE_Z' #5m00sec
#Camera Keyframe #(Insert keyframe to object's Offset Factor Python API - stack exchange)
bpy.data.objects['Camera'].select_set(False)
bpy.data.objects['Empty'].select_set(True)
bpy.context.scene.frame_current = 1
bpy.context.object.constraints["Follow Path"].offset_factor = 0
ob = bpy.context.object
# ob.constraints['Follow Path']
# bpy.data.objects['Empty'].constraints["Follow Path"]
# [bpy.data.objects['Empty'].constraints["Follow Path"]]
con = ob.constraints.get("Follow Path")
con.offset_factor = 0.0
con.keyframe_insert("offset_factor", frame=1)
con.offset_factor = 0.15
con.keyframe_insert("offset_factor", frame=8)
con.offset_factor = 0.4
con.keyframe_insert("offset_factor", frame=16)
con.offset_factor = 0.3
con.keyframe_insert("offset_factor", frame=18)
con.offset_factor = 0.0
con.keyframe_insert("offset_factor", frame=30)
# =======
Recommended Posts