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.
101 lines
3.9 KiB
101 lines
3.9 KiB
#读取需要重新贴图的数据 |
|
import os,sys,time,shlex,subprocess,shutil |
|
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 libs_db_repeat_texture |
|
import libs,config |
|
|
|
|
|
#读取 数据库的信息 |
|
def get_pid(): |
|
data = libs_db_repeat_texture.get_pid_task() |
|
if data != None and data != "error": |
|
return data[0],data[1] |
|
else: |
|
return None,None |
|
|
|
#开始处理任务 |
|
def start_task(pid): |
|
#下载Obj数据 |
|
print(f"处理{pid}任务") |
|
print("开始下载{pid}数据") |
|
# pid = str("175635") |
|
complateCloudPath = libs.down_obj_from_oss_for_repeat_texture(config.workdir, pid,"auto") |
|
if complateCloudPath == "error": |
|
return -1,"error-从oss上下载出问题" |
|
#下载下来之后重新加载obj 和texture |
|
print("complateCloudPath",complateCloudPath) |
|
|
|
|
|
outPath = os.path.join(config.workdir, pid, "output") |
|
if os.path.exists(outPath): |
|
print("移除文件夹") |
|
#移除文件夹 |
|
shutil.rmtree(outPath) |
|
|
|
cmd = f'{config.rcbin} {config.r2["init"]} -setInstanceName {pid} \ |
|
-load "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" \ |
|
-importModel "{os.path.join(complateCloudPath, f"{pid}.obj")}" \ |
|
-calculateTexture -exportSelectedModel "{os.path.join(config.workdir, pid, "output", f"{pid}.obj")}" "d:\\make2\\config\\ModelExportParams0722.xml" -quit' |
|
print(cmd) |
|
cmd = shlex.split(cmd) |
|
res = subprocess.run(cmd) |
|
|
|
#检查out目录文件夹是否有多个 贴图文件。如果是的话只保留最新的一个,并且重命名为初始图像的名称 |
|
outFilePath = os.path.join(config.workdir, pid, "output") |
|
arrTempImage = [] |
|
for file in os.listdir(outFilePath): |
|
if file.endswith(".jpg") or file.endswith(".png"): |
|
#字符串替换 |
|
fileTempName = file.replace(f"{pid}_u0_v0_diffuse","") |
|
fileTempName = fileTempName.replace(".jpg","") |
|
fileTempName = fileTempName.replace(".png","") |
|
if "_" in fileTempName: |
|
fileTempName = fileTempName.replace("_","") |
|
arrTempImage.append(fileTempName) |
|
print(arrTempImage) |
|
if len(arrTempImage) > 1: |
|
#获取 arrTempImage 中最大的值 |
|
arrTempImage.sort() |
|
print(arrTempImage) |
|
#获取最大值 |
|
maxValue = arrTempImage[-1] |
|
|
|
for i in arrTempImage: |
|
if i == "": |
|
filePath1 = os.path.join(config.workdir, pid, "output",pid+"_u0_v0_diffuse.jpg") |
|
filePath2 = os.path.join(config.workdir, pid, "output",pid+"_u0_v0_diffuse.png") |
|
else: |
|
filePath1 = os.path.join(config.workdir, pid, "output",pid+"_u0_v0_diffuse_"+str(i)+".jpg") |
|
filePath2 = os.path.join(config.workdir, pid, "output",pid+"_u0_v0_diffuse_"+str(i)+".png") |
|
|
|
if i != maxValue: |
|
if os.path.exists(filePath1): |
|
os.remove(filePath1) |
|
if os.path.exists(filePath2): |
|
os.remove(filePath2) |
|
else: |
|
if os.path.exists(filePath1): |
|
os.rename(filePath1,os.path.join(config.workdir, pid, "output",pid+"_u0_v0_diffuse.jpg")) |
|
if os.path.exists(filePath2): |
|
os.rename(filePath2,os.path.join(config.workdir, pid, "output",pid+"_u0_v0_diffuse.jpg")) |
|
#执行step3 |
|
os.system(f'python d:\\make2\\main_step3.py {pid}') |
|
return 3,"success" |
|
|
|
if __name__ == '__main__': |
|
while True: |
|
id,pid = get_pid() |
|
print(f"读取的数据{pid}") |
|
if pid != None: |
|
#更新状态为2 |
|
libs_db_repeat_texture.update_status(id,2) |
|
statusres,res = start_task(str(pid)) |
|
libs_db_repeat_texture.update_status(id,statusres) |
|
else: |
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}-没有任务') |
|
time.sleep(10)
|
|
|