product-ad-video 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -27
- package/package.json +41 -41
- package/scripts/logo_ad.py +366 -366
- package/template/gitignore +6 -4
- package/template/src/common.tsx +3 -2
package/README.md
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
# product-ad-video
|
|
2
|
-
|
|
3
|
-
The engine behind the **Product Ad Video** plugin for Claude Code: make an 18-second product launch video in code.
|
|
4
|
-
|
|
5
|
-
- `init`: copies a Remotion project driven by one `ad.json` file (four styles: `apple3d`, `wrapped`, `terminal`, `minimal`; landscape, vertical or square)
|
|
6
|
-
- `frames`: turns your SVG logo into a glossy 3D object and renders it headless in Blender 4.2+
|
|
7
|
-
- `sound`: synthesizes sound effects and a music bed on the exact frames of each cut, with voiceover ducking
|
|
8
|
-
- `voice`: generates voiceover lines with Kokoro (optional)
|
|
9
|
-
|
|
10
|
-
```bash
|
|
11
|
-
npx product-ad-video@1.1.
|
|
12
|
-
cd ad && npm install
|
|
13
|
-
npx product-ad-video@1.1.
|
|
14
|
-
npx product-ad-video@1.1.
|
|
15
|
-
npx product-ad-video@1.1.
|
|
16
|
-
npx product-ad-video@1.1.
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## What it runs and sends
|
|
20
|
-
|
|
21
|
-
- Runs locally: Node (this CLI), Python 3 with numpy and scipy (sound, voice), and Blender (3D frames) in headless mode.
|
|
22
|
-
- `voice` sends only the voiceover lines to the public Kokoro demo on Hugging Face (hexgrad-kokoro-tts.hf.space). No other command contacts the network. Rendering with Remotion downloads fonts from Google Fonts.
|
|
23
|
-
- No telemetry.
|
|
24
|
-
|
|
25
|
-
Full docs, demos and the Claude Code plugin: https://github.com/Dhananjay-alt/product-ad-video-skill
|
|
26
|
-
|
|
27
|
-
MIT licensed.
|
|
1
|
+
# product-ad-video
|
|
2
|
+
|
|
3
|
+
The engine behind the **Product Ad Video** plugin for Claude Code: make an 18-second product launch video in code.
|
|
4
|
+
|
|
5
|
+
- `init`: copies a Remotion project driven by one `ad.json` file (four styles: `apple3d`, `wrapped`, `terminal`, `minimal`; landscape, vertical or square)
|
|
6
|
+
- `frames`: turns your SVG logo into a glossy 3D object and renders it headless in Blender 4.2+
|
|
7
|
+
- `sound`: synthesizes sound effects and a music bed on the exact frames of each cut, with voiceover ducking
|
|
8
|
+
- `voice`: generates voiceover lines with Kokoro (optional)
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npx product-ad-video@1.1.1 init ad --logo logo.svg
|
|
12
|
+
cd ad && npm install
|
|
13
|
+
npx product-ad-video@1.1.1 doctor
|
|
14
|
+
npx product-ad-video@1.1.1 frames ad.json anim # apple3d style only
|
|
15
|
+
npx product-ad-video@1.1.1 sound ad.json
|
|
16
|
+
npx product-ad-video@1.1.1 render # -> out/ad.mp4
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## What it runs and sends
|
|
20
|
+
|
|
21
|
+
- Runs locally: Node (this CLI), Python 3 with numpy and scipy (sound, voice), and Blender (3D frames) in headless mode.
|
|
22
|
+
- `voice` sends only the voiceover lines to the public Kokoro demo on Hugging Face (hexgrad-kokoro-tts.hf.space). No other command contacts the network. Rendering with Remotion downloads fonts from Google Fonts.
|
|
23
|
+
- No telemetry.
|
|
24
|
+
|
|
25
|
+
Full docs, demos and the Claude Code plugin: https://github.com/Dhananjay-alt/product-ad-video-skill
|
|
26
|
+
|
|
27
|
+
MIT licensed.
|
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "product-ad-video",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Make product launch videos in code: SVG logo to 3D ad (Blender) or 2D motion graphics (Remotion), with synthesized sound and optional voiceover. The engine behind the Product Ad Video plugin for Claude Code.",
|
|
5
|
-
"bin": {
|
|
6
|
-
"product-ad-video": "bin/cli.js"
|
|
7
|
-
},
|
|
8
|
-
"files": [
|
|
9
|
-
"bin",
|
|
10
|
-
"scripts/*.py",
|
|
11
|
-
"template",
|
|
12
|
-
"!template/public/audio",
|
|
13
|
-
"!template/public/frames",
|
|
14
|
-
"!template/out",
|
|
15
|
-
"!template/node_modules",
|
|
16
|
-
"!template/cues.json",
|
|
17
|
-
"README.md",
|
|
18
|
-
"LICENSE"
|
|
19
|
-
],
|
|
20
|
-
"engines": {
|
|
21
|
-
"node": ">=18"
|
|
22
|
-
},
|
|
23
|
-
"keywords": [
|
|
24
|
-
"video",
|
|
25
|
-
"remotion",
|
|
26
|
-
"blender",
|
|
27
|
-
"motion-graphics",
|
|
28
|
-
"claude-code",
|
|
29
|
-
"launch",
|
|
30
|
-
"tts"
|
|
31
|
-
],
|
|
32
|
-
"homepage": "https://github.com/Dhananjay-alt/product-ad-video-skill",
|
|
33
|
-
"repository": {
|
|
34
|
-
"type": "git",
|
|
35
|
-
"url": "git+https://github.com/Dhananjay-alt/product-ad-video-skill.git",
|
|
36
|
-
"directory": "packages/product-ad-video"
|
|
37
|
-
},
|
|
38
|
-
"bugs": "https://github.com/Dhananjay-alt/product-ad-video-skill/issues",
|
|
39
|
-
"author": "Dhananjay Hire",
|
|
40
|
-
"license": "MIT"
|
|
41
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "product-ad-video",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Make product launch videos in code: SVG logo to 3D ad (Blender) or 2D motion graphics (Remotion), with synthesized sound and optional voiceover. The engine behind the Product Ad Video plugin for Claude Code.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"product-ad-video": "bin/cli.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin",
|
|
10
|
+
"scripts/*.py",
|
|
11
|
+
"template",
|
|
12
|
+
"!template/public/audio",
|
|
13
|
+
"!template/public/frames",
|
|
14
|
+
"!template/out",
|
|
15
|
+
"!template/node_modules",
|
|
16
|
+
"!template/cues.json",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"video",
|
|
25
|
+
"remotion",
|
|
26
|
+
"blender",
|
|
27
|
+
"motion-graphics",
|
|
28
|
+
"claude-code",
|
|
29
|
+
"launch",
|
|
30
|
+
"tts"
|
|
31
|
+
],
|
|
32
|
+
"homepage": "https://github.com/Dhananjay-alt/product-ad-video-skill",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/Dhananjay-alt/product-ad-video-skill.git",
|
|
36
|
+
"directory": "packages/product-ad-video"
|
|
37
|
+
},
|
|
38
|
+
"bugs": "https://github.com/Dhananjay-alt/product-ad-video-skill/issues",
|
|
39
|
+
"author": "Dhananjay Hire",
|
|
40
|
+
"license": "MIT"
|
|
41
|
+
}
|
package/scripts/logo_ad.py
CHANGED
|
@@ -1,366 +1,366 @@
|
|
|
1
|
-
"""Turn any SVG logo into a glossy 3D product ad, headless in Blender 4.2+.
|
|
2
|
-
|
|
3
|
-
blender -b --factory-startup -P logo_ad.py -- ad.json still <out_dir> [frames=auto] [scale%=50]
|
|
4
|
-
blender -b --factory-startup -P logo_ad.py -- ad.json anim <out_dir> [start end]
|
|
5
|
-
blender -b --factory-startup -P logo_ad.py -- ad.json save <file.blend>
|
|
6
|
-
|
|
7
|
-
Reads the logo, colours, aspect and shot count from ad.json, so the camera cuts line up with
|
|
8
|
-
the Remotion text overlay (template/src/styles/Apple3D.tsx). Writes f0001.jpg ... into out_dir.
|
|
9
|
-
|
|
10
|
-
Logo rules: filled shapes only (convert strokes/text to paths first); gradients become their
|
|
11
|
-
first colour; each SVG shape becomes a layer, later shapes sit slightly in front.
|
|
12
|
-
"""
|
|
13
|
-
import math
|
|
14
|
-
import os
|
|
15
|
-
import sys
|
|
16
|
-
|
|
17
|
-
import addon_utils
|
|
18
|
-
import bpy
|
|
19
|
-
from mathutils import Vector
|
|
20
|
-
|
|
21
|
-
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
22
|
-
import adspec # noqa: E402
|
|
23
|
-
|
|
24
|
-
argv = sys.argv[sys.argv.index("--") + 1:]
|
|
25
|
-
AD = adspec.load(argv[0])
|
|
26
|
-
MODE = argv[1]
|
|
27
|
-
TOTAL = AD["_total"]
|
|
28
|
-
W, H = AD["_size"]
|
|
29
|
-
VERTICAL = H > W
|
|
30
|
-
N = len(AD["shots"])
|
|
31
|
-
STARTS = AD["_shot_starts"]
|
|
32
|
-
END_START = AD["_end_start"]
|
|
33
|
-
CUTS = [s - 1 for s in STARTS] + [END_START - 1]
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
# ------------------------------------------------------------------ helpers
|
|
37
|
-
def srgb(hex_):
|
|
38
|
-
hex_ = hex_.lstrip("#")
|
|
39
|
-
c = [int(hex_[i:i + 2], 16) / 255 for i in (0, 2, 4)]
|
|
40
|
-
return tuple(((v / 12.92) if v <= 0.04045 else ((v + 0.055) / 1.055) ** 2.4) for v in c) + (1.0,)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def set_input(node, names, value):
|
|
44
|
-
for n in names:
|
|
45
|
-
if n in node.inputs:
|
|
46
|
-
node.inputs[n].default_value = value
|
|
47
|
-
return
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def glossy(name, color, rough=0.2, metallic=0.0, coat=1.0):
|
|
51
|
-
m = bpy.data.materials.new(name)
|
|
52
|
-
m.use_nodes = True
|
|
53
|
-
b = next(n for n in m.node_tree.nodes if n.type == "BSDF_PRINCIPLED")
|
|
54
|
-
set_input(b, ["Base Color"], color)
|
|
55
|
-
set_input(b, ["Roughness"], rough)
|
|
56
|
-
set_input(b, ["Metallic"], metallic)
|
|
57
|
-
set_input(b, ["Coat Weight", "Coat", "Clearcoat"], coat)
|
|
58
|
-
set_input(b, ["Coat Roughness", "Clearcoat Roughness"], 0.04)
|
|
59
|
-
return m
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def link(obj):
|
|
63
|
-
bpy.context.scene.collection.objects.link(obj)
|
|
64
|
-
return obj
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
def look_at(obj, target):
|
|
68
|
-
d = Vector(target) - obj.location
|
|
69
|
-
obj.rotation_euler = d.to_track_quat("-Z", "Y").to_euler()
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def ease(t):
|
|
73
|
-
t = max(0.0, min(1.0, t))
|
|
74
|
-
return t * t * (3 - 2 * t)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def ease_out(t):
|
|
78
|
-
t = max(0.0, min(1.0, t))
|
|
79
|
-
return 1 - (1 - t) ** 3
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def seg(f, a, b, e=ease):
|
|
83
|
-
return e((f - a) / (b - a)) if b != a else 0.0
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def lerp(a, b, t):
|
|
87
|
-
return a + (b - a) * t
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def clamp01(x):
|
|
91
|
-
return max(0.0, min(1.0, x))
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
# ------------------------------------------------------------------ scene
|
|
95
|
-
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
96
|
-
scene = bpy.context.scene
|
|
97
|
-
scene.frame_start, scene.frame_end = 1, TOTAL
|
|
98
|
-
scene.render.fps = adspec.FPS
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
def build_hero(svg_path, size=2.4, depth=0.34, step=0.1):
|
|
102
|
-
"""Import the SVG, extrude every shape, stack later shapes in front, centre it, face -Y."""
|
|
103
|
-
addon_utils.enable("io_curve_svg", default_set=True)
|
|
104
|
-
before = set(bpy.data.objects)
|
|
105
|
-
bpy.ops.import_curve.svg(filepath=svg_path)
|
|
106
|
-
shapes = [o for o in bpy.data.objects if o not in before and o.type == "CURVE"]
|
|
107
|
-
if not shapes:
|
|
108
|
-
raise SystemExit(f"No filled shapes found in {svg_path}")
|
|
109
|
-
bpy.context.view_layer.update()
|
|
110
|
-
pts = [o.matrix_world @ Vector(c) for o in shapes for c in o.bound_box]
|
|
111
|
-
lo = Vector((min(p.x for p in pts), min(p.y for p in pts), 0))
|
|
112
|
-
hi = Vector((max(p.x for p in pts), max(p.y for p in pts), 0))
|
|
113
|
-
centre = (lo + hi) / 2
|
|
114
|
-
s = size / max(hi.x - lo.x, hi.y - lo.y)
|
|
115
|
-
|
|
116
|
-
hero = link(bpy.data.objects.new("Hero", None))
|
|
117
|
-
pivot = link(bpy.data.objects.new("LogoPivot", None)) # flat SVG plane -> upright, facing the camera
|
|
118
|
-
pivot.parent = hero
|
|
119
|
-
pivot.rotation_euler = (math.radians(90), 0, 0)
|
|
120
|
-
pivot.scale = (s, s, s)
|
|
121
|
-
accent_only = AD.get("logo_colors") == "accent"
|
|
122
|
-
for i, o in enumerate(shapes):
|
|
123
|
-
mw = o.matrix_world.copy()
|
|
124
|
-
for col in list(o.users_collection):
|
|
125
|
-
col.objects.unlink(o)
|
|
126
|
-
link(o)
|
|
127
|
-
o.parent = pivot
|
|
128
|
-
o.matrix_parent_inverse.identity()
|
|
129
|
-
o.matrix_basis = mw
|
|
130
|
-
o.location = (o.location.x - centre.x, o.location.y - centre.y, (i * step) / s)
|
|
131
|
-
cu = o.data
|
|
132
|
-
cu.dimensions = "2D"
|
|
133
|
-
cu.fill_mode = "BOTH"
|
|
134
|
-
cu.extrude = (depth / 2 - 0.03 * min(i, 1)) / s
|
|
135
|
-
cu.bevel_depth = 0.035 / s
|
|
136
|
-
cu.bevel_resolution = 4
|
|
137
|
-
cu.resolution_u = 24
|
|
138
|
-
old = o.active_material
|
|
139
|
-
c = old.diffuse_color if old is not None else srgb(AD["colors"]["accent"])
|
|
140
|
-
if accent_only and i > 0:
|
|
141
|
-
c = srgb(AD["colors"]["accent"])
|
|
142
|
-
lum = 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2]
|
|
143
|
-
mat = glossy(f"Logo{i}", (c[0], c[1], c[2], 1), rough=0.16 if lum > 0.02 else 0.12)
|
|
144
|
-
cu.materials.clear()
|
|
145
|
-
cu.materials.append(mat)
|
|
146
|
-
# thickness centred on the hero origin
|
|
147
|
-
pivot.location = (0, (len(shapes) - 1) * step / 2, 0)
|
|
148
|
-
return hero
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
hero = build_hero(adspec.rel(AD, AD.get("logo", "public/logo.svg")))
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
# ------------------------------------------------------------------ lights (rims take the brand accent)
|
|
155
|
-
def area(name, loc, target, size, power, color=(1, 1, 1), size_y=None):
|
|
156
|
-
li = bpy.data.lights.new(name, "AREA")
|
|
157
|
-
li.energy = power
|
|
158
|
-
li.color = color
|
|
159
|
-
li.size = size
|
|
160
|
-
if size_y:
|
|
161
|
-
li.shape = "RECTANGLE"
|
|
162
|
-
li.size_y = size_y
|
|
163
|
-
ob = link(bpy.data.objects.new(name, li))
|
|
164
|
-
ob.location = loc
|
|
165
|
-
look_at(ob, target)
|
|
166
|
-
return ob
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
acc = srgb(AD["colors"]["accent"])[:3]
|
|
170
|
-
mx = max(acc) or 1
|
|
171
|
-
rim_col = tuple(0.25 + 0.75 * c / mx for c in acc)
|
|
172
|
-
key = area("Key", (-3.2, -4.5, 4.2), (0, 0, 0), 4.5, 1100)
|
|
173
|
-
fill = area("Fill", (4.5, -5, -0.5), (0, 0, 0), 5, 160)
|
|
174
|
-
rim_r = area("RimRight", (4.2, 4.5, 2.2), (0, 0, 0), 3, 2400, rim_col)
|
|
175
|
-
rim_l = area("RimLeft", (-4.6, 3.8, -0.4), (0, 0, 0), 3, 1400, rim_col)
|
|
176
|
-
streak = area("Streak", (0, -3.2, 3), (0, 0, 0), 0.22, 0, (1, 1, 1), size_y=7)
|
|
177
|
-
|
|
178
|
-
world = bpy.data.worlds.new("Void")
|
|
179
|
-
world.use_nodes = True
|
|
180
|
-
bg = next(n for n in world.node_tree.nodes if n.type == "BACKGROUND")
|
|
181
|
-
bg.inputs[0].default_value = (0.0015, 0.0013, 0.0014, 1)
|
|
182
|
-
scene.world = world
|
|
183
|
-
|
|
184
|
-
cam_data = bpy.data.cameras.new("Cam")
|
|
185
|
-
cam = link(bpy.data.objects.new("Cam", cam_data))
|
|
186
|
-
focus = link(bpy.data.objects.new("Focus", None))
|
|
187
|
-
scene.camera = cam
|
|
188
|
-
cam_data.dof.use_dof = True
|
|
189
|
-
cam_data.dof.focus_object = focus
|
|
190
|
-
cam_data.sensor_width = 36
|
|
191
|
-
cam_data.sensor_fit = "AUTO" # 36 mm across the longer side
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
# ------------------------------------------------------------------ choreography
|
|
195
|
-
def view_size(r, lens):
|
|
196
|
-
"""Visible (width, height) in scene units at distance r."""
|
|
197
|
-
long_side = 36 / lens * r
|
|
198
|
-
return (long_side, long_side * H / W) if W >= H else (long_side * W / H, long_side)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
def framed(r, lens, deg, h, subject=(0, 0, 0), side=1.0):
|
|
202
|
-
"""Camera on a circle round the hero, shifted so the hero clears the text block.
|
|
203
|
-
Landscape: text lower-left, hero right of centre. Vertical/square: text at the bottom, hero high."""
|
|
204
|
-
vw, vh = view_size(r, lens)
|
|
205
|
-
off = 0.
|
|
206
|
-
zoff = 0.0 if W > H else -0.17 * vh * side
|
|
207
|
-
a = math.radians(deg)
|
|
208
|
-
right = (math.cos(a), math.sin(a))
|
|
209
|
-
cx = subject[0] + r * math.sin(a) - right[0] * off
|
|
210
|
-
cy = subject[1] - r * math.cos(a) - right[1] * off
|
|
211
|
-
aim = (subject[0] - right[0] * off, subject[1] - right[1] * off, subject[2] + zoff)
|
|
212
|
-
return (cx, cy, subject[2] + h + zoff), aim
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
def streak_pass(s, f, a, b, power, left_to_right=True):
|
|
216
|
-
s["streak"] = power * math.sin(math.pi * clamp01((f - a) / (b - a)))
|
|
217
|
-
x0, x1 = (-3.4, 3.4) if left_to_right else (3.4, -3.4)
|
|
218
|
-
s["streak_x"] = lerp(x0, x1, seg(f, a, b))
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
def shot_move(kind, f, a, b, s):
|
|
222
|
-
"""Four reusable camera moves for the stat shots; they cycle A B C D A ..."""
|
|
223
|
-
t = seg(f, a, b)
|
|
224
|
-
bob = 0.05 * math.sin(f / 22)
|
|
225
|
-
if kind == 0: # A: swing round as the hero turns to face us
|
|
226
|
-
t = seg(f, a, b, ease_out)
|
|
227
|
-
s["rot"] = (0, 0, math.radians(lerp(50, -8, t)))
|
|
228
|
-
s["loc"] = (0, 0, bob)
|
|
229
|
-
r = lerp(9.5, 12.5, t)
|
|
230
|
-
s["cam"], s["aim"] = framed(r, 50, lerp(-50, 6, t), lerp(1.4, 0.25, t))
|
|
231
|
-
s["lens"], s["fstop"], s["focus"] = 50, 2.8, (0, -0.3, 0)
|
|
232
|
-
elif kind == 1: # B: macro along the bevel, light streak crosses (text gets a scrim)
|
|
233
|
-
s["rot"] = (0, 0, math.radians(lerp(-28, -12, t)))
|
|
234
|
-
s["cam"], s["aim"] = framed(lerp(4.6, 4.0, t), 85, lerp(28, 2, t), lerp(0.5, 0.1, t),
|
|
235
|
-
subject=(0.6, -0.2, 0.35), side=0.6)
|
|
236
|
-
s["lens"], s["fstop"], s["focus"] = 85, 3.2, (0.7, -0.3, 0.3)
|
|
237
|
-
s["key"] = 520
|
|
238
|
-
streak_pass(s, f, a + 12, b - 10, 440, left_to_right=False)
|
|
239
|
-
elif kind == 2: # C: low hero angle, slow orbit, looking up
|
|
240
|
-
s["rot"] = (math.radians(-8), 0, math.radians(lerp(24, 4, t)))
|
|
241
|
-
s["loc"] = (0, 0, bob)
|
|
242
|
-
s["cam"], s["aim"] = framed(lerp(12.8, 11.4, t), 50, lerp(-20, 14, t), lerp(-2.0, -1.2, t))
|
|
243
|
-
s["lens"], s["fstop"], s["focus"] = 50, 3.2, (0, -0.3, 0)
|
|
244
|
-
else: # D: from above as the hero tips upright, streak across the face
|
|
245
|
-
tin = seg(f, a, a + 34, ease_out)
|
|
246
|
-
s["rot"] = (math.radians(lerp(-55, 0, tin)), 0, math.radians(lerp(-14, 10, t)))
|
|
247
|
-
s["loc"] = (0, 0, bob)
|
|
248
|
-
s["cam"], s["aim"] = framed(lerp(11.8, 10.8, t), 50, lerp(18, -10, t), lerp(3.0, 1.4, t))
|
|
249
|
-
s["lens"], s["fstop"], s["focus"] = 50, 3.2, (0, -0.3, 0)
|
|
250
|
-
streak_pass(s, f, a + 30, b - 8, 520)
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
def state(f):
|
|
254
|
-
s = {"loc": (0, 0, 0), "rot": (0, 0, 0), "cam": (0, -12, 0), "aim": (0, 0, 0), "focus": (0, -0.3, 0),
|
|
255
|
-
"lens": 50, "fstop": 4.0, "streak": 0.0, "streak_x": 0.0, "key": 1100, "rim": 1.0}
|
|
256
|
-
if f < (STARTS[0] if N else END_START): # hook: macro across the face, streak races over
|
|
257
|
-
t = seg(f, 1, adspec.HOOK)
|
|
258
|
-
s["rot"] = (0, 0, math.radians(lerp(-38, -18, t)))
|
|
259
|
-
r = lerp(3.4, 3.9, t)
|
|
260
|
-
a = math.radians(lerp(-40, 22, t))
|
|
261
|
-
s["cam"] = (0.35 + r * math.sin(a), -r * math.cos(a), lerp(1.1, 0.7, t))
|
|
262
|
-
s["aim"] = (0.35, 0, 0.45)
|
|
263
|
-
s["focus"] = (0.4, -0.25, 0.55)
|
|
264
|
-
s["lens"], s["fstop"], s["key"] = 60, 5.6, 160
|
|
265
|
-
streak_pass(s, f, 6, 64, 380)
|
|
266
|
-
return s
|
|
267
|
-
for i in range(N - 1, -1, -1):
|
|
268
|
-
if f >= STARTS[i] and f < (STARTS[i + 1] if i + 1 < N else END_START):
|
|
269
|
-
shot_move(i % 4, f, STARTS[i], (STARTS[i + 1] if i + 1 < N else END_START) - 1, s)
|
|
270
|
-
return s
|
|
271
|
-
# end: one spin, settle front-on, centred high so the end-card text sits underneath
|
|
272
|
-
t = seg(f, END_START, END_START + 95)
|
|
273
|
-
lens = 85
|
|
274
|
-
vw, vh = view_size(1, lens)
|
|
275
|
-
target_h = 0.3 if W > H else 0.22 # hero height as a share of the frame height
|
|
276
|
-
r_end = 2.4 / (target_h * vh)
|
|
277
|
-
zoff_end = -0.12 * vh * r_end
|
|
278
|
-
s["rot"] = (0, 0, math.radians(lerp(-330, 0, seg(f, END_START, END_START + 80, ease_out))))
|
|
279
|
-
r = lerp(r_end * 0.45, r_end, t)
|
|
280
|
-
a = math.radians(lerp(-46, 0, t))
|
|
281
|
-
z = lerp(-1.6, 0, t) + zoff_end * t
|
|
282
|
-
s["cam"] = (r * math.sin(a), -r * math.cos(a), z)
|
|
283
|
-
s["aim"] = (0, 0, zoff_end * t)
|
|
284
|
-
s["focus"] = (0, -0.3, 0)
|
|
285
|
-
s["lens"], s["fstop"] = lens, lerp(2.8, 11, t)
|
|
286
|
-
s["key"], s["rim"] = lerp(1100, 750, t), lerp(1.0, 0.55, t)
|
|
287
|
-
return s
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
def apply(f):
|
|
291
|
-
s = state(f)
|
|
292
|
-
hero.location = s["loc"]
|
|
293
|
-
hero.rotation_euler = s["rot"]
|
|
294
|
-
cam.location = s["cam"]
|
|
295
|
-
look_at(cam, s["aim"])
|
|
296
|
-
focus.location = s["focus"]
|
|
297
|
-
cam_data.lens = s["lens"]
|
|
298
|
-
cam_data.dof.aperture_fstop = s["fstop"]
|
|
299
|
-
streak.location = (s["streak_x"], -3.0, 3.2)
|
|
300
|
-
look_at(streak, (s["streak_x"] * 0.25, 0, 0))
|
|
301
|
-
streak.data.energy = s["streak"]
|
|
302
|
-
key.data.energy = s["key"]
|
|
303
|
-
rim_r.data.energy = 2400 * s["rim"]
|
|
304
|
-
rim_l.data.energy = 1400 * s["rim"]
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
def bake(start, end):
|
|
308
|
-
frames = [float(f) for f in range(start, end + 1)]
|
|
309
|
-
frames += [c + 0.5 for c in CUTS if start <= c <= end] # hard cuts: no motion blur smear across shots
|
|
310
|
-
for f in sorted(frames):
|
|
311
|
-
apply(f)
|
|
312
|
-
for ob in (hero, cam, focus, streak):
|
|
313
|
-
ob.keyframe_insert("location", frame=f)
|
|
314
|
-
ob.keyframe_insert("rotation_euler", frame=f)
|
|
315
|
-
cam_data.keyframe_insert("lens", frame=f)
|
|
316
|
-
cam_data.dof.keyframe_insert("aperture_fstop", frame=f)
|
|
317
|
-
for li in (streak, key, rim_r, rim_l):
|
|
318
|
-
li.data.keyframe_insert("energy", frame=f)
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
# ------------------------------------------------------------------ render settings
|
|
322
|
-
r = scene.render
|
|
323
|
-
engines = [e.identifier for e in type(r).bl_rna.properties["engine"].enum_items]
|
|
324
|
-
r.engine = "BLENDER_EEVEE_NEXT" if "BLENDER_EEVEE_NEXT" in engines else "BLENDER_EEVEE"
|
|
325
|
-
r.resolution_x, r.resolution_y, r.resolution_percentage = W, H, 100
|
|
326
|
-
ee = scene.eevee
|
|
327
|
-
for attr, val in (("taa_render_samples", 48), ("use_raytracing", True), ("use_shadows", True),
|
|
328
|
-
("use_gtao", True), ("motion_blur_shutter", 0.5), ("motion_blur_position", "START")):
|
|
329
|
-
if hasattr(ee, attr):
|
|
330
|
-
try:
|
|
331
|
-
setattr(ee, attr, val)
|
|
332
|
-
except Exception as ex: # noqa: BLE001
|
|
333
|
-
print("skip", attr, ex)
|
|
334
|
-
if hasattr(r, "use_motion_blur"):
|
|
335
|
-
r.use_motion_blur = True
|
|
336
|
-
scene.view_settings.view_transform = "Standard"
|
|
337
|
-
try:
|
|
338
|
-
scene.view_settings.look = "Medium High Contrast"
|
|
339
|
-
except Exception: # noqa: BLE001
|
|
340
|
-
pass
|
|
341
|
-
|
|
342
|
-
if MODE == "still":
|
|
343
|
-
out = os.path.abspath(argv[2]) # Blender resolves relative paths oddly; pin it
|
|
344
|
-
auto = [40] + [s + 40 for s in STARTS] + [TOTAL - 5]
|
|
345
|
-
frames = auto if len(argv) < 4 or argv[3] == "auto" else [int(x) for x in argv[3].split(",")]
|
|
346
|
-
r.resolution_percentage = int(argv[4]) if len(argv) > 4 else 50
|
|
347
|
-
r.image_settings.file_format = "PNG"
|
|
348
|
-
r.use_motion_blur = False
|
|
349
|
-
bake(1, TOTAL)
|
|
350
|
-
for f in frames:
|
|
351
|
-
scene.frame_set(f)
|
|
352
|
-
r.filepath = os.path.join(out, f"s{f:04d}.png")
|
|
353
|
-
bpy.ops.render.render(write_still=True)
|
|
354
|
-
elif MODE == "anim":
|
|
355
|
-
out = os.path.abspath(argv[2]) # Blender resolves relative paths oddly; pin it
|
|
356
|
-
bake(1, TOTAL)
|
|
357
|
-
r.image_settings.file_format = "JPEG"
|
|
358
|
-
r.image_settings.quality = 92
|
|
359
|
-
r.filepath = os.path.join(out, "f")
|
|
360
|
-
scene.frame_start = int(argv[3]) if len(argv) > 3 else 1
|
|
361
|
-
scene.frame_end = int(argv[4]) if len(argv) > 4 else TOTAL
|
|
362
|
-
bpy.ops.render.render(animation=True)
|
|
363
|
-
elif MODE == "save":
|
|
364
|
-
bake(1, TOTAL)
|
|
365
|
-
bpy.ops.wm.save_as_mainfile(filepath=os.path.abspath(argv[2]))
|
|
366
|
-
print("ENGINE", r.engine, "FRAMES", TOTAL, "DONE", MODE)
|
|
1
|
+
"""Turn any SVG logo into a glossy 3D product ad, headless in Blender 4.2+.
|
|
2
|
+
|
|
3
|
+
blender -b --factory-startup -P logo_ad.py -- ad.json still <out_dir> [frames=auto] [scale%=50]
|
|
4
|
+
blender -b --factory-startup -P logo_ad.py -- ad.json anim <out_dir> [start end]
|
|
5
|
+
blender -b --factory-startup -P logo_ad.py -- ad.json save <file.blend>
|
|
6
|
+
|
|
7
|
+
Reads the logo, colours, aspect and shot count from ad.json, so the camera cuts line up with
|
|
8
|
+
the Remotion text overlay (template/src/styles/Apple3D.tsx). Writes f0001.jpg ... into out_dir.
|
|
9
|
+
|
|
10
|
+
Logo rules: filled shapes only (convert strokes/text to paths first); gradients become their
|
|
11
|
+
first colour; each SVG shape becomes a layer, later shapes sit slightly in front.
|
|
12
|
+
"""
|
|
13
|
+
import math
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
|
|
17
|
+
import addon_utils
|
|
18
|
+
import bpy
|
|
19
|
+
from mathutils import Vector
|
|
20
|
+
|
|
21
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
22
|
+
import adspec # noqa: E402
|
|
23
|
+
|
|
24
|
+
argv = sys.argv[sys.argv.index("--") + 1:]
|
|
25
|
+
AD = adspec.load(argv[0])
|
|
26
|
+
MODE = argv[1]
|
|
27
|
+
TOTAL = AD["_total"]
|
|
28
|
+
W, H = AD["_size"]
|
|
29
|
+
VERTICAL = H > W
|
|
30
|
+
N = len(AD["shots"])
|
|
31
|
+
STARTS = AD["_shot_starts"]
|
|
32
|
+
END_START = AD["_end_start"]
|
|
33
|
+
CUTS = [s - 1 for s in STARTS] + [END_START - 1]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# ------------------------------------------------------------------ helpers
|
|
37
|
+
def srgb(hex_):
|
|
38
|
+
hex_ = hex_.lstrip("#")
|
|
39
|
+
c = [int(hex_[i:i + 2], 16) / 255 for i in (0, 2, 4)]
|
|
40
|
+
return tuple(((v / 12.92) if v <= 0.04045 else ((v + 0.055) / 1.055) ** 2.4) for v in c) + (1.0,)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def set_input(node, names, value):
|
|
44
|
+
for n in names:
|
|
45
|
+
if n in node.inputs:
|
|
46
|
+
node.inputs[n].default_value = value
|
|
47
|
+
return
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def glossy(name, color, rough=0.2, metallic=0.0, coat=1.0):
|
|
51
|
+
m = bpy.data.materials.new(name)
|
|
52
|
+
m.use_nodes = True
|
|
53
|
+
b = next(n for n in m.node_tree.nodes if n.type == "BSDF_PRINCIPLED")
|
|
54
|
+
set_input(b, ["Base Color"], color)
|
|
55
|
+
set_input(b, ["Roughness"], rough)
|
|
56
|
+
set_input(b, ["Metallic"], metallic)
|
|
57
|
+
set_input(b, ["Coat Weight", "Coat", "Clearcoat"], coat)
|
|
58
|
+
set_input(b, ["Coat Roughness", "Clearcoat Roughness"], 0.04)
|
|
59
|
+
return m
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def link(obj):
|
|
63
|
+
bpy.context.scene.collection.objects.link(obj)
|
|
64
|
+
return obj
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def look_at(obj, target):
|
|
68
|
+
d = Vector(target) - obj.location
|
|
69
|
+
obj.rotation_euler = d.to_track_quat("-Z", "Y").to_euler()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def ease(t):
|
|
73
|
+
t = max(0.0, min(1.0, t))
|
|
74
|
+
return t * t * (3 - 2 * t)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def ease_out(t):
|
|
78
|
+
t = max(0.0, min(1.0, t))
|
|
79
|
+
return 1 - (1 - t) ** 3
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def seg(f, a, b, e=ease):
|
|
83
|
+
return e((f - a) / (b - a)) if b != a else 0.0
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def lerp(a, b, t):
|
|
87
|
+
return a + (b - a) * t
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def clamp01(x):
|
|
91
|
+
return max(0.0, min(1.0, x))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# ------------------------------------------------------------------ scene
|
|
95
|
+
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
96
|
+
scene = bpy.context.scene
|
|
97
|
+
scene.frame_start, scene.frame_end = 1, TOTAL
|
|
98
|
+
scene.render.fps = adspec.FPS
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def build_hero(svg_path, size=2.4, depth=0.34, step=0.1):
|
|
102
|
+
"""Import the SVG, extrude every shape, stack later shapes in front, centre it, face -Y."""
|
|
103
|
+
addon_utils.enable("io_curve_svg", default_set=True)
|
|
104
|
+
before = set(bpy.data.objects)
|
|
105
|
+
bpy.ops.import_curve.svg(filepath=svg_path)
|
|
106
|
+
shapes = [o for o in bpy.data.objects if o not in before and o.type == "CURVE"]
|
|
107
|
+
if not shapes:
|
|
108
|
+
raise SystemExit(f"No filled shapes found in {svg_path}")
|
|
109
|
+
bpy.context.view_layer.update()
|
|
110
|
+
pts = [o.matrix_world @ Vector(c) for o in shapes for c in o.bound_box]
|
|
111
|
+
lo = Vector((min(p.x for p in pts), min(p.y for p in pts), 0))
|
|
112
|
+
hi = Vector((max(p.x for p in pts), max(p.y for p in pts), 0))
|
|
113
|
+
centre = (lo + hi) / 2
|
|
114
|
+
s = size / max(hi.x - lo.x, hi.y - lo.y)
|
|
115
|
+
|
|
116
|
+
hero = link(bpy.data.objects.new("Hero", None))
|
|
117
|
+
pivot = link(bpy.data.objects.new("LogoPivot", None)) # flat SVG plane -> upright, facing the camera
|
|
118
|
+
pivot.parent = hero
|
|
119
|
+
pivot.rotation_euler = (math.radians(90), 0, 0)
|
|
120
|
+
pivot.scale = (s, s, s)
|
|
121
|
+
accent_only = AD.get("logo_colors") == "accent"
|
|
122
|
+
for i, o in enumerate(shapes):
|
|
123
|
+
mw = o.matrix_world.copy()
|
|
124
|
+
for col in list(o.users_collection):
|
|
125
|
+
col.objects.unlink(o)
|
|
126
|
+
link(o)
|
|
127
|
+
o.parent = pivot
|
|
128
|
+
o.matrix_parent_inverse.identity()
|
|
129
|
+
o.matrix_basis = mw
|
|
130
|
+
o.location = (o.location.x - centre.x, o.location.y - centre.y, (i * step) / s)
|
|
131
|
+
cu = o.data
|
|
132
|
+
cu.dimensions = "2D"
|
|
133
|
+
cu.fill_mode = "BOTH"
|
|
134
|
+
cu.extrude = (depth / 2 - 0.03 * min(i, 1)) / s
|
|
135
|
+
cu.bevel_depth = 0.035 / s
|
|
136
|
+
cu.bevel_resolution = 4
|
|
137
|
+
cu.resolution_u = 24
|
|
138
|
+
old = o.active_material
|
|
139
|
+
c = old.diffuse_color if old is not None else srgb(AD["colors"]["accent"])
|
|
140
|
+
if accent_only and i > 0:
|
|
141
|
+
c = srgb(AD["colors"]["accent"])
|
|
142
|
+
lum = 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2]
|
|
143
|
+
mat = glossy(f"Logo{i}", (c[0], c[1], c[2], 1), rough=0.16 if lum > 0.02 else 0.12)
|
|
144
|
+
cu.materials.clear()
|
|
145
|
+
cu.materials.append(mat)
|
|
146
|
+
# thickness centred on the hero origin
|
|
147
|
+
pivot.location = (0, (len(shapes) - 1) * step / 2, 0)
|
|
148
|
+
return hero
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
hero = build_hero(adspec.rel(AD, AD.get("logo", "public/logo.svg")))
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
# ------------------------------------------------------------------ lights (rims take the brand accent)
|
|
155
|
+
def area(name, loc, target, size, power, color=(1, 1, 1), size_y=None):
|
|
156
|
+
li = bpy.data.lights.new(name, "AREA")
|
|
157
|
+
li.energy = power
|
|
158
|
+
li.color = color
|
|
159
|
+
li.size = size
|
|
160
|
+
if size_y:
|
|
161
|
+
li.shape = "RECTANGLE"
|
|
162
|
+
li.size_y = size_y
|
|
163
|
+
ob = link(bpy.data.objects.new(name, li))
|
|
164
|
+
ob.location = loc
|
|
165
|
+
look_at(ob, target)
|
|
166
|
+
return ob
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
acc = srgb(AD["colors"]["accent"])[:3]
|
|
170
|
+
mx = max(acc) or 1
|
|
171
|
+
rim_col = tuple(0.25 + 0.75 * c / mx for c in acc)
|
|
172
|
+
key = area("Key", (-3.2, -4.5, 4.2), (0, 0, 0), 4.5, 1100)
|
|
173
|
+
fill = area("Fill", (4.5, -5, -0.5), (0, 0, 0), 5, 160)
|
|
174
|
+
rim_r = area("RimRight", (4.2, 4.5, 2.2), (0, 0, 0), 3, 2400, rim_col)
|
|
175
|
+
rim_l = area("RimLeft", (-4.6, 3.8, -0.4), (0, 0, 0), 3, 1400, rim_col)
|
|
176
|
+
streak = area("Streak", (0, -3.2, 3), (0, 0, 0), 0.22, 0, (1, 1, 1), size_y=7)
|
|
177
|
+
|
|
178
|
+
world = bpy.data.worlds.new("Void")
|
|
179
|
+
world.use_nodes = True
|
|
180
|
+
bg = next(n for n in world.node_tree.nodes if n.type == "BACKGROUND")
|
|
181
|
+
bg.inputs[0].default_value = (0.0015, 0.0013, 0.0014, 1)
|
|
182
|
+
scene.world = world
|
|
183
|
+
|
|
184
|
+
cam_data = bpy.data.cameras.new("Cam")
|
|
185
|
+
cam = link(bpy.data.objects.new("Cam", cam_data))
|
|
186
|
+
focus = link(bpy.data.objects.new("Focus", None))
|
|
187
|
+
scene.camera = cam
|
|
188
|
+
cam_data.dof.use_dof = True
|
|
189
|
+
cam_data.dof.focus_object = focus
|
|
190
|
+
cam_data.sensor_width = 36
|
|
191
|
+
cam_data.sensor_fit = "AUTO" # 36 mm across the longer side
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
# ------------------------------------------------------------------ choreography
|
|
195
|
+
def view_size(r, lens):
|
|
196
|
+
"""Visible (width, height) in scene units at distance r."""
|
|
197
|
+
long_side = 36 / lens * r
|
|
198
|
+
return (long_side, long_side * H / W) if W >= H else (long_side * W / H, long_side)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def framed(r, lens, deg, h, subject=(0, 0, 0), side=1.0):
|
|
202
|
+
"""Camera on a circle round the hero, shifted so the hero clears the text block.
|
|
203
|
+
Landscape: text lower-left, hero right of centre. Vertical/square: text at the bottom, hero high."""
|
|
204
|
+
vw, vh = view_size(r, lens)
|
|
205
|
+
off = 0.23 * vw * side if W > H else 0.0
|
|
206
|
+
zoff = 0.0 if W > H else -0.17 * vh * side
|
|
207
|
+
a = math.radians(deg)
|
|
208
|
+
right = (math.cos(a), math.sin(a))
|
|
209
|
+
cx = subject[0] + r * math.sin(a) - right[0] * off
|
|
210
|
+
cy = subject[1] - r * math.cos(a) - right[1] * off
|
|
211
|
+
aim = (subject[0] - right[0] * off, subject[1] - right[1] * off, subject[2] + zoff)
|
|
212
|
+
return (cx, cy, subject[2] + h + zoff), aim
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def streak_pass(s, f, a, b, power, left_to_right=True):
|
|
216
|
+
s["streak"] = power * math.sin(math.pi * clamp01((f - a) / (b - a)))
|
|
217
|
+
x0, x1 = (-3.4, 3.4) if left_to_right else (3.4, -3.4)
|
|
218
|
+
s["streak_x"] = lerp(x0, x1, seg(f, a, b))
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def shot_move(kind, f, a, b, s):
|
|
222
|
+
"""Four reusable camera moves for the stat shots; they cycle A B C D A ..."""
|
|
223
|
+
t = seg(f, a, b)
|
|
224
|
+
bob = 0.05 * math.sin(f / 22)
|
|
225
|
+
if kind == 0: # A: swing round as the hero turns to face us
|
|
226
|
+
t = seg(f, a, b, ease_out)
|
|
227
|
+
s["rot"] = (0, 0, math.radians(lerp(50, -8, t)))
|
|
228
|
+
s["loc"] = (0, 0, bob)
|
|
229
|
+
r = lerp(9.5, 12.5, t)
|
|
230
|
+
s["cam"], s["aim"] = framed(r, 50, lerp(-50, 6, t), lerp(1.4, 0.25, t))
|
|
231
|
+
s["lens"], s["fstop"], s["focus"] = 50, 2.8, (0, -0.3, 0)
|
|
232
|
+
elif kind == 1: # B: macro along the bevel, light streak crosses (text gets a scrim)
|
|
233
|
+
s["rot"] = (0, 0, math.radians(lerp(-28, -12, t)))
|
|
234
|
+
s["cam"], s["aim"] = framed(lerp(4.6, 4.0, t), 85, lerp(28, 2, t), lerp(0.5, 0.1, t),
|
|
235
|
+
subject=(0.6, -0.2, 0.35), side=0.6)
|
|
236
|
+
s["lens"], s["fstop"], s["focus"] = 85, 3.2, (0.7, -0.3, 0.3)
|
|
237
|
+
s["key"] = 520
|
|
238
|
+
streak_pass(s, f, a + 12, b - 10, 440, left_to_right=False)
|
|
239
|
+
elif kind == 2: # C: low hero angle, slow orbit, looking up
|
|
240
|
+
s["rot"] = (math.radians(-8), 0, math.radians(lerp(24, 4, t)))
|
|
241
|
+
s["loc"] = (0, 0, bob)
|
|
242
|
+
s["cam"], s["aim"] = framed(lerp(12.8, 11.4, t), 50, lerp(-20, 14, t), lerp(-2.0, -1.2, t))
|
|
243
|
+
s["lens"], s["fstop"], s["focus"] = 50, 3.2, (0, -0.3, 0)
|
|
244
|
+
else: # D: from above as the hero tips upright, streak across the face
|
|
245
|
+
tin = seg(f, a, a + 34, ease_out)
|
|
246
|
+
s["rot"] = (math.radians(lerp(-55, 0, tin)), 0, math.radians(lerp(-14, 10, t)))
|
|
247
|
+
s["loc"] = (0, 0, bob)
|
|
248
|
+
s["cam"], s["aim"] = framed(lerp(11.8, 10.8, t), 50, lerp(18, -10, t), lerp(3.0, 1.4, t))
|
|
249
|
+
s["lens"], s["fstop"], s["focus"] = 50, 3.2, (0, -0.3, 0)
|
|
250
|
+
streak_pass(s, f, a + 30, b - 8, 520)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def state(f):
|
|
254
|
+
s = {"loc": (0, 0, 0), "rot": (0, 0, 0), "cam": (0, -12, 0), "aim": (0, 0, 0), "focus": (0, -0.3, 0),
|
|
255
|
+
"lens": 50, "fstop": 4.0, "streak": 0.0, "streak_x": 0.0, "key": 1100, "rim": 1.0}
|
|
256
|
+
if f < (STARTS[0] if N else END_START): # hook: macro across the face, streak races over
|
|
257
|
+
t = seg(f, 1, adspec.HOOK)
|
|
258
|
+
s["rot"] = (0, 0, math.radians(lerp(-38, -18, t)))
|
|
259
|
+
r = lerp(3.4, 3.9, t)
|
|
260
|
+
a = math.radians(lerp(-40, 22, t))
|
|
261
|
+
s["cam"] = (0.35 + r * math.sin(a), -r * math.cos(a), lerp(1.1, 0.7, t))
|
|
262
|
+
s["aim"] = (0.35, 0, 0.45)
|
|
263
|
+
s["focus"] = (0.4, -0.25, 0.55)
|
|
264
|
+
s["lens"], s["fstop"], s["key"] = 60, 5.6, 160
|
|
265
|
+
streak_pass(s, f, 6, 64, 380)
|
|
266
|
+
return s
|
|
267
|
+
for i in range(N - 1, -1, -1):
|
|
268
|
+
if f >= STARTS[i] and f < (STARTS[i + 1] if i + 1 < N else END_START):
|
|
269
|
+
shot_move(i % 4, f, STARTS[i], (STARTS[i + 1] if i + 1 < N else END_START) - 1, s)
|
|
270
|
+
return s
|
|
271
|
+
# end: one spin, settle front-on, centred high so the end-card text sits underneath
|
|
272
|
+
t = seg(f, END_START, END_START + 95)
|
|
273
|
+
lens = 85
|
|
274
|
+
vw, vh = view_size(1, lens)
|
|
275
|
+
target_h = 0.3 if W > H else 0.22 # hero height as a share of the frame height
|
|
276
|
+
r_end = 2.4 / (target_h * vh)
|
|
277
|
+
zoff_end = -0.12 * vh * r_end
|
|
278
|
+
s["rot"] = (0, 0, math.radians(lerp(-330, 0, seg(f, END_START, END_START + 80, ease_out))))
|
|
279
|
+
r = lerp(r_end * 0.45, r_end, t)
|
|
280
|
+
a = math.radians(lerp(-46, 0, t))
|
|
281
|
+
z = lerp(-1.6, 0, t) + zoff_end * t
|
|
282
|
+
s["cam"] = (r * math.sin(a), -r * math.cos(a), z)
|
|
283
|
+
s["aim"] = (0, 0, zoff_end * t)
|
|
284
|
+
s["focus"] = (0, -0.3, 0)
|
|
285
|
+
s["lens"], s["fstop"] = lens, lerp(2.8, 11, t)
|
|
286
|
+
s["key"], s["rim"] = lerp(1100, 750, t), lerp(1.0, 0.55, t)
|
|
287
|
+
return s
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def apply(f):
|
|
291
|
+
s = state(f)
|
|
292
|
+
hero.location = s["loc"]
|
|
293
|
+
hero.rotation_euler = s["rot"]
|
|
294
|
+
cam.location = s["cam"]
|
|
295
|
+
look_at(cam, s["aim"])
|
|
296
|
+
focus.location = s["focus"]
|
|
297
|
+
cam_data.lens = s["lens"]
|
|
298
|
+
cam_data.dof.aperture_fstop = s["fstop"]
|
|
299
|
+
streak.location = (s["streak_x"], -3.0, 3.2)
|
|
300
|
+
look_at(streak, (s["streak_x"] * 0.25, 0, 0))
|
|
301
|
+
streak.data.energy = s["streak"]
|
|
302
|
+
key.data.energy = s["key"]
|
|
303
|
+
rim_r.data.energy = 2400 * s["rim"]
|
|
304
|
+
rim_l.data.energy = 1400 * s["rim"]
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def bake(start, end):
|
|
308
|
+
frames = [float(f) for f in range(start, end + 1)]
|
|
309
|
+
frames += [c + 0.5 for c in CUTS if start <= c <= end] # hard cuts: no motion blur smear across shots
|
|
310
|
+
for f in sorted(frames):
|
|
311
|
+
apply(f)
|
|
312
|
+
for ob in (hero, cam, focus, streak):
|
|
313
|
+
ob.keyframe_insert("location", frame=f)
|
|
314
|
+
ob.keyframe_insert("rotation_euler", frame=f)
|
|
315
|
+
cam_data.keyframe_insert("lens", frame=f)
|
|
316
|
+
cam_data.dof.keyframe_insert("aperture_fstop", frame=f)
|
|
317
|
+
for li in (streak, key, rim_r, rim_l):
|
|
318
|
+
li.data.keyframe_insert("energy", frame=f)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
# ------------------------------------------------------------------ render settings
|
|
322
|
+
r = scene.render
|
|
323
|
+
engines = [e.identifier for e in type(r).bl_rna.properties["engine"].enum_items]
|
|
324
|
+
r.engine = "BLENDER_EEVEE_NEXT" if "BLENDER_EEVEE_NEXT" in engines else "BLENDER_EEVEE"
|
|
325
|
+
r.resolution_x, r.resolution_y, r.resolution_percentage = W, H, 100
|
|
326
|
+
ee = scene.eevee
|
|
327
|
+
for attr, val in (("taa_render_samples", 48), ("use_raytracing", True), ("use_shadows", True),
|
|
328
|
+
("use_gtao", True), ("motion_blur_shutter", 0.5), ("motion_blur_position", "START")):
|
|
329
|
+
if hasattr(ee, attr):
|
|
330
|
+
try:
|
|
331
|
+
setattr(ee, attr, val)
|
|
332
|
+
except Exception as ex: # noqa: BLE001
|
|
333
|
+
print("skip", attr, ex)
|
|
334
|
+
if hasattr(r, "use_motion_blur"):
|
|
335
|
+
r.use_motion_blur = True
|
|
336
|
+
scene.view_settings.view_transform = "Standard"
|
|
337
|
+
try:
|
|
338
|
+
scene.view_settings.look = "Medium High Contrast"
|
|
339
|
+
except Exception: # noqa: BLE001
|
|
340
|
+
pass
|
|
341
|
+
|
|
342
|
+
if MODE == "still":
|
|
343
|
+
out = os.path.abspath(argv[2]) # Blender resolves relative paths oddly; pin it
|
|
344
|
+
auto = [40] + [s + 40 for s in STARTS] + [TOTAL - 5]
|
|
345
|
+
frames = auto if len(argv) < 4 or argv[3] == "auto" else [int(x) for x in argv[3].split(",")]
|
|
346
|
+
r.resolution_percentage = int(argv[4]) if len(argv) > 4 else 50
|
|
347
|
+
r.image_settings.file_format = "PNG"
|
|
348
|
+
r.use_motion_blur = False
|
|
349
|
+
bake(1, TOTAL)
|
|
350
|
+
for f in frames:
|
|
351
|
+
scene.frame_set(f)
|
|
352
|
+
r.filepath = os.path.join(out, f"s{f:04d}.png")
|
|
353
|
+
bpy.ops.render.render(write_still=True)
|
|
354
|
+
elif MODE == "anim":
|
|
355
|
+
out = os.path.abspath(argv[2]) # Blender resolves relative paths oddly; pin it
|
|
356
|
+
bake(1, TOTAL)
|
|
357
|
+
r.image_settings.file_format = "JPEG"
|
|
358
|
+
r.image_settings.quality = 92
|
|
359
|
+
r.filepath = os.path.join(out, "f")
|
|
360
|
+
scene.frame_start = int(argv[3]) if len(argv) > 3 else 1
|
|
361
|
+
scene.frame_end = int(argv[4]) if len(argv) > 4 else TOTAL
|
|
362
|
+
bpy.ops.render.render(animation=True)
|
|
363
|
+
elif MODE == "save":
|
|
364
|
+
bake(1, TOTAL)
|
|
365
|
+
bpy.ops.wm.save_as_mainfile(filepath=os.path.abspath(argv[2]))
|
|
366
|
+
print("ENGINE", r.engine, "FRAMES", TOTAL, "DONE", MODE)
|
package/template/gitignore
CHANGED
package/template/src/common.tsx
CHANGED
|
@@ -55,8 +55,9 @@ export const Stat: React.FC<{
|
|
|
55
55
|
return { opacity: a * (1 - out), transform: `translateY(${lerp(30, 0, a) * L.u}px)` };
|
|
56
56
|
};
|
|
57
57
|
const pad = (L.landscape ? 140 : 80) * L.u;
|
|
58
|
-
|
|
59
|
-
const
|
|
58
|
+
/* landscape: the 3D hero sits right of centre, so the headline must stay in the left ~half */
|
|
59
|
+
const maxW = L.landscape ? L.width * 0.44 : L.width - 2 * pad;
|
|
60
|
+
const bigSize = fitSize(big, (L.landscape ? 200 : 190) * L.u, maxW, 0.6);
|
|
60
61
|
return (
|
|
61
62
|
<AbsoluteFill style={{ fontFamily: SANS, color }}>
|
|
62
63
|
{scrim ? (
|