@ajsmonty/adobe-mcp 1.1.1 → 1.3.0
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 +308 -119
- package/SECURITY.md +19 -1
- package/adapters/blender.mjs +230 -0
- package/adapters/ppro.mjs +4 -3
- package/adapters/substance.mjs +193 -0
- package/adapters/texlib.mjs +193 -0
- package/bridges/blender/adobe_mcp_bridge.py +132 -0
- package/cep/mcp-bridge/main.js +2 -2
- package/cli/doctor.mjs +203 -0
- package/cli/index.mjs +67 -0
- package/cli/install.mjs +142 -0
- package/core/blender_pbr.py +148 -0
- package/core/bridge.mjs +113 -64
- package/core/harness.py +34 -0
- package/core/platform.mjs +205 -0
- package/core/pybridge.mjs +256 -0
- package/core/telemetry.mjs +80 -0
- package/core/texlib.mjs +279 -0
- package/core/win/run_com.js +25 -0
- package/core/workspace.mjs +35 -0
- package/knowledge/knowledge.mjs +9 -7
- package/knowledge/lessons.jsonl +20 -0
- package/package.json +45 -3
- package/scripts/ae/Cinematic_3D_Composite.jsx +173 -0
- package/scripts/blender/Creature_Walk_Cinematic.py +569 -0
- package/scripts/substance/Creature_Skin_LookDev.py +148 -0
- package/server.mjs +69 -27
- package/workflow/vfx.mjs +136 -0
- package/workflow/workflow.mjs +66 -21
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Creature_Walk_Cinematic — a physically timed heavy-biped (theropod) walk past a handheld camera,
|
|
3
|
+
with the head turning to look at the lens. Builds a proxy blocking rig (or drives your mesh via
|
|
4
|
+
PARAMS["bind"]), a documentary camera rig and a comp-ready render setup: Cycles, 180° shutter
|
|
5
|
+
motion blur, shadow catcher, and beauty / shadow / mist sequences for the After Effects composite.
|
|
6
|
+
|
|
7
|
+
Timing is derived, not guessed: speed from a Froude number (v = sqrt(Fr*g*h)), stride from
|
|
8
|
+
Alexander (1976) lambda/h = 2.3*Fr^0.3. The default Fr 0.055 at 3.1 m hip height gives about 1.3 m/s,
|
|
9
|
+
in line with published T. rex walking-speed estimates. Secondary motion is propagated down
|
|
10
|
+
the neck and tail chains with a per-joint frame lag (overlapping action), the head is gaze-stabilised,
|
|
11
|
+
and every footfall puts a small impact shake into the camera.
|
|
12
|
+
Override any key in DEFAULTS via PARAMS (run_script params). Sets `result` to the derived numbers.
|
|
13
|
+
"""
|
|
14
|
+
import math
|
|
15
|
+
import os
|
|
16
|
+
|
|
17
|
+
import bpy
|
|
18
|
+
import bmesh
|
|
19
|
+
|
|
20
|
+
DEFAULTS = {
|
|
21
|
+
"fps": 24,
|
|
22
|
+
"duration_s": 10.0,
|
|
23
|
+
"hip_height_m": 3.1, # T. rex-scale; drives every other dimension
|
|
24
|
+
"mass_kg": 8000.0,
|
|
25
|
+
"froude": 0.055, # 0.05-0.1 = heavy walk; 0.5 = walk/run transition
|
|
26
|
+
"duty_factor": 0.62, # fraction of the cycle each foot is planted (heavy walkers > 0.6)
|
|
27
|
+
"joint_lag_frames": 3, # overlap delay per neck/tail joint (mass inertia)
|
|
28
|
+
"neck_joints": 4,
|
|
29
|
+
"tail_joints": 6,
|
|
30
|
+
"pass_at": 0.55, # fraction of the shot where the creature crosses the camera axis
|
|
31
|
+
"look_in": 0.30, "look_hold": 0.62, "look_out": 0.85, # head-turn window (fractions of shot)
|
|
32
|
+
"look_max_deg": 70.0,
|
|
33
|
+
"cam_distance_m": 14.0, # from the walk line
|
|
34
|
+
"cam_height_m": 1.7, # eye height of a person holding the camera
|
|
35
|
+
"lens_mm": 35.0, # sells scale while keeping the whole animal readable on the pan
|
|
36
|
+
"sensor_mm": 36.0,
|
|
37
|
+
"fstop": 2.8,
|
|
38
|
+
"operator_lag_s": 0.25, # camera operator reaction delay while panning
|
|
39
|
+
"handheld_deg": 0.25, # handheld rotational noise amplitude
|
|
40
|
+
"footfall_shake_deg": 0.35, # impact shake at 10 m for an 8 t animal
|
|
41
|
+
"engine": "CYCLES",
|
|
42
|
+
"samples": 128,
|
|
43
|
+
"resolution": [1920, 1080],
|
|
44
|
+
"shutter": 0.5, # 180-degree shutter
|
|
45
|
+
"output_dir": "//render", # blend-relative unless absolute
|
|
46
|
+
"bind": {}, # {"Dino_Mesh": "Hips"} parents your objects to proxy controls
|
|
47
|
+
"texture_dir": None, # Substance export folder -> PBR material on bound meshes
|
|
48
|
+
"proxy_render": None, # None = render proxies only when nothing is bound
|
|
49
|
+
}
|
|
50
|
+
P = dict(DEFAULTS)
|
|
51
|
+
P.update(globals().get("PARAMS") or {})
|
|
52
|
+
|
|
53
|
+
G = 9.81
|
|
54
|
+
TAU = 2.0 * math.pi
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# ---------------------------------------------------------------------------
|
|
58
|
+
# Gait physics (pure math, no bpy)
|
|
59
|
+
# ---------------------------------------------------------------------------
|
|
60
|
+
|
|
61
|
+
def derive_gait(p):
|
|
62
|
+
h, fr = p["hip_height_m"], p["froude"]
|
|
63
|
+
v = math.sqrt(fr * G * h)
|
|
64
|
+
stride = 2.3 * (fr ** 0.3) * h # full cycle: left + right step
|
|
65
|
+
cycle_s = stride / v
|
|
66
|
+
breath_s = 4.0 * (p["mass_kg"] / 70.0) ** 0.26 * 0.5 # allometric resting period, halved for exertion
|
|
67
|
+
return {
|
|
68
|
+
"speed_mps": v, "speed_kmh": v * 3.6, "stride_m": stride, "cycle_s": cycle_s,
|
|
69
|
+
"cycle_frames": cycle_s * p["fps"], "step_frames": cycle_s * p["fps"] / 2.0,
|
|
70
|
+
"breath_s": breath_s, "scale": h / 3.1,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def smoothstep(x):
|
|
75
|
+
x = max(0.0, min(1.0, x))
|
|
76
|
+
return x * x * (3.0 - 2.0 * x)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def foot_world(phase, offset, gait, p, x0):
|
|
80
|
+
"""World (x, z, pitch) of a foot. Planted in stance, eased arc in swing."""
|
|
81
|
+
beta = p["duty_factor"]
|
|
82
|
+
lam = gait["stride_m"]
|
|
83
|
+
u = phase + offset
|
|
84
|
+
n = math.floor(u)
|
|
85
|
+
phi = u - n
|
|
86
|
+
base = x0 + n * lam + lam * (beta / 2.0 - offset) # plant spot: centred under the hip at mid-stance
|
|
87
|
+
if phi < beta:
|
|
88
|
+
return base, 0.0, 0.0, False
|
|
89
|
+
s = (phi - beta) / (1.0 - beta)
|
|
90
|
+
lift = 0.12 * p["hip_height_m"]
|
|
91
|
+
z = lift * math.sin(math.pi * (s ** 0.8)) # quick pick-up, careful set-down
|
|
92
|
+
pitch = -math.radians(18.0) * math.sin(math.pi * s) # toe-off / reach
|
|
93
|
+
return base + lam * smoothstep(s), z, pitch, True
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def body_pose(t, gait, p):
|
|
97
|
+
"""Root x and hip offsets at time t (seconds)."""
|
|
98
|
+
ph = t / gait["cycle_s"]
|
|
99
|
+
beta = p["duty_factor"]
|
|
100
|
+
h = p["hip_height_m"]
|
|
101
|
+
a = 0.04 # speed surge per step (push-off)
|
|
102
|
+
x = gait["speed_mps"] * t - gait["speed_mps"] * a * math.cos(2 * TAU * ph) * gait["cycle_s"] / (2 * TAU)
|
|
103
|
+
c = math.cos(TAU * (ph - beta / 2.0)) # +1 at left mid-stance
|
|
104
|
+
return {
|
|
105
|
+
"phase": ph,
|
|
106
|
+
"root_x": x,
|
|
107
|
+
"hip_z": h - 0.028 * h * math.cos(2 * TAU * (ph - 0.06)), # lowest just after each contact
|
|
108
|
+
"hip_y": 0.04 * h * c, # weight over the stance foot
|
|
109
|
+
"hip_roll": math.radians(3.0) * c, # swing side drops
|
|
110
|
+
"hip_yaw": math.radians(4.0) * c, # pelvis follows the swinging leg
|
|
111
|
+
"hip_pitch": math.radians(1.2) * math.sin(2 * TAU * ph),
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
# ---------------------------------------------------------------------------
|
|
116
|
+
# Blender helpers
|
|
117
|
+
# ---------------------------------------------------------------------------
|
|
118
|
+
|
|
119
|
+
def collection(name):
|
|
120
|
+
col = bpy.data.collections.get(name)
|
|
121
|
+
if col is None:
|
|
122
|
+
col = bpy.data.collections.new(name)
|
|
123
|
+
bpy.context.scene.collection.children.link(col)
|
|
124
|
+
return col
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def remove_existing(prefix):
|
|
128
|
+
"""Delete a previous build; children we did not create (a bound hero mesh) keep their pose."""
|
|
129
|
+
doomed = [ob for ob in bpy.data.objects if ob.name.startswith(prefix)]
|
|
130
|
+
if not doomed:
|
|
131
|
+
return
|
|
132
|
+
bpy.context.scene.frame_set(bpy.context.scene.frame_start)
|
|
133
|
+
for ob in doomed:
|
|
134
|
+
for child in ob.children:
|
|
135
|
+
if not child.name.startswith(prefix):
|
|
136
|
+
mw = child.matrix_world.copy()
|
|
137
|
+
child.parent = None
|
|
138
|
+
child.matrix_world = mw
|
|
139
|
+
for ob in doomed:
|
|
140
|
+
bpy.data.objects.remove(ob, do_unlink=True)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def empty(name, col, parent=None, loc=(0, 0, 0), size=0.3, shape="PLAIN_AXES"):
|
|
144
|
+
ob = bpy.data.objects.new(name, None)
|
|
145
|
+
ob.empty_display_type = shape
|
|
146
|
+
ob.empty_display_size = size
|
|
147
|
+
col.objects.link(ob)
|
|
148
|
+
ob.parent = parent
|
|
149
|
+
ob.location = loc
|
|
150
|
+
ob.rotation_mode = "XYZ"
|
|
151
|
+
return ob
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def proxy_box(name, col, parent, size, offset=(0, 0, 0), mat=None):
|
|
155
|
+
me = bpy.data.meshes.new(name)
|
|
156
|
+
bm = bmesh.new()
|
|
157
|
+
bmesh.ops.create_cube(bm, size=1.0)
|
|
158
|
+
for v in bm.verts:
|
|
159
|
+
v.co = (v.co.x * size[0] + offset[0], v.co.y * size[1] + offset[1], v.co.z * size[2] + offset[2])
|
|
160
|
+
bm.to_mesh(me)
|
|
161
|
+
bm.free()
|
|
162
|
+
ob = bpy.data.objects.new(name, me)
|
|
163
|
+
col.objects.link(ob)
|
|
164
|
+
ob.parent = parent
|
|
165
|
+
if mat:
|
|
166
|
+
me.materials.append(mat)
|
|
167
|
+
return ob
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def proxy_material():
|
|
171
|
+
mat = bpy.data.materials.get("PROXY_Skin") or bpy.data.materials.new("PROXY_Skin")
|
|
172
|
+
mat.use_nodes = True
|
|
173
|
+
bsdf = next((n for n in mat.node_tree.nodes if n.type == "BSDF_PRINCIPLED"), None)
|
|
174
|
+
if bsdf:
|
|
175
|
+
bsdf.inputs["Base Color"].default_value = (0.23, 0.2, 0.16, 1.0)
|
|
176
|
+
bsdf.inputs["Roughness"].default_value = 0.72 # matte, aged scales
|
|
177
|
+
return mat
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def fcurves_of(ob):
|
|
181
|
+
"""F-curves for an object's action on Blender 4.x (legacy) and 5.x (slotted actions)."""
|
|
182
|
+
ad = ob.animation_data
|
|
183
|
+
if not ad or not ad.action:
|
|
184
|
+
return []
|
|
185
|
+
act = ad.action
|
|
186
|
+
if hasattr(act, "fcurves") and not getattr(act, "is_action_layered", False):
|
|
187
|
+
return list(act.fcurves)
|
|
188
|
+
from bpy_extras import anim_utils
|
|
189
|
+
cb = anim_utils.action_get_channelbag_for_slot(act, ad.action_slot)
|
|
190
|
+
return list(cb.fcurves) if cb else []
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def key(ob, frame, loc=None, rot=None, scale=None):
|
|
194
|
+
if loc is not None:
|
|
195
|
+
ob.location = loc
|
|
196
|
+
ob.keyframe_insert("location", frame=frame)
|
|
197
|
+
if rot is not None:
|
|
198
|
+
ob.rotation_euler = rot
|
|
199
|
+
ob.keyframe_insert("rotation_euler", frame=frame)
|
|
200
|
+
if scale is not None:
|
|
201
|
+
ob.scale = scale
|
|
202
|
+
ob.keyframe_insert("scale", frame=frame)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def apply_pbr(ob, tex_dir):
|
|
206
|
+
"""Principled material from Substance 'PBR Metallic Roughness' exports found in tex_dir."""
|
|
207
|
+
files = os.listdir(tex_dir)
|
|
208
|
+
|
|
209
|
+
def find(*keys):
|
|
210
|
+
for f in files:
|
|
211
|
+
low = f.lower().replace("_", "")
|
|
212
|
+
if any(k in low for k in keys):
|
|
213
|
+
return os.path.join(tex_dir, f)
|
|
214
|
+
return None
|
|
215
|
+
|
|
216
|
+
mat = bpy.data.materials.new(ob.name + "_PBR")
|
|
217
|
+
mat.use_nodes = True
|
|
218
|
+
nt = mat.node_tree
|
|
219
|
+
bsdf = next(n for n in nt.nodes if n.type == "BSDF_PRINCIPLED")
|
|
220
|
+
out = next(n for n in nt.nodes if n.type == "OUTPUT_MATERIAL")
|
|
221
|
+
used = {}
|
|
222
|
+
|
|
223
|
+
def img(path, non_color):
|
|
224
|
+
node = nt.nodes.new("ShaderNodeTexImage")
|
|
225
|
+
node.image = bpy.data.images.load(path, check_existing=True)
|
|
226
|
+
if non_color:
|
|
227
|
+
node.image.colorspace_settings.name = "Non-Color"
|
|
228
|
+
return node
|
|
229
|
+
|
|
230
|
+
for label, keys, sock, non_color in (
|
|
231
|
+
("base", ("basecolor", "albedo", "diffuse"), "Base Color", False),
|
|
232
|
+
("rough", ("roughness",), "Roughness", True),
|
|
233
|
+
("metal", ("metallic", "metalness"), "Metallic", True),
|
|
234
|
+
):
|
|
235
|
+
f = find(*keys)
|
|
236
|
+
if f:
|
|
237
|
+
nt.links.new(img(f, non_color).outputs["Color"], bsdf.inputs[sock])
|
|
238
|
+
used[label] = os.path.basename(f)
|
|
239
|
+
f = find("normal")
|
|
240
|
+
if f:
|
|
241
|
+
nm = nt.nodes.new("ShaderNodeNormalMap")
|
|
242
|
+
nt.links.new(img(f, True).outputs["Color"], nm.inputs["Color"])
|
|
243
|
+
nt.links.new(nm.outputs["Normal"], bsdf.inputs["Normal"])
|
|
244
|
+
used["normal"] = os.path.basename(f)
|
|
245
|
+
f = find("height", "displacement")
|
|
246
|
+
if f:
|
|
247
|
+
disp = nt.nodes.new("ShaderNodeDisplacement")
|
|
248
|
+
disp.inputs["Scale"].default_value = 0.02 * P["hip_height_m"] / 3.1
|
|
249
|
+
nt.links.new(img(f, True).outputs["Color"], disp.inputs["Height"])
|
|
250
|
+
nt.links.new(disp.outputs["Displacement"], out.inputs["Displacement"])
|
|
251
|
+
try:
|
|
252
|
+
mat.displacement_method = "BOTH" # true micro-displacement + bump
|
|
253
|
+
except (AttributeError, TypeError):
|
|
254
|
+
pass
|
|
255
|
+
used["height"] = os.path.basename(f)
|
|
256
|
+
if ob.data and hasattr(ob.data, "materials"):
|
|
257
|
+
ob.data.materials.clear()
|
|
258
|
+
ob.data.materials.append(mat)
|
|
259
|
+
return used
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
# ---------------------------------------------------------------------------
|
|
263
|
+
# Build
|
|
264
|
+
# ---------------------------------------------------------------------------
|
|
265
|
+
|
|
266
|
+
def build():
|
|
267
|
+
scene = bpy.context.scene
|
|
268
|
+
gait = derive_gait(P)
|
|
269
|
+
s = gait["scale"]
|
|
270
|
+
h = P["hip_height_m"]
|
|
271
|
+
fps = int(P["fps"])
|
|
272
|
+
f0, f1 = 1, int(round(P["duration_s"] * fps))
|
|
273
|
+
|
|
274
|
+
scene.render.fps = fps
|
|
275
|
+
scene.render.fps_base = 1.0
|
|
276
|
+
scene.frame_start, scene.frame_end = f0, f1
|
|
277
|
+
scene.unit_settings.system = "METRIC"
|
|
278
|
+
scene.unit_settings.scale_length = 1.0
|
|
279
|
+
|
|
280
|
+
if "Cube" in bpy.data.objects:
|
|
281
|
+
bpy.data.objects.remove(bpy.data.objects["Cube"], do_unlink=True)
|
|
282
|
+
remove_existing("CR_")
|
|
283
|
+
col = collection("Creature_Rig")
|
|
284
|
+
cam_col = collection("Camera_Rig")
|
|
285
|
+
mat = proxy_material()
|
|
286
|
+
|
|
287
|
+
# --- proxy rig (body faces +X) -------------------------------------------------
|
|
288
|
+
root = empty("CR_Root", col, size=1.5 * s, shape="ARROWS")
|
|
289
|
+
hips = empty("CR_Hips", col, root, (0, 0, h), 0.8 * s, "CUBE")
|
|
290
|
+
proxies = [proxy_box("CR_px_Hips", col, hips, (1.5 * s, 1.0 * s, 1.1 * s), mat=mat)]
|
|
291
|
+
spine, parent = [], hips
|
|
292
|
+
for i, off in enumerate(((0.9 * s, 0, 0.12 * s), (0.9 * s, 0, 0.1 * s))):
|
|
293
|
+
j = empty("CR_Spine%d" % (i + 1), col, parent, off, 0.5 * s)
|
|
294
|
+
proxies.append(proxy_box("CR_px_Spine%d" % (i + 1), col, j, (1.1 * s, 1.1 * s, 1.3 * s), mat=mat))
|
|
295
|
+
spine.append(j)
|
|
296
|
+
parent = j
|
|
297
|
+
chest = spine[-1]
|
|
298
|
+
neck, parent = [], empty("CR_NeckBase", col, chest, (0.7 * s, 0, 0.3 * s), 0.4 * s)
|
|
299
|
+
for i in range(P["neck_joints"]):
|
|
300
|
+
j = empty("CR_Neck%d" % (i + 1), col, parent, (0.32 * s, 0, 0.12 * s), 0.35 * s)
|
|
301
|
+
proxies.append(proxy_box("CR_px_Neck%d" % (i + 1), col, j, (0.45 * s, 0.6 * s, 0.7 * s), mat=mat))
|
|
302
|
+
neck.append(j)
|
|
303
|
+
parent = j
|
|
304
|
+
head = empty("CR_Head", col, parent, (0.35 * s, 0, 0.05 * s), 0.4 * s, "SPHERE")
|
|
305
|
+
proxies.append(proxy_box("CR_px_Head", col, head, (1.5 * s, 0.6 * s, 0.65 * s), (0.6 * s, 0, 0), mat=mat))
|
|
306
|
+
tail, parent = [], hips
|
|
307
|
+
for i in range(P["tail_joints"]):
|
|
308
|
+
taper = 1.0 - 0.13 * i
|
|
309
|
+
j = empty("CR_Tail%d" % (i + 1), col, parent, (-0.85 * s if i else -0.7 * s, 0, 0), 0.4 * s * taper)
|
|
310
|
+
proxies.append(proxy_box("CR_px_Tail%d" % (i + 1), col, j, (0.9 * s, 0.8 * s * taper, 0.8 * s * taper),
|
|
311
|
+
(-0.45 * s, 0, 0), mat=mat))
|
|
312
|
+
tail.append(j)
|
|
313
|
+
parent = j
|
|
314
|
+
feet, legs = {}, {}
|
|
315
|
+
for side, sy in (("L", 1.0), ("R", -1.0)):
|
|
316
|
+
sock = empty("CR_HipSocket_%s" % side, col, hips, (0, sy * 0.5 * s, -0.15 * s), 0.25 * s)
|
|
317
|
+
foot = empty("CR_Foot_%s" % side, col, None, (0, sy * 0.38 * s, 0), 0.5 * s, "CUBE")
|
|
318
|
+
proxies.append(proxy_box("CR_px_Foot_%s" % side, col, foot, (0.9 * s, 0.4 * s, 0.2 * s), (0.2 * s, 0, 0.1 * s), mat=mat))
|
|
319
|
+
leg = proxy_box("CR_px_Leg_%s" % side, col, sock, (0.45 * s, 1.0, 0.45 * s), (0, 0.5, 0), mat=mat)
|
|
320
|
+
st = leg.constraints.new("STRETCH_TO")
|
|
321
|
+
st.target = foot
|
|
322
|
+
st.rest_length = 1.0
|
|
323
|
+
st.volume = "NO_VOLUME"
|
|
324
|
+
proxies.append(leg)
|
|
325
|
+
feet[side], legs[side] = foot, leg
|
|
326
|
+
|
|
327
|
+
# --- shot layout ----------------------------------------------------------------
|
|
328
|
+
dur = P["duration_s"]
|
|
329
|
+
cam_x = 0.0
|
|
330
|
+
x0 = cam_x - gait["speed_mps"] * P["pass_at"] * dur
|
|
331
|
+
cam_pos = (cam_x, -P["cam_distance_m"], P["cam_height_m"])
|
|
332
|
+
|
|
333
|
+
# --- camera rig: operator pans a tripod-less camera, reacting late ---------------
|
|
334
|
+
remove_existing("CAM_")
|
|
335
|
+
aim = empty("CAM_Aim", cam_col, None, (0, 0, h), 0.5)
|
|
336
|
+
rig = empty("CAM_Rig", cam_col, None, cam_pos, 0.5)
|
|
337
|
+
tt = rig.constraints.new("TRACK_TO")
|
|
338
|
+
tt.target = aim
|
|
339
|
+
tt.track_axis = "TRACK_NEGATIVE_Z"
|
|
340
|
+
tt.up_axis = "UP_Y"
|
|
341
|
+
cam_data = bpy.data.cameras.new("CAM_Cinematic")
|
|
342
|
+
cam = bpy.data.objects.new("CAM_Cinematic", cam_data)
|
|
343
|
+
cam_col.objects.link(cam)
|
|
344
|
+
cam.parent = rig
|
|
345
|
+
cam.rotation_mode = "XYZ"
|
|
346
|
+
cam_data.lens = P["lens_mm"]
|
|
347
|
+
cam_data.sensor_fit = "HORIZONTAL"
|
|
348
|
+
cam_data.sensor_width = P["sensor_mm"]
|
|
349
|
+
cam_data.clip_end = 1000.0
|
|
350
|
+
cam_data.dof.use_dof = True
|
|
351
|
+
cam_data.dof.focus_object = head
|
|
352
|
+
cam_data.dof.aperture_fstop = P["fstop"]
|
|
353
|
+
cam_data.dof.aperture_blades = 7
|
|
354
|
+
scene.camera = cam
|
|
355
|
+
|
|
356
|
+
# --- bake the animation -------------------------------------------------------
|
|
357
|
+
lag = P["joint_lag_frames"] / float(fps)
|
|
358
|
+
N, M = len(neck), len(tail)
|
|
359
|
+
look_max = math.radians(P["look_max_deg"])
|
|
360
|
+
contacts = []
|
|
361
|
+
prev_swing = {"L": None, "R": None}
|
|
362
|
+
for f in range(f0, f1 + 1):
|
|
363
|
+
t = (f - f0) / float(fps)
|
|
364
|
+
b = body_pose(t, gait, P)
|
|
365
|
+
key(root, f, loc=(x0 + b["root_x"], 0, 0))
|
|
366
|
+
key(hips, f, loc=(0, b["hip_y"], b["hip_z"]), rot=(b["hip_roll"], b["hip_pitch"], b["hip_yaw"]))
|
|
367
|
+
# spine counter-rotates the pelvis yaw (shoulders vs hips), lagged
|
|
368
|
+
for i, j in enumerate(spine):
|
|
369
|
+
bl = body_pose(t - (i + 1) * lag, gait, P)
|
|
370
|
+
key(j, f, rot=(-0.4 * bl["hip_roll"], 0.0, -0.35 * bl["hip_yaw"]))
|
|
371
|
+
breathe = 1.0 + 0.012 * math.sin(TAU * t / gait["breath_s"])
|
|
372
|
+
key(chest, f, scale=(1.0, breathe, breathe))
|
|
373
|
+
|
|
374
|
+
# head-look toward the lens: head leads, each joint toward the base engages later
|
|
375
|
+
head_x = x0 + b["root_x"] + 3.3 * s
|
|
376
|
+
want = math.atan2(cam_pos[1] - 0.0, cam_pos[0] - head_x)
|
|
377
|
+
want = max(-look_max, min(look_max, want))
|
|
378
|
+
|
|
379
|
+
def look_w(tt_):
|
|
380
|
+
u = tt_ / dur
|
|
381
|
+
return smoothstep((u - P["look_in"]) / 0.12) * (1.0 - smoothstep((u - P["look_hold"]) / max(0.01, P["look_out"] - P["look_hold"])))
|
|
382
|
+
|
|
383
|
+
body_yaw = b["hip_yaw"] - 0.35 * b["hip_yaw"] * len(spine)
|
|
384
|
+
neck_pitch_sum = 0.0
|
|
385
|
+
for k, j in enumerate(neck):
|
|
386
|
+
tk = t - (k + 1) * lag
|
|
387
|
+
bk = body_pose(tk, gait, P)
|
|
388
|
+
amp = math.radians(2.2) * (k + 1) / N
|
|
389
|
+
pitch = amp * math.cos(2 * TAU * (bk["phase"] - 0.06)) # neck droops after the hips drop
|
|
390
|
+
yaw_bal = -math.radians(1.5) * math.cos(TAU * (bk["phase"] - P["duty_factor"] / 2.0))
|
|
391
|
+
w = look_w(t - (N - k) * lag)
|
|
392
|
+
yaw = yaw_bal + w * (want - body_yaw) * 0.6 / N
|
|
393
|
+
neck_pitch_sum += pitch
|
|
394
|
+
key(j, f, rot=(0.0, pitch, yaw))
|
|
395
|
+
# gaze stabilisation: the head cancels most of the body/neck pitch
|
|
396
|
+
key(head, f, rot=(0.0, -0.85 * (neck_pitch_sum + b["hip_pitch"]), look_w(t) * (want - body_yaw) * 0.4))
|
|
397
|
+
|
|
398
|
+
for k, j in enumerate(tail):
|
|
399
|
+
tk = t - (k + 1) * lag
|
|
400
|
+
bk = body_pose(tk, gait, P)
|
|
401
|
+
r = ((k + 1) / float(M)) ** 0.7
|
|
402
|
+
yaw = -math.radians(3.2) * r * math.cos(TAU * (bk["phase"] - P["duty_factor"] / 2.0))
|
|
403
|
+
pitch = -math.radians(1.4) * r * math.cos(2 * TAU * (bk["phase"] - 0.06))
|
|
404
|
+
key(j, f, rot=(0.0, pitch, yaw))
|
|
405
|
+
|
|
406
|
+
for side, off, sy in (("L", 0.0, 1.0), ("R", 0.5, -1.0)):
|
|
407
|
+
fx, fz, fp, swing = foot_world(b["phase"], off, gait, P, x0)
|
|
408
|
+
key(feet[side], f, loc=(fx, sy * 0.38 * s, fz), rot=(0.0, fp, 0.0))
|
|
409
|
+
if prev_swing[side] and not swing:
|
|
410
|
+
contacts.append((f, side))
|
|
411
|
+
prev_swing[side] = swing
|
|
412
|
+
|
|
413
|
+
# operator follows the chest late (reaction lag), aim point smoothed
|
|
414
|
+
ba = body_pose(max(0.0, t - P["operator_lag_s"]), gait, P)
|
|
415
|
+
key(aim, f, loc=(x0 + ba["root_x"] + 1.8 * s, 0.0, 0.95 * h))
|
|
416
|
+
|
|
417
|
+
# --- camera: footfall impacts + handheld noise ---------------------------------
|
|
418
|
+
for m in [m for m in scene.timeline_markers if m.name.endswith("_contact")]:
|
|
419
|
+
scene.timeline_markers.remove(m)
|
|
420
|
+
shake = math.radians(P["footfall_shake_deg"]) * (P["mass_kg"] / 8000.0) ** (1 / 3.0) * (10.0 / max(1.0, P["cam_distance_m"]))
|
|
421
|
+
for f in range(f0, f1 + 1):
|
|
422
|
+
rx = rz = 0.0
|
|
423
|
+
for c, _side in contacts:
|
|
424
|
+
d = (f - c) / float(fps)
|
|
425
|
+
if 0.0 <= d < 0.6:
|
|
426
|
+
env = math.exp(-d / 0.12)
|
|
427
|
+
rx += shake * env * math.sin(TAU * d * 9.0)
|
|
428
|
+
rz += 0.35 * shake * env * math.sin(TAU * d * 7.0 + 1.3)
|
|
429
|
+
key(cam, f, rot=(rx, 0.0, rz))
|
|
430
|
+
for c, side in contacts:
|
|
431
|
+
scene.timeline_markers.new("%s_contact" % side, frame=c)
|
|
432
|
+
for fc in fcurves_of(cam):
|
|
433
|
+
if fc.data_path == "rotation_euler":
|
|
434
|
+
mod = fc.modifiers.new("NOISE")
|
|
435
|
+
mod.scale = 38.0 + 7.0 * fc.array_index
|
|
436
|
+
mod.strength = math.radians(P["handheld_deg"]) * 2.0
|
|
437
|
+
mod.phase = 11.0 * (fc.array_index + 1)
|
|
438
|
+
|
|
439
|
+
# --- bind the hero asset ---------------------------------------------------------
|
|
440
|
+
bound = {}
|
|
441
|
+
for obj_name, ctrl_name in (P["bind"] or {}).items():
|
|
442
|
+
ob = bpy.data.objects.get(obj_name)
|
|
443
|
+
ctrl = bpy.data.objects.get("CR_" + ctrl_name) or bpy.data.objects.get(ctrl_name)
|
|
444
|
+
if ob is None or ctrl is None:
|
|
445
|
+
bound[obj_name] = "skipped (object or control missing)"
|
|
446
|
+
continue
|
|
447
|
+
scene.frame_set(f0)
|
|
448
|
+
mw = ob.matrix_world.copy()
|
|
449
|
+
ob.parent = ctrl
|
|
450
|
+
ob.matrix_parent_inverse = ctrl.matrix_world.inverted()
|
|
451
|
+
ob.matrix_world = mw
|
|
452
|
+
bound[obj_name] = ctrl.name
|
|
453
|
+
if P["texture_dir"] and os.path.isdir(bpy.path.abspath(P["texture_dir"])):
|
|
454
|
+
bound[obj_name + ":pbr"] = apply_pbr(ob, bpy.path.abspath(P["texture_dir"]))
|
|
455
|
+
show_proxies = P["proxy_render"] if P["proxy_render"] is not None else not any(v.startswith("CR_") for v in bound.values() if isinstance(v, str))
|
|
456
|
+
for px in proxies:
|
|
457
|
+
px.hide_render = not show_proxies
|
|
458
|
+
|
|
459
|
+
# --- ground / light / world ------------------------------------------------------
|
|
460
|
+
remove_existing("ENV_")
|
|
461
|
+
env_col = collection("Environment")
|
|
462
|
+
gme = bpy.data.meshes.new("ENV_Ground")
|
|
463
|
+
bm = bmesh.new()
|
|
464
|
+
bmesh.ops.create_grid(bm, x_segments=1, y_segments=1, size=150.0)
|
|
465
|
+
bm.to_mesh(gme)
|
|
466
|
+
bm.free()
|
|
467
|
+
ground = bpy.data.objects.new("ENV_Ground", gme)
|
|
468
|
+
env_col.objects.link(ground)
|
|
469
|
+
ground.is_shadow_catcher = True # shadows only; the plate provides the ground in comp
|
|
470
|
+
sun_data = bpy.data.lights.new("ENV_Sun", "SUN")
|
|
471
|
+
sun_data.energy = 4.0
|
|
472
|
+
sun_data.angle = math.radians(0.8)
|
|
473
|
+
sun = bpy.data.objects.new("ENV_Sun", sun_data)
|
|
474
|
+
env_col.objects.link(sun)
|
|
475
|
+
sun.rotation_euler = (math.radians(48), 0.0, math.radians(35))
|
|
476
|
+
world = scene.world or bpy.data.worlds.new("World")
|
|
477
|
+
scene.world = world
|
|
478
|
+
world.mist_settings.start = max(0.0, P["cam_distance_m"] - 6.0)
|
|
479
|
+
world.mist_settings.depth = 60.0
|
|
480
|
+
world.mist_settings.falloff = "LINEAR"
|
|
481
|
+
|
|
482
|
+
# --- render / passes ---------------------------------------------------------------
|
|
483
|
+
r = scene.render
|
|
484
|
+
r.engine = P["engine"]
|
|
485
|
+
r.resolution_x, r.resolution_y = P["resolution"]
|
|
486
|
+
r.resolution_percentage = 100
|
|
487
|
+
r.use_motion_blur = True
|
|
488
|
+
r.motion_blur_shutter = P["shutter"]
|
|
489
|
+
r.film_transparent = True
|
|
490
|
+
if r.engine == "CYCLES":
|
|
491
|
+
scene.cycles.samples = P["samples"]
|
|
492
|
+
scene.cycles.use_denoising = True
|
|
493
|
+
vl = bpy.context.view_layer
|
|
494
|
+
for attr in ("use_pass_z", "use_pass_mist", "use_pass_normal", "use_pass_cryptomatte_object"):
|
|
495
|
+
if hasattr(vl, attr):
|
|
496
|
+
setattr(vl, attr, True)
|
|
497
|
+
if hasattr(vl, "cycles") and hasattr(vl.cycles, "use_pass_shadow_catcher"):
|
|
498
|
+
vl.cycles.use_pass_shadow_catcher = True
|
|
499
|
+
out_dir = P["output_dir"]
|
|
500
|
+
if hasattr(r.image_settings, "media_type"): # Blender 5.x
|
|
501
|
+
r.image_settings.media_type = "MULTI_LAYER_IMAGE"
|
|
502
|
+
else:
|
|
503
|
+
r.image_settings.file_format = "OPEN_EXR_MULTILAYER"
|
|
504
|
+
r.image_settings.color_depth = "16"
|
|
505
|
+
r.filepath = os.path.join(out_dir, "exr", "Dino_Render_")
|
|
506
|
+
comp_outputs = setup_pass_outputs(scene, out_dir)
|
|
507
|
+
|
|
508
|
+
scene.frame_set(f0)
|
|
509
|
+
return {
|
|
510
|
+
"gait": {k: round(v, 3) for k, v in gait.items()},
|
|
511
|
+
"frames": [f0, f1], "fps": fps,
|
|
512
|
+
"contacts": [c for c, _ in contacts],
|
|
513
|
+
"camera": {"lens_mm": P["lens_mm"], "distance_m": P["cam_distance_m"], "fstop": P["fstop"],
|
|
514
|
+
"shutter": P["shutter"], "footfall_shake_deg": round(math.degrees(shake), 3)},
|
|
515
|
+
"bound": bound, "proxies_render": show_proxies,
|
|
516
|
+
"outputs": {"multilayer_exr": r.filepath, **comp_outputs},
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
def setup_pass_outputs(scene, out_dir):
|
|
521
|
+
"""PNG sequences AE can import directly: beauty (RGBA), shadow catcher, mist."""
|
|
522
|
+
want = (("Image", "beauty", "Dino_Render_Beauty_", "RGBA"),
|
|
523
|
+
("Shadow Catcher", "shadow", "Dino_Shadow_", "RGB"),
|
|
524
|
+
("Mist", "mist", "Dino_Mist_", "BW"))
|
|
525
|
+
written = {}
|
|
526
|
+
try:
|
|
527
|
+
if hasattr(scene, "compositing_node_group"): # Blender 5.x
|
|
528
|
+
tree = scene.compositing_node_group
|
|
529
|
+
if tree is None:
|
|
530
|
+
tree = bpy.data.node_groups.new("MCP_Compositor", "CompositorNodeTree")
|
|
531
|
+
scene.compositing_node_group = tree
|
|
532
|
+
else: # Blender 4.x
|
|
533
|
+
scene.use_nodes = True
|
|
534
|
+
tree = scene.node_tree
|
|
535
|
+
for n in [n for n in tree.nodes if n.name.startswith("MCP_")]:
|
|
536
|
+
tree.nodes.remove(n)
|
|
537
|
+
rl = tree.nodes.new("CompositorNodeRLayers")
|
|
538
|
+
rl.name = "MCP_RenderLayers"
|
|
539
|
+
for i, (sock_name, sub, base, mode) in enumerate(want):
|
|
540
|
+
sock = next((o for o in rl.outputs if o.name == sock_name and o.enabled), None)
|
|
541
|
+
if sock is None:
|
|
542
|
+
written[sub] = "skipped (pass %r unavailable for this engine)" % sock_name
|
|
543
|
+
continue
|
|
544
|
+
fo = tree.nodes.new("CompositorNodeOutputFile")
|
|
545
|
+
fo.name = "MCP_Out_" + sub
|
|
546
|
+
fo.location = (400, -200 * i)
|
|
547
|
+
if hasattr(fo.format, "media_type"): # 5.x defaults nodes to multilayer EXR
|
|
548
|
+
fo.format.media_type = "IMAGE"
|
|
549
|
+
fo.format.file_format = "PNG"
|
|
550
|
+
fo.format.color_depth = "16"
|
|
551
|
+
fo.format.color_mode = mode
|
|
552
|
+
folder = os.path.join(out_dir, sub)
|
|
553
|
+
if hasattr(fo, "file_output_items"): # 5.x
|
|
554
|
+
fo.directory = folder
|
|
555
|
+
fo.file_name = base
|
|
556
|
+
fo.file_output_items.clear()
|
|
557
|
+
item = fo.file_output_items.new("RGBA" if mode != "BW" else "FLOAT", "")
|
|
558
|
+
tree.links.new(sock, fo.inputs[item.name] if item.name else fo.inputs[0])
|
|
559
|
+
else: # 4.x
|
|
560
|
+
fo.base_path = folder
|
|
561
|
+
fo.file_slots[0].path = base
|
|
562
|
+
tree.links.new(sock, fo.inputs[0])
|
|
563
|
+
written[sub] = os.path.join(folder, base + "####.png")
|
|
564
|
+
except Exception as e: # never lose the shot over comp plumbing; the EXR has every pass
|
|
565
|
+
written["error"] = "pass outputs not configured: %s" % e
|
|
566
|
+
return written
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
result = build()
|