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.
53 lines
2.6 KiB
53 lines
2.6 KiB
import os, sys, oss2, time |
|
|
|
def main(): |
|
pids = [pid for pid in os.listdir(workdir) if os.path.isdir(os.path.join(workdir, pid))] |
|
for pid in pids: |
|
if not os.path.exists(os.path.join(workdir, pid, f'{pid}.obj')): |
|
print(f'文件不存在: {pid}.obj, 跳过处理{pid}') |
|
continue |
|
if not os.path.exists(os.path.join(workdir, pid, f'{pid}.mtl')): |
|
print(f'文件不存在: {pid}.mtl, 跳过处理{pid}') |
|
continue |
|
if not os.path.exists(os.path.join(workdir, pid, f'{pid}Tex1.jpg')): |
|
print(f'文件不存在: {pid}Tex1.jpg, 跳过处理{pid}') |
|
continue |
|
print(f'开始处理{pid},先生成glb文件,删除oss上的文件,再上传模型文件和glb文件,最后删除本地文件') |
|
# 生成glb文件 |
|
print(f'开始生成glb文件') |
|
os.system(f'gltfpack -c -i {os.path.join(workdir, pid, pid + ".obj")} -o {os.path.join(workdir, pid, pid + ".glb")}') |
|
# 根据前缀获取文件列表 |
|
prefix = f'objs/print/{pid}/' |
|
filelist = oss2.ObjectIteratorV2(oss_client, prefix=prefix) |
|
for file in filelist: |
|
filename = file.key.split('/')[-1] |
|
if filename == '': continue |
|
print('正在删除:', file.key) |
|
oss_client.delete_object(file.key) |
|
|
|
print(f'开始上传{pid}的文件') |
|
oss_client.put_object_from_file(f'objs/print/{pid}/{pid}.obj', os.path.join(workdir, pid, f'{pid}.obj')) |
|
oss_client.put_object_from_file(f'objs/print/{pid}/{pid}.mtl', os.path.join(workdir, pid, f'{pid}.mtl')) |
|
oss_client.put_object_from_file(f'objs/print/{pid}/{pid}Tex1.jpg', os.path.join(workdir, pid, f'{pid}Tex1.jpg')) |
|
oss_client.put_object_from_file(f'glbs/print/{pid}.glb', os.path.join(workdir, pid, f'{pid}.glb')) |
|
|
|
print(f'删除本地文件') |
|
for file in os.listdir(os.path.join(workdir, pid)): |
|
os.remove(os.path.join(workdir, pid, file)) |
|
os.rmdir(os.path.join(workdir, pid)) |
|
|
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid}处理完成') |
|
|
|
str_pids = '、'.join(pids) |
|
print(f'模型重新生成已完成,可以下载打印了。共处理{len(pids)}个模型:{str_pids}') |
|
|
|
|
|
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) |
|
|
|
workdir = '/home/water/Downloads/objs/temp/' |
|
main() |