Загрузка данных


import bpy
import random
import math

bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)

def c_mat(color, em=0.0):
    m = bpy.data.materials.new("Material")
    m.use_nodes = True
    b = m.node_tree.nodes.get("Principled BSDF")
    b.inputs['Base Color'].default_value = color
    if em > 0:
        b.inputs['Emission Color'].default_value = color
        b.inputs['Emission Strength'].default_value = em
    return m

m_wat = c_mat((0.02, 0.15, 0.35, 1))
m_wd = c_mat((0.2, 0.1, 0.05, 1))
m_sl = c_mat((0.8, 0.75, 0.7, 1))
m_lt = c_mat((1.0, 0.7, 0.1, 1), 8.0)
m_rk = c_mat((0.15, 0.15, 0.18, 1))
m_rn = c_mat((0.6, 0.8, 1.0, 1))

bpy.ops.mesh.primitive_plane_add(size=30, location=(0, 0, 0))
bpy.context.active_object.data.materials.append(m_wat)

bpy.ops.mesh.primitive_cube_add(size=1, location=(0, 0, 0.4))
bpy.context.active_object.scale = (4, 1.4, 0.8)
bpy.ops.object.transform_apply(scale=True)
bpy.context.active_object.data.materials.append(m_wd)

bpy.ops.mesh.primitive_cone_add(vertices=16, radius1=0.7, depth=1.6, location=(2.8, 0, 0.4), rotation=(0, math.radians(90), 0))
bpy.context.active_object.scale = (1, 1, 0.5)
bpy.ops.object.transform_apply(scale=True)
bpy.context.active_object.data.materials.append(m_wd)

bpy.ops.mesh.primitive_cube_add(size=1, location=(-1.2, 0, 1.2))
bpy.context.active_object.scale = (1.2, 1.0, 0.8)
bpy.ops.object.transform_apply(scale=True)
bpy.context.active_object.data.materials.append(m_wd)

bpy.ops.mesh.primitive_cylinder_add(radius=0.08, depth=4, location=(0.8, 0, 2.8))
bpy.context.active_object.data.materials.append(m_wd)

bpy.ops.mesh.primitive_cube_add(size=1, location=(1.0, 0, 3.2))
bpy.context.active_object.scale = (0.05, 2.0, 2.2)
bpy.ops.object.transform_apply(scale=True)
bpy.context.active_object.data.materials.append(m_sl)

bpy.ops.mesh.primitive_cylinder_add(radius=0.15, depth=0.3, location=(-1.2, 0, 1.75))
bpy.context.active_object.data.materials.append(m_lt)

for _ in range(12):
    rx = random.uniform(-12, 12)
    ry = random.uniform(-12, 12)
    if -4 < rx < 5 and -2.5 < ry < 2.5:
        continue
    bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=1, radius=random.uniform(0.5, 2.0), location=(rx, ry, -0.2))
    bpy.context.active_object.scale = (1, 1, random.uniform(0.5, 1.5))
    bpy.ops.object.transform_apply(scale=True)
    bpy.context.active_object.data.materials.append(m_rk)

bpy.ops.object.light_add(type='POINT', location=(-1.2, 0, 2.0))
bpy.context.active_object.data.energy = 250
bpy.context.active_object.data.color = (1.0, 0.7, 0.1)

bpy.ops.object.light_add(type='SUN', location=(5, -5, 8), rotation=(0.8, 0, 0.6))
bpy.context.active_object.data.energy = 0.4
bpy.context.active_object.data.color = (0.2, 0.4, 0.8)

bpy.ops.mesh.primitive_cylinder_add(radius=0.015, depth=0.2, location=(0, 0, -10))
rn_obj = bpy.context.active_object
rn_obj.data.materials.append(m_rn)

bpy.ops.mesh.primitive_plane_add(size=25, location=(0, 0, 12))
em = bpy.context.active_object
mod = em.modifiers.new("ParticleSystem", 'PARTICLE_SYSTEM')
ps = em.particle_systems[0].settings
ps.count = 2500
ps.frame_end = 250
ps.lifetime = 60
ps.render_type = 'OBJECT'
ps.instance_object = rn_obj
ps.effector_weights.gravity = 1.0
em.show_instancer_for_viewport = False
em.show_instancer_for_render = False

bpy.ops.object.camera_add(location=(9, -10, 6), rotation=(math.radians(65), 0, math.radians(42)))
bpy.context.scene.camera = bpy.context.active_object

bpy.ops.object.select_all(action='DESELECT')
bpy.context.view_layer.update()