dongchangxi 9 months ago
parent
commit
b279fdac97
  1. 59
      tools/cal_weight.py

59
tools/cal_weight.py

@ -1,5 +1,5 @@
import os, sys, time, bpy, bmesh, shutil,requests,json import os, sys, time, bpy, bmesh, shutil,requests,json
import platform import platform,oss2
if platform.system() == 'Windows': if platform.system() == 'Windows':
sys.path.append('e:\\libs\\') sys.path.append('e:\\libs\\')
else: else:
@ -66,8 +66,63 @@ def cal_weight(obj, size):
print(f'{size/10}cm:体积 {model_info["volume"]}cm³, 克重 {model_info["weight"]}g') print(f'{size/10}cm:体积 {model_info["volume"]}cm³, 克重 {model_info["weight"]}g')
return model_info["weight"] return model_info["weight"]
def down_obj_from_oss(workdir, pid, action):
if os.path.exists(os.path.join(workdir, action, pid)):
print(f'目录{os.path.join(workdir, action, pid)}已存在,跳过')
return
else:
os.makedirs(os.path.join(workdir, action, pid))
# 根据前缀获取文件列表
prefix = f'objs/{action}/{pid}/'
filelist = oss2.ObjectIteratorV2(config.oss_bucket, prefix=prefix)
print('正在下载:', prefix)
obj_filename = ""
dirPath = os.path.join(workdir, action, pid)
for file in filelist:
filename = file.key.split('/')[-1]
if filename.endswith('.obj'):
obj_filename = filename
# print('正在下载:', file.key)
localfile = os.path.join(workdir, action, pid, filename)
#判断目录里是否已经存在obj文件了
isObjFile = False
isJpgFile = False
isMtlFile = False
for file in os.listdir(dirPath):
if file.endswith('.obj'):
isObjFile = True
if file.endswith('.jpg'):
isJpgFile = True
if file.endswith('.mtl'):
isMtlFile = True
if localfile.endswith('.obj'):
if isObjFile and os.path.exists(localfile):
print(f'目录{dirPath}已存在obj文件,跳过')
continue
if localfile.endswith('.jpg'):
if isJpgFile and os.path.exists(localfile):
print(f'目录{dirPath}已存在jpg文件,跳过')
continue
if localfile.endswith('.mtl'):
if isMtlFile and os.path.exists(localfile):
print(f'目录{dirPath}已存在mtl文件,跳过')
continue
config.oss_bucket.get_object_to_file(file.key, localfile)
return obj_filename
def main(action, pid, sizes,orderId=0): def main(action, pid, sizes,orderId=0):
libs.down_obj_from_oss(config.workdir, pid, action) down_obj_from_oss(config.workdir, pid, action)
obj = reload_obj(pid, action) obj = reload_obj(pid, action)
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)

Loading…
Cancel
Save