File size: 1,916 Bytes
abd6877 | 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 | # -*- coding: utf-8 -*-
"""
统一路径与可执行文件定位。
原则:仓库内的一切路径都相对本文件推导,不写死盘符。
克隆到 D:\\work\\build3d 或 /home/u/build3d 都能跑,只要遵守两点:
1. Blender 便携版解压在仓库根目录下(目录名以 blender 开头),或设置环境变量 BLENDER_EXE
2. Python 依赖按 requirements.txt 装好
"""
import glob
import os
import shutil
APP = os.path.dirname(os.path.abspath(__file__))
PROJECT = os.path.dirname(APP)
DEMO = os.path.join(PROJECT, "demo")
STATIC = os.path.join(APP, "static")
PLANS = os.path.join(STATIC, "plans")
THUMBS = os.path.join(STATIC, "thumbs")
OUTPUT = os.path.join(APP, "output")
MEDIA = DEMO # 页面里的 /media/* 映射到 demo/
BUILD_SCRIPT = os.path.join(DEMO, "build_model.py")
BLENDER_VERSION = "4.5.15"
BLENDER_DIR_NAME = "blender-%s-windows-x64" % BLENDER_VERSION
def find_blender():
"""按 环境变量 → 仓库根目录 blender*/blender.exe → PATH 的顺序查找"""
env = os.environ.get("BLENDER_EXE", "").strip().strip('"')
if env and os.path.isfile(env):
return env
for pattern in (os.path.join(PROJECT, "blender*", "blender.exe"),
os.path.join(PROJECT, "*", "blender.exe")):
for c in sorted(glob.glob(pattern)):
if os.path.isfile(c):
return c
found = shutil.which("blender") or shutil.which("blender.exe")
if found:
return found
# 都没找到时返回期望位置,便于上层给出"请先解压 Blender"的提示
return os.path.join(PROJECT, BLENDER_DIR_NAME, "blender.exe")
BLENDER = find_blender()
BLENDER_OK = os.path.isfile(BLENDER)
if __name__ == "__main__":
for k in ("PROJECT", "APP", "STATIC", "OUTPUT", "MEDIA", "BLENDER"):
print("%-10s %s" % (k, globals()[k]))
print("%-10s %s" % ("BLENDER_OK", BLENDER_OK))
|