import os, sys, time, shutil, subprocess, shlex import platform if platform.system() == 'Windows': sys.path.append('e:\\libs\\') #sys.path.append('libs') else: sys.path.append('/data/deploy/make3d/make2/libs/') import config, libs, libs_db,common,main_service_db 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): if get_rcver() == 1: # old version #修改重建区域的大小 common.change_rcbox_s(pid,"0.999") simplify_value = 1000000 * libs.getHeadCount(pid) add_photo3 = ' ' if common.task_need_photo3(pid): 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(35) 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} 定义定位点距离完成') #2023-10-27为了解决老版本使用step1 的 重建区域框的问题,这里加入了 -set "sfmEnableCameraPrior=True" -align -set "sfmEnableCameraPrior=False" align 使相机的对齐线统一向下后,再进行重建区域的设置 cmd = f'{config.rcbin} {config.r1["init"]} -load "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" -update \ -set "sfmEnableCameraPrior=True" -align -set "sfmEnableCameraPrior=False" -align -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 common.task_need_high_model(pid): 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 #最后还是要判断有没有存在目录 if not os.path.exists(os.path.join(config.workdir, pid)): print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {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: main_service_db.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)