import os, sys, datetime, oss2, requests, time import subprocess, shlex, shutil def find_blender_bin_path(): base_path = 'C:\\Program Files\\Blender Foundation\\' if os.path.exists(base_path): for dir in os.listdir(base_path): if dir.startswith('Blender'): blender_bin_path = base_path + dir + '\\blender.exe' return f'"{blender_bin_path}"' else: print('未找到blender安装目录') exit(1) def diff_time(start_time, end_time): d = end_time - start_time m = d.microseconds return str(d.seconds // 60) + ":" + str(d.seconds % 60) + ":" + str(m)[:-3] def delete_lines_in_file(filename, count): with open(filename, 'r') as f: lines = f.readlines() lines = lines[count:] with open(filename, 'w') as f: f.writelines(lines) def fix_mtl_file(pid): mtl_file = os.path.join(input_path, pid + '.mtl') with open(mtl_file, 'r') as f: lines = f.readlines() lines = [line.replace('_u1_v1.jpg', '.jpg') for line in lines] with open(mtl_file, 'w') as f: f.writelines(lines) os.rename(os.path.join(input_path, pid + '_u1_v1.jpg'), os.path.join(input_path, pid + '.jpg')) if __name__ == '__main__': AccessKeyId = 'LTAI5tSReWm8hz7dSYxxth8f' AccessKeySecret = '8ywTDF9upPAtvgXtLKALY2iMYHIxdS' Endpoint = 'oss-cn-shanghai.aliyuncs.com' Bucket = 'suwa3d-securedata' oss_client = oss2.Bucket(oss2.Auth(AccessKeyId, AccessKeySecret), Endpoint, Bucket) update_status_modelsuccess_url = 'https://repair.api.suwa3d.com/api/modelRepairOrder/toModelMakeSucceed' blenderbin = find_blender_bin_path() workdir = "d:\\" start = datetime.datetime.now() if len(sys.argv) == 2: pid = sys.argv[1] else: print('usage: python update.py [pid]') exit(1) input_path = os.path.join(workdir, pid, 'output') fix_mtl_file(pid) os.system(f'{blenderbin} -b -P d:\\apps\\blender\\autofix.py -- {pid}') os.system(f'gltfpack -c -i {os.path.join(input_path, pid + ".obj")} -o {os.path.join(input_path, pid + ".glb")}') print(f'开始上传{pid}模型文件...') oss_client.put_object_from_file(f'objs/auto/{pid}/{pid}.obj', os.path.join(input_path, pid + '.obj')) oss_client.put_object_from_file(f'objs/auto/{pid}/{pid}.mtl', os.path.join(input_path, pid + '.mtl')) oss_client.put_object_from_file(f'objs/auto/{pid}/{pid}.jpg', os.path.join(input_path, pid + '.jpg')) oss_client.put_object_from_file(f'glbs/auto/{pid}.glb', os.path.join(input_path, pid + '.glb')) print(f'{update_status_modelsuccess_url}?id={pid}') res = requests.post(update_status_modelsuccess_url, data={'id': pid}) print('上传完成更新建模成功状态:', res.text) shutil.rmtree(os.path.join(workdir, pid), ignore_errors=True)