You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
4.9 KiB
103 lines
4.9 KiB
import os, sys, time, shutil, subprocess, shlex |
|
import platform |
|
if platform.system() == 'Windows': |
|
#sys.path.append('e:\\libs\\') |
|
sys.path.append('libs') |
|
sys.path.append('logic') |
|
else: |
|
sys.path.append('/data/deploy/make3d/make2/libs/') |
|
import config, libs, libs_db,logic_main_service |
|
|
|
def load_model(pid): |
|
cmd = f'{config.rcbin} {config.r1["init"]} -load "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}"' |
|
print(cmd) |
|
cmd = shlex.split(cmd) |
|
res = subprocess.run(cmd) |
|
|
|
def get_rcver(): |
|
rcbin = '"C:\\Program Files\\Capturing Reality\\RealityCapture\\RealityCapture.exe"' |
|
if os.path.getsize(rcbin[1:-1]) == 20783616: |
|
return 1 |
|
else: |
|
return 2 |
|
|
|
def make3d(pid): |
|
simplify_value = 1000000 * libs.getHeadCount(pid) |
|
add_photo3 = ' ' |
|
if os.path.exists(os.path.join(config.workdir, pid, 'photo3')): |
|
add_photo3 = ' -addFolder "' + os.path.join(config.workdir, pid, 'photo3') + '" -align -align ' |
|
|
|
if get_rcver() == 1: # old version |
|
cmd = f'{config.rcbin} {config.r1["init"]} \ |
|
-addFolder "{os.path.join(config.workdir, pid, "photo1")}" -addFolder "{os.path.join(config.workdir, pid, "photo2")}" {add_photo3} \ |
|
-importControlPointsMeasurements "{os.path.join(config.workdir, pid, f"{pid}.controlPoints.csv")}" \ |
|
-align -save "{os.path.join(config.workdir, pid, f"{pid}_wait.rcproj")}" ' |
|
print(cmd) |
|
cmd = shlex.split(cmd) |
|
res = subprocess.run(cmd) |
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 定位点导入完成') |
|
|
|
# defind_distance |
|
|
|
time.sleep(20) |
|
shutil.move(os.path.join(config.workdir, pid, f'{pid}_wait.rcproj'), os.path.join(config.workdir, pid, f'{pid}.rcproj')) |
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 定义定位点距离完成') |
|
|
|
cmd = f'{config.rcbin} {config.r1["init"]} -load "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" -update \ |
|
-setReconstructionRegion "{os.path.join(config.workdir, pid, f"{pid}.rcbox")}" \ |
|
-mvs -modelSelectMaximalConnectedComponent -modelInvertSelection -modelRemoveSelectedTriangles -closeHoles -clean -simplify {simplify_value} -smooth -unwrap -calculateTexture -renameModel {pid} -exportModel "{pid} {os.path.join(config.workdir, pid, "output", f"{pid}.obj")}" "d:\\make2\\config\\ModelExportParams102.xml" -quit' |
|
print(cmd) |
|
cmd = shlex.split(cmd) |
|
res = subprocess.run(cmd) |
|
else: # new version |
|
if libs.aliyun_face(pid) and libs.get_ps_type(pid) == 1: |
|
calulate_type = 'calculateHighModel' |
|
else: |
|
calulate_type = 'calculateNormalModel' |
|
cmd = f'{config.rcbin} {config.r2["init"]} -setInstanceName {pid} \ |
|
-load "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" \ |
|
-{calulate_type} \ |
|
-selectLargestModelComponent -invertTrianglesSelection -removeSelectedTriangles -simplify {simplify_value} -smooth -closeHoles -cleanModel -calculateTexture \ |
|
-save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" \ |
|
-exportSelectedModel "{os.path.join(config.workdir, pid, "output", f"{pid}.obj")}" "d:\\make2\\config\\ModelExportParams.xml" -quit' |
|
print(cmd) |
|
cmd = shlex.split(cmd) |
|
res = subprocess.run(cmd) |
|
|
|
def step2(pid,task_distributed_id=""): |
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 开始建模任务step2') |
|
if os.path.exists(os.path.join(config.sharedir, pid)) and not os.path.exists(os.path.join(config.workdir, pid)): |
|
shutil.move(os.path.join(config.sharedir, pid), config.workdir) |
|
else: |
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 目录{os.path.join(config.sharedir, pid)}不存在,或{os.path.join(config.workdir, pid)}已存在') |
|
# return |
|
start_time = time.time() |
|
make3d(pid) |
|
|
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 建模任务step2完成,共费时{libs.diff_time(start_time)},任务已提交到step3') |
|
# 更新本地任务状态,加入step3任务队列 |
|
if task_distributed_id == "": |
|
os.system(f'python d:\\make2\\main_step3.py {pid}') |
|
else: |
|
logic_main_service.update_task_distributed_detail({"task_distributed_id":task_distributed_id,"finished_at":time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}) |
|
return |
|
|
|
def main(pid): |
|
if pid == '0': |
|
while True: |
|
# 取本地mysql队列任务,完成第二步的建模任务 |
|
|
|
step2(pid) |
|
else: |
|
step2(pid) |
|
|
|
if __name__ == '__main__': |
|
# 取本地mysql队列任务,完成第二步的建模任务 |
|
# 默认循环值守,可传参数运行单一任务,以方便调试 |
|
pid = '0' |
|
if len(sys.argv) > 1: |
|
pids = sys.argv[1].split(',') |
|
for pid in pids: |
|
main(pid) |
|
exit() |
|
main(pid) |