-
-
Save hyuki/bfe2aeeda13e971ab6cabc5933e6592a to your computer and use it in GitHub Desktop.
sphere2.py - BlenderでICO球、平面、カメラ、ライトを設定する
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 math | |
# Unsplash: at least 2500x2000 | |
# https://help.unsplash.com/en/articles/3878503-submission-guidelines-for-institiutions | |
bpy.context.scene.render.resolution_x = 3000 | |
bpy.context.scene.render.resolution_y = 2000 | |
# Delete all objects | |
for item in bpy.data.meshes: | |
bpy.data.meshes.remove(item) | |
for item in bpy.data.materials: | |
bpy.data.materials.remove(item) | |
for item in bpy.data.objects: | |
bpy.data.objects.remove(item) | |
# Plane | |
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) | |
# Material for plane | |
# cf. https://zenn.dev/hotcocoa/articles/5c5ab06c40862b | |
material = bpy.data.materials.new("material for plane") | |
material.use_nodes = True | |
bsdf = material.node_tree.nodes["Principled BSDF"] | |
R = 0.284 | |
G = 0.760 | |
B = 0.646 | |
A = 1 | |
bsdf.inputs[0].default_value = (R, G, B, A) | |
bsdf.inputs[6].default_value = 0 # metalic | |
bsdf.inputs[9].default_value = 0.03 # 粗さ | |
bpy.context.object.data.materials.append(material) | |
# Camera | |
bpy.ops.object.camera_add(enter_editmode=False, | |
align='VIEW', | |
location=(0, -6, 6), | |
rotation=(1, 0, 0), | |
scale=(1, 1, 1)) | |
# Icosphere | |
bpy.ops.mesh.primitive_ico_sphere_add( | |
enter_editmode=False, | |
align='WORLD', | |
location=(0, 0, 2.5), | |
subdivisions=4, | |
radius=1, | |
scale=(1, 1, 1)) | |
bpy.ops.object.shade_smooth() | |
# Material for icosphere | |
material = bpy.data.materials.new("material for icosphere") | |
material.use_nodes = True | |
bsdf = material.node_tree.nodes["Principled BSDF"] | |
R = 0.106 | |
G = 0.475 | |
B = 0.760 | |
A = 1 | |
bsdf.inputs[0].default_value = (R, G, B, A) | |
bsdf.inputs[6].default_value = 0.5 # metalic | |
bpy.context.object.data.materials.append(material) | |
# light | |
bpy.ops.object.light_add( | |
type='SPOT', | |
radius=1, | |
align='WORLD', | |
location=(0, 0, 10), | |
scale=(1, 1, 1)) | |
bpy.context.object.data.energy = 1000 | |
bpy.context.object.data.spot_size = 1.07163 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment