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


import bpy
import math
import random

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

def c_m(c, e=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 = c
    if e > 0:
        b.inputs['Emission Color'].default_value = c
        b.inputs['Emission Strength'].default_value = e
    return m

m_w = c_m((0.01, 0.05, 0.2, 1))
m_s = c_m((0.2, 0.1, 0.05, 1))
m_l = c_m((0.8, 0.75, 0.7, 1))
m_k = c_m((0.5, 0.1, 0.6, 1))
m_m = c_m((0.8, 0.6, 0.4, 1))

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

bpy.ops.mesh.primitive_cube_add(size=1, location=(0, -10, 0.4))
ship = bpy.context.active_object
ship.scale = (2.5, 6.0, 1.2)
bpy.ops.object.transform_apply(scale=True)
ship.data.materials.append(m_s)

bpy.ops.mesh.primitive_cylinder_add(radius=0.15, depth=5, location=(0, -10, 3))
mast = bpy.context.active_object
mast.data.materials.append(m_s)
mast.parent = ship

bpy.ops.mesh.primitive_cube_add(size=1, location=(0, -9.5, 3.5))
sail = bpy.context.active_object
sail.scale = (3.0, 0.1, 2.5)
bpy.ops.object.transform_apply(scale=True)
sail.data.materials.append(m_l)
sail.parent = ship

b_pts = []
bpy.ops.mesh.primitive_cube_add(size=0.4, location=(0, -9, 2))
b_pts.append(bpy.context.active_object)
bpy.ops.mesh.primitive_cube_add(size=0.25, location=(0, -9, 2.5))
b_pts.append(bpy.context.active_object)
bpy.ops.mesh.primitive_cube_add(size=0.15, location=(0.4, -9, 2))
b_pts.append(bpy.context.active_object)
bpy.ops.mesh.primitive_cube_add(size=0.15, location=(-0.4, -9, 2))
b_pts.append(bpy.context.active_object)
bpy.ops.mesh.primitive_cube_add(size=0.15, location=(0.2, -9, 1.5))
b_pts.append(bpy.context.active_object)
bpy.ops.mesh.primitive_cube_add(size=0.15, location=(-0.2, -9, 1.5))
b_pts.append(bpy.context.active_object)

bpy.ops.object.select_all(action='DESELECT')
for p in b_pts:
    p.select_set(True)
    p.data.materials.append(m_m)
bpy.context.view_layer.objects.active = b_pts[0]
bpy.ops.object.join()
dancer = bpy.context.active_object
dancer.parent = ship

tents = []
for i in range(5):
    x = random.choice([-6, 6]) + random.uniform(-2, 2)
    y = random.uniform(-10, 10)
    bpy.ops.mesh.primitive_cone_add(radius1=1.2, depth=8, location=(x, y, -4))
    t = bpy.context.active_object
    t.data.materials.append(m_k)
    tents.append(t)

bpy.ops.mesh.primitive_plane_add(size=60, location=(0, 0, 20))
em = bpy.context.active_object
mod = em.modifiers.new("ParticleSystem", 'PARTICLE_SYSTEM')
ps = em.particle_systems[0].settings
ps.count = 8000
ps.frame_end = 250
ps.lifetime = 60
ps.render_type = 'LINE'
ps.effector_weights.gravity = 2.0
em.show_instancer_for_viewport = False
em.show_instancer_for_render = False

bpy.ops.object.light_add(type='SUN', location=(0, 0, 10))
bpy.context.active_object.data.energy = 0.05
bpy.context.active_object.data.color = (0.1, 0.2, 0.4)

bpy.ops.object.light_add(type='POINT', location=(0, 0, 25))
lt = bpy.context.active_object
lt.data.color = (0.8, 0.9, 1.0)

bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = 250

for f in range(1, 251):
    ship.location.y = -15 + (f / 250) * 30
    ship.rotation_euler.x = math.sin(f * 0.1) * 0.15
    ship.rotation_euler.y = math.sin(f * 0.05) * 0.2
    ship.keyframe_insert(data_path="location", frame=f)
    ship.keyframe_insert(data_path="rotation_euler", frame=f)

    dancer.rotation_euler.x = f * 0.6
    dancer.rotation_euler.y = f * 0.8
    dancer.rotation_euler.z = f * 1.2
    dancer.location.z = 1.5 + abs(math.sin(f * 0.4)) * 1.5
    dancer.keyframe_insert(data_path="rotation_euler", frame=f)
    dancer.keyframe_insert(data_path="location", frame=f)

    for idx, t in enumerate(tents):
        t.location.z = -3 + math.sin(f * 0.1 + idx) * 4
        t.rotation_euler.x = math.sin(f * 0.15 + idx) * 0.6
        t.rotation_euler.y = math.cos(f * 0.12 + idx) * 0.6
        t.keyframe_insert(data_path="location", frame=f)
        t.keyframe_insert(data_path="rotation_euler", frame=f)

    if f % random.randint(30, 60) in (0, 2, 4):
        lt.data.energy = 500000
    else:
        lt.data.energy = 0
    lt.data.keyframe_insert(data_path="energy", frame=f)

bpy.ops.object.camera_add(location=(18, -18, 12), rotation=(math.radians(65), 0, math.radians(45)))
bpy.context.scene.camera = bpy.context.active_object

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