111
This commit is contained in:
1 parent
a84990f7d4
commit
4d1e9dff58
4 files changed
+83
-10
No files matched your search
+2
-2
@@ -71,7 +71,7 @@ def down_obj_fromoss(pid, print_type=1, order_id=None,download_flag="print_build
|
||||
find = True
|
||||
|
||||
if download_flag == "print_build":
|
||||
if filename != str(pid)+".obj" and filename != str(pid)+".mtl" and filename != str(pid)+"Tex1.jpg":
|
||||
if filename != str(pid)+".obj" and filename != str(pid)+".mtl" and filename != str(pid)+"Tex1.jpg" and filename != str(pid)+"_RB_B_Tex1.jpg":
|
||||
continue
|
||||
localfile = os.path.join(path, filename)
|
||||
res = oss_client.get_object_to_file(file.key, localfile)
|
||||
@@ -208,7 +208,7 @@ def make3d4print_task(orderId):
|
||||
else:
|
||||
os.system(f'python fix_nose.py {pid}_{orderId}')
|
||||
#上传jpg文件
|
||||
oss_client.put_object_from_file(f'objs/print/{pid}/{pid}Tex1.jpg', os.path.join(workdir, 'print', f'{pid}_{orderId}', f'{pid}Tex1.jpg'))
|
||||
#oss_client.put_object_from_file(f'objs/print/{pid}/{pid}Tex1.jpg', os.path.join(workdir, 'print', f'{pid}_{orderId}', f'{pid}Tex1.jpg'))
|
||||
# oss_client.put_object_from_file(f'objs/print/{pid}/{pid}Tex1_old.jpg', os.path.join(workdir, 'print', f'{pid}_{orderId}', f'{pid}Tex1_old.jpg'))
|
||||
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), f'orderId:{orderId} pid:{pid} 处理鼻孔 end')
|
||||
|
||||
|
||||
+11
-2
@@ -71,7 +71,7 @@ def down_obj_fromoss(pid, print_type=1, order_id=None,download_flag="print_build
|
||||
find = True
|
||||
|
||||
if download_flag == "print_build":
|
||||
if filename != str(pid)+".obj" and filename != str(pid)+".mtl" and filename != str(pid)+"Tex1.jpg":
|
||||
if filename != str(pid)+".obj" and filename != str(pid)+".mtl" and filename != str(pid)+"Tex1.jpg" and filename != str(pid)+"_RB_B_Tex1.jpg":
|
||||
continue
|
||||
localfile = os.path.join(path, filename)
|
||||
res = oss_client.get_object_to_file(file.key, localfile)
|
||||
@@ -205,6 +205,14 @@ def make3d4print_task(r):
|
||||
print("查询打印订单信息失败,重新开启进程")
|
||||
#os.system(f'python auto_convert3d.py')
|
||||
return
|
||||
|
||||
#根据 buy_type 判断 是否是冰箱贴 或者徽章
|
||||
buyType = str(res['buy_type'])
|
||||
if buyType == "2" or buyType == "3":
|
||||
#塞入到no_resize 队列
|
||||
r.lpush("model:noresize", orderId)
|
||||
return
|
||||
|
||||
pid = str(res['pid'])
|
||||
if pid == "88985":
|
||||
return
|
||||
@@ -235,7 +243,7 @@ def make3d4print_task(r):
|
||||
else:
|
||||
os.system(f'python fix_nose.py {pid}_{orderId}')
|
||||
#上传jpg文件
|
||||
oss_client.put_object_from_file(f'objs/print/{pid}/{pid}Tex1.jpg', os.path.join(workdir, 'print', f'{pid}_{orderId}', f'{pid}Tex1.jpg'))
|
||||
#oss_client.put_object_from_file(f'objs/print/{pid}/{pid}Tex1.jpg', os.path.join(workdir, 'print', f'{pid}_{orderId}', f'{pid}Tex1.jpg'))
|
||||
# oss_client.put_object_from_file(f'objs/print/{pid}/{pid}Tex1_old.jpg', os.path.join(workdir, 'print', f'{pid}_{orderId}', f'{pid}Tex1_old.jpg'))
|
||||
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), f'orderId:{orderId} pid:{pid} 处理鼻孔 end')
|
||||
|
||||
@@ -257,6 +265,7 @@ def make3d4print_task(r):
|
||||
if file in [f'{pid}.png',f'{pid}_old.jpg', f'{pid}.obj', f'{pid}_decimate.glb', f'{pid}_decimate.obj', f'{pid}_decimate.mtl', f'{pid}Tex1_decimate.jpg', f'{pid}_original.obj', f'{pid}_original.mtl']: continue
|
||||
print("当前目录",os.path.join(path, file))
|
||||
|
||||
print(f"复制文件路径-{file}")
|
||||
#将文件移动到指定目录
|
||||
if not os.path.exists(os.path.join(workdir, f'complate/objs/{pid}/')):
|
||||
os.makedirs(os.path.join(workdir, f'complate/objs/{pid}/'),mode=0o777, exist_ok=True)
|
||||
|
||||
+37
-2
@@ -144,8 +144,35 @@ def find_obj(pid, order_id):
|
||||
for filename in filelist:
|
||||
if f'{pid}.obj' in filename:
|
||||
find = True
|
||||
#进行图片分辨率的调整
|
||||
# get_printsize_url = 'https://mp.api.suwa3d.com/api/printOrder/info'
|
||||
# res = requests.get(f'{get_printsize_url}?id={order_id}')
|
||||
# print('获取订单信息:', res.text)
|
||||
# if res.status_code == 200:
|
||||
# headcount = res.json()['data']['headcount']
|
||||
# for f in res.json()['data']['fileList']:
|
||||
# if "undefined" in f:
|
||||
# continue
|
||||
# try:
|
||||
# height = float(f.split('_')[-2][:-2]) * 10
|
||||
# except Exception as e:
|
||||
# continue
|
||||
|
||||
# if headcount == 1 and height <= 80:
|
||||
# pixs = 4096
|
||||
# if height <= 5:
|
||||
# pixs = 1024
|
||||
# print(f"图片分辨率进行处理{pixs}")
|
||||
# imagePiex(os.path.join(workdir, f'{pid}_{order_id}', f'{pid}Tex1.jpg'),pixs)
|
||||
|
||||
return filename
|
||||
print('没有找到obj模型文件')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return ''
|
||||
|
||||
def find_pid_objname(pid):
|
||||
@@ -606,10 +633,18 @@ def main(workdir, r, print_id):
|
||||
print("workdirworkdir",workdir)
|
||||
shutil.rmtree(os.path.join(workdir, f'{pid}_{order_id}'))
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 运行{print_id}任务完成,继续运行下一个任务')
|
||||
|
||||
|
||||
# restart_current_process("blender -b -P fill_dm_code.py")
|
||||
|
||||
def imagePiex(filePath,piex):
|
||||
# 打开图片
|
||||
image = Image.open(filePath)
|
||||
# 设置新的最大宽度和高度
|
||||
max_size = (piex, piex)
|
||||
# 保持宽高比缩放图片
|
||||
image.thumbnail(max_size)
|
||||
# 保存调整后的图片
|
||||
image.save(filePath)
|
||||
|
||||
#根据print_id 获取 短网址
|
||||
def get_short_url(print_id):
|
||||
res = requests.get(f'{get_short_url_by_print_id}?print_id={print_id}')
|
||||
|
||||
+33
-4
@@ -76,6 +76,15 @@ def fix_link_texture(pid):
|
||||
|
||||
f.close()
|
||||
|
||||
def imagePiex(filePath,piex):
|
||||
# 打开图片
|
||||
image = Image.open(filePath)
|
||||
# 设置新的最大宽度和高度
|
||||
max_size = (piex, piex)
|
||||
# 保持宽高比缩放图片
|
||||
image.thumbnail(max_size)
|
||||
# 保存调整后的图片
|
||||
image.save(filePath)
|
||||
|
||||
def main():
|
||||
start = time.time()
|
||||
@@ -91,6 +100,7 @@ def main():
|
||||
pid = res.json()['data']['pid']
|
||||
path = os.path.join(workdir, 'print', f'{pid}_{orderId}')
|
||||
filename = os.path.join(path, f'{pid}.obj')
|
||||
imagePath = os.path.join(path, f'{pid}Tex1.jpg')
|
||||
bpy.ops.object.delete(use_global=False, confirm=False)
|
||||
bpy.context.scene.unit_settings.scale_length = 0.001
|
||||
bpy.context.scene.unit_settings.length_unit = 'CENTIMETERS'
|
||||
@@ -104,7 +114,7 @@ def main():
|
||||
print('应用后模型尺寸:', obj.dimensions)
|
||||
shutil.copy(filename, os.path.join(path, f'{pid}_original.obj'))
|
||||
filename_original = os.path.join(path, f'{pid}_original.obj')
|
||||
|
||||
headcount = res.json()['data']['headcount']
|
||||
for f in res.json()['data']['fileList']:
|
||||
|
||||
if "undefined" in f:
|
||||
@@ -117,20 +127,39 @@ def main():
|
||||
bpy.ops.wm.quit_blender()
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
||||
obj = bpy.context.selected_objects[0]
|
||||
bpy.context.view_layer.objects.active = obj
|
||||
print(f'{f}处理前{height}mm模型尺寸: {obj.dimensions}')
|
||||
scale = height / obj.dimensions.z
|
||||
obj.scale = (scale, scale, scale)
|
||||
bpy.ops.object.transform_apply(scale=True)
|
||||
print(f'{f}处理后{height}mm模型尺寸: {obj.dimensions}')
|
||||
|
||||
|
||||
if headcount == 1 and height <= 80:
|
||||
pixs = 4096
|
||||
faces_dest = 125000
|
||||
if height <= 50:
|
||||
pixs = 2048
|
||||
faces_dest = 63000
|
||||
print(f'减面到{faces_dest}')
|
||||
faces_dest = faces_dest * headcount
|
||||
# 减面
|
||||
faces_current = len(obj.data.polygons)
|
||||
bpy.ops.object.modifier_add(type='DECIMATE')
|
||||
bpy.context.object.modifiers["Decimate"].ratio = faces_dest / faces_current
|
||||
bpy.ops.object.modifier_apply(modifier="Decimate")
|
||||
# imagePiex(imagePath,pixs)
|
||||
|
||||
bpy.ops.export_scene.obj(filepath=os.path.join(path, f'{pid}.obj'))
|
||||
if os.path.exists(os.path.join(path, f)):
|
||||
os.remove(os.path.join(path, f))
|
||||
os.rename(os.path.join(path, f'{pid}.obj'), os.path.join(path, f))
|
||||
config.oss_bucket.put_object_from_file(f'objs/print/{pid}/{f}', os.path.join(path, f))
|
||||
|
||||
|
||||
|
||||
# 重新加载模型,然后生成数字模型
|
||||
bpy.ops.object.delete(use_global=False, confirm=False)
|
||||
fix_link_texture(pid)
|
||||
@@ -148,7 +177,7 @@ def main():
|
||||
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
|
||||
# if str(pid) == '120745': bpy.ops.wm.save_as_mainfile(filepath=os.path.join(path, f'{pid}_{orderId}.blend'))
|
||||
|
||||
headcount = res.json()['data']['headcount']
|
||||
|
||||
|
||||
bm = bmesh_copy_from_object(obj)
|
||||
obj_volume = round(bm.calc_volume() / 1000, 3)
|
||||
|
||||
Reference in new issue
Block a user