-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplus_batch.py
More file actions
69 lines (55 loc) · 2.44 KB
/
Copy pathplus_batch.py
File metadata and controls
69 lines (55 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# plus_batch.py — Blender 내부에서 plus.py를 여러 번 실행하여 일괄 머지 수행
# 속도 개선
# 실행: blender --background --python plus_batch.py -- <config.json>
import sys, os, json, runpy
import bpy
def reset_scene():
# 깨끗한 상태로 초기화 (기존 씬 잔여물 제거)
bpy.ops.wm.read_factory_settings(use_empty=True)
def run_plus_once(plus_script, obj_path, base_glb, out_glb, hair_glb):
# plus.py가 argv를 사용하는 형태를 그대로 흉내내서 호출
argv = [plus_script, "--", obj_path, base_glb, out_glb]
if hair_glb:
argv.append(hair_glb)
# 씬 리셋 후 실행
reset_scene()
# runpy로 실행하면서 SystemExit 방지
old_argv = sys.argv[:]
try:
sys.argv = argv
try:
runpy.run_path(plus_script, run_name="__main__")
except SystemExit as e:
# plus.py가 sys.exit()를 호출해도 배치가 끊기지 않도록 무시
pass
finally:
sys.argv = old_argv
# 산출물 확인
if not os.path.exists(out_glb) or os.path.getsize(out_glb) == 0:
raise RuntimeError(f"[plus_batch] 출력 파일이 생성되지 않음: {out_glb}")
def main():
if "--" not in sys.argv:
raise RuntimeError("usage: blender --background --python plus_batch.py -- <config.json>")
cfg_path = sys.argv[sys.argv.index("--") + 1]
if not os.path.exists(cfg_path):
raise RuntimeError(f"[plus_batch] 설정 파일이 없음: {cfg_path}")
with open(cfg_path, "r", encoding="utf-8") as f:
cfg = json.load(f)
plus_script = cfg["plus_script"]
obj_path = cfg["obj"]
hair_glb = cfg.get("hair") or None
pairs = cfg["pairs"]
if not os.path.exists(plus_script):
raise RuntimeError(f"[plus_batch] plus.py 경로 없음: {plus_script}")
if not os.path.exists(obj_path):
raise RuntimeError(f"[plus_batch] obj 경로 없음: {obj_path}")
for i, pair in enumerate(pairs, 1):
base_glb = pair["base"]
out_glb = pair["out"]
if not os.path.exists(base_glb):
raise RuntimeError(f"[plus_batch] base 경로 없음: {base_glb}")
print(f"[plus_batch] ({i}/{len(pairs)}) base={base_glb} -> out={out_glb}")
run_plus_once(plus_script, obj_path, base_glb, out_glb, hair_glb)
print("[plus_batch] 완료")
if __name__ == "__main__":
main()