-
-
Save hyuki/1ad045dde5c741e78d3a90bdfbadf1af to your computer and use it in GitHub Desktop.
random_sphere.py - Blenderでランダムに球を出すための実験的なスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 平面と球をランダムに並べる | |
import bpy | |
import random | |
# 平面を追加します。 | |
bpy.ops.mesh.primitive_plane_add( | |
size=2, | |
enter_editmode=False, | |
align='WORLD', | |
location=(0, 0, 0), | |
scale=(1, 1, 1)) | |
bpy.ops.transform.resize(value=(100, 100, 100), | |
orient_type='GLOBAL', | |
orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), | |
orient_matrix_type='GLOBAL', | |
mirror=False, | |
use_proportional_edit=False, | |
proportional_edit_falloff='SMOOTH', | |
proportional_size=1, | |
use_proportional_connected=False, | |
use_proportional_projected=False) | |
# カメラ | |
bpy.ops.object.camera_add(enter_editmode=False, | |
align='VIEW', | |
location=(0, -6, 6), | |
rotation=(1, 0, 0), | |
scale=(1, 1, 1)) | |
# ICO球 | |
COUNT = 3 | |
HEIGHT = 5 | |
for x in range(COUNT): | |
for y in range(COUNT): | |
z = random.random() * HEIGHT * 2 - HEIGHT | |
r = random.random() | |
bpy.ops.mesh.primitive_ico_sphere_add( | |
enter_editmode=False, | |
align='WORLD', | |
location=(x, y, z), | |
subdivisions=4, | |
radius=r, | |
scale=(1, 1, 1)) | |
z = random.random() * HEIGHT * 2 - HEIGHT | |
r = random.random() | |
bpy.ops.mesh.primitive_ico_sphere_add( | |
enter_editmode=False, | |
align='WORLD', | |
location=(-x, y, z), | |
subdivisions=4, | |
radius=r, | |
scale=(1, 1, 1)) | |
# ライト | |
bpy.ops.object.light_add( | |
type='SPOT', | |
radius=1, | |
align='WORLD', | |
location=(0, 0, 0), | |
scale=(1, 1, 1)) | |
# bpy.context.object.data.energy = 3000 | |
# bpy.context.object.data.spot_size = 2.62148 | |
# すべて選択はどうするんだろう | |
# bpy.ops.object.shade_smooth() | |
# bpy.data.materials["Material"].node_tree.nodes["Subsurface Scattering"].inputs[0].default_value = (0.8, 0.71426, 0.223951, 1) | |
# bpy.data.materials["Material"].node_tree.nodes["Subsurface Scattering"].inputs[0].default_value = (0.8, 0.71426, 0.223951, 1) | |
Author
hyuki
commented
Jul 7, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment