Files
LihonT/scripts/promo3d/promo.py
cheb0chik b78266d40c LihonT 3 Luna beta 1: the site look, the floating island, full-screen video and the agent
The "Как сайт" look by default, also in TikTok's settings and all their sub-pages, where every item is its own rounded row.
The bottom bar floats as an island, 9:16 videos reach under it, the seek bar is lifted, thicker and on by default, the
comment input is an island too, and "only sound" downloads are saved as audio. The LihonT agent: a chat that makes cards and
slides for a photo post, looks things up on the web, signs in with Telegram and has a daily limit on the server. Also the
нейронка.рус landing page and the 3D-phone promo scripts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:10:45 +03:00

226 lines
8.3 KiB
Python

"""A phone in 3D with a LihonT screen on it, rendered by Blender in the background.
blender -b --python phone.py -- <screen.png> <out.png> [yaw_deg] [pitch_deg]
"""
import math
import sys
import bmesh
import bpy
argv = sys.argv[sys.argv.index("--") + 1:]
SCREEN, OUT = argv[0], argv[1]
YAW = float(argv[2]) if len(argv) > 2 else -22.0
PITCH = float(argv[3]) if len(argv) > 3 else 8.0
ANIM = float(argv[4]) if len(argv) > 4 else 0
CUTS = [float(t) for t in argv[5].split(",")] if len(argv) > 5 else []
FLY = argv[6].split(",") if len(argv) > 6 else []
SPINS = int(argv[7]) if len(argv) > 7 else 99
VERTICAL = ANIM > 0
# a 20:9 phone, in centimetres-ish units
W, H, D = 7.2, 16.1, 0.82
R = 0.95 # corner radius of the body
BEZEL = 0.16
SCREEN_R = R - BEZEL
def clear():
bpy.ops.wm.read_factory_settings(use_empty=True)
def rounded_outline(w, h, r, steps=16):
pts = []
corners = [(w / 2 - r, h / 2 - r, 0), (-w / 2 + r, h / 2 - r, 90), (-w / 2 + r, -h / 2 + r, 180), (w / 2 - r, -h / 2 + r, 270)]
for cx, cz, start in corners:
for i in range(steps + 1):
a = math.radians(start + 90 * i / steps)
pts.append((cx + r * math.cos(a), cz + r * math.sin(a)))
return pts
def slab(name, w, h, r, depth, y):
"""A rounded rectangle in the XZ plane, extruded along Y (front at y, back at y + depth)."""
mesh = bpy.data.meshes.new(name)
bm = bmesh.new()
front = [bm.verts.new((x, y, z)) for x, z in rounded_outline(w, h, r)]
face = bm.faces.new(front)
ext = bmesh.ops.extrude_face_region(bm, geom=[face])
moved = [e for e in ext["geom"] if isinstance(e, bmesh.types.BMVert)]
bmesh.ops.translate(bm, verts=moved, vec=(0, depth, 0))
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
bm.to_mesh(mesh)
bm.free()
obj = bpy.data.objects.new(name, mesh)
bpy.context.collection.objects.link(obj)
return obj
def screen_plane(w, h, r, y):
mesh = bpy.data.meshes.new("Screen")
bm = bmesh.new()
pts = rounded_outline(w, h, r)
verts = [bm.verts.new((x, y, z)) for x, z in pts]
face = bm.faces.new(verts)
face.normal_flip() if face.normal.y > 0 else None
uv = bm.loops.layers.uv.new()
for loop in face.loops:
x, _, z = loop.vert.co
loop[uv].uv = ((x + w / 2) / w, (z + h / 2) / h)
bm.to_mesh(mesh)
bm.free()
obj = bpy.data.objects.new("Screen", mesh)
bpy.context.collection.objects.link(obj)
return obj
def body_material():
m = bpy.data.materials.new("Body")
m.use_nodes = True
p = m.node_tree.nodes["Principled BSDF"]
p.inputs["Base Color"].default_value = (0.035, 0.036, 0.04, 1)
p.inputs["Metallic"].default_value = 0.85
p.inputs["Roughness"].default_value = 0.28
return m
MIXES = []
def screen_material(paths):
m = bpy.data.materials.new("ScreenMat")
m.use_nodes = True
nodes, links = m.node_tree.nodes, m.node_tree.links
p = nodes["Principled BSDF"]
out = None
for path in paths:
tex = nodes.new("ShaderNodeTexImage")
tex.image = bpy.data.images.load(path)
tex.interpolation = "Cubic"
if out is None:
out = tex.outputs["Color"]
continue
mix = nodes.new("ShaderNodeMix")
mix.data_type = "RGBA"
links.new(out, mix.inputs[6])
links.new(tex.outputs["Color"], mix.inputs[7])
MIXES.append(mix)
out = mix.outputs[2]
# the picture is the screen's own light; the glass on top only adds a faint reflection
p.inputs["Base Color"].default_value = (0, 0, 0, 1)
links.new(out, p.inputs["Emission Color"])
p.inputs["Emission Strength"].default_value = 1.0
p.inputs["Roughness"].default_value = 0.06
p.inputs["Specular IOR Level"].default_value = 0.25
return m
def build():
clear()
scene = bpy.context.scene
engines = [e.identifier for e in bpy.types.RenderSettings.bl_rna.properties["engine"].enum_items]
scene.render.engine = "BLENDER_EEVEE_NEXT" if "BLENDER_EEVEE_NEXT" in engines else "BLENDER_EEVEE"
scene.render.resolution_x, scene.render.resolution_y = (1080, 1920) if VERTICAL else (1080, 1350)
scene.render.film_transparent = False
scene.view_settings.view_transform = "Standard"
try:
scene.eevee.taa_render_samples = 64
except AttributeError:
pass
world = bpy.data.worlds.new("World")
scene.world = world
world.use_nodes = True
world.node_tree.nodes["Background"].inputs["Color"].default_value = (0.93, 0.93, 0.94, 1)
world.node_tree.nodes["Background"].inputs["Strength"].default_value = 1.0
rig = bpy.data.objects.new("Rig", None)
bpy.context.collection.objects.link(rig)
body = slab("Body", W, H, R, D, -D / 2)
bev = body.modifiers.new("Bevel", "BEVEL")
bev.width, bev.segments, bev.limit_method = 0.12, 6, "ANGLE"
body.data.materials.append(body_material())
for poly in body.data.polygons:
poly.use_smooth = True
screen = screen_plane(W - 2 * BEZEL, H - 2 * BEZEL, SCREEN_R, -D / 2 - 0.004)
screen.data.materials.append(screen_material(SCREEN.split(';')))
for obj in (body, screen):
obj.parent = rig
rig.rotation_euler = (math.radians(PITCH), 0, math.radians(YAW))
if ANIM:
fps = 30
scene.render.fps = fps
end = int(round(fps * ANIM))
scene.frame_start, scene.frame_end = 1, end
scene.render.film_transparent = True
def key(frame, yaw, z=0.0, x_rot=PITCH):
rig.rotation_euler = (math.radians(x_rot), 0, math.radians(yaw))
rig.location = (0, 0, z)
rig.keyframe_insert("rotation_euler", frame=frame)
rig.keyframe_insert("location", frame=frame)
# in: from below; out: up and away
t_in, t_still = (float(v) for v in FLY[:2]) if FLY else (0.0, 0.5)
t_out, t_gone = (float(v) for v in FLY[2:4]) if len(FLY) > 3 else (ANIM - 1, ANIM)
key(max(1, round(t_in * fps)), YAW - 40, -26)
spin = 0.0
key(round(t_still * fps), YAW, 0)
for i, t in enumerate(CUTS):
f = round(t * fps)
if i >= SPINS:
continue
# drift before the cut, then a full quick turn; the screen swaps when the phone is edge-on
key(f - 6, YAW + spin + (8 if i % 2 == 0 else -8), 0.25 if i % 2 == 0 else -0.25)
spin += 360
key(f + 6, YAW + spin, 0)
key(round(t_out * fps), YAW + spin + 6, 0.2)
key(round(t_gone * fps), YAW + spin + 50, 28)
for i, mix in enumerate(MIXES):
fac = mix.inputs[0]
at = round(CUTS[i] * fps) if i < len(CUTS) else end
fac.default_value = 0.0
fac.keyframe_insert("default_value", frame=1)
fac.keyframe_insert("default_value", frame=at - 1)
fac.default_value = 1.0
fac.keyframe_insert("default_value", frame=at)
# the screen swaps at once; the moves ease
for action in bpy.data.actions:
curves = getattr(action, "fcurves", None)
if curves is None:
continue
for curve in curves:
is_mix = "default_value" in curve.data_path
for point in curve.keyframe_points:
point.interpolation = "CONSTANT" if is_mix else "BEZIER"
cam_data = bpy.data.cameras.new("Cam")
cam_data.lens = 60
cam = bpy.data.objects.new("Cam", cam_data)
bpy.context.collection.objects.link(cam)
cam.location = (0, -40 if VERTICAL else -33, 0.4)
cam.rotation_euler = (math.radians(90), 0, 0)
scene.camera = cam
def area(name, loc, rot, size, power, color=(1, 1, 1)):
light = bpy.data.lights.new(name, "AREA")
light.size, light.energy, light.color = size, power, color
obj = bpy.data.objects.new(name, light)
obj.location, obj.rotation_euler = loc, rot
bpy.context.collection.objects.link(obj)
area("Key", (-14, -18, 14), (math.radians(55), 0, math.radians(-38)), 14, 9000)
area("Rim", (16, 10, 8), (math.radians(70), 0, math.radians(125)), 10, 6000)
area("Fill", (8, -20, -6), (math.radians(105), 0, math.radians(20)), 12, 2500)
return scene
scene = build()
if ANIM:
scene.render.filepath = OUT + "/f_"
scene.render.image_settings.file_format = "PNG"
bpy.ops.render.render(animation=True)
else:
scene.render.filepath = OUT
bpy.ops.render.render(write_still=True)
print("rendered", OUT)