dongchangxi 7 months ago
parent
commit
39c00b4386
  1. 4
      apps/auto_convert3d_new.py
  2. 1
      timer/external_order_glb.py
  3. 47
      timer/external_order_glbV2.py
  4. 41
      timer/test.py

4
apps/auto_convert3d_new.py

@ -141,9 +141,9 @@ def team_check(r): @@ -141,9 +141,9 @@ def team_check(r):
#处理封面图
#执行获取obj缩略图
print("执行获取obj全身缩略图脚本")
print("执行获取obj全身缩略图脚本1111111111")
os.system(f'python d:\\make2\\tools\pic_for_obj\image_rander_small.py -pid {pid} -i D://print/{pid} -o D://print/{pid}')
print("判断是否存在封面图")
#判断文件是否存在,存在则上传到oss, 更新数据库内容
if os.path.exists(f'D://print/{pid}/{pid}_pic.png'):
#获取拍照订单的信息,从中得到拍照订单的信息

1
timer/external_order_glb.py

@ -250,6 +250,7 @@ def create_redis_connection(): @@ -250,6 +250,7 @@ def create_redis_connection():
time.sleep(5)
if __name__ == '__main__':
arrArgs = sys.argv
if len(arrArgs) == 2:
pid = arrArgs[1]

47
timer/external_order_glbV2.py

@ -39,7 +39,9 @@ def bmesh_copy_from_object(obj, transform=True, triangulate=True, apply_modifier @@ -39,7 +39,9 @@ def bmesh_copy_from_object(obj, transform=True, triangulate=True, apply_modifier
return bm
def find_pid_objname(pid):
print(bpy.data.objects)
for obj in bpy.data.objects:
print(obj)
if obj.name.startswith(str(pid)):
return obj.name
@ -118,25 +120,20 @@ def get_p3d_info(pid): @@ -118,25 +120,20 @@ def get_p3d_info(pid):
res = requests.get(url)
res = res.json()
if res["code"] == 1000:
#https://www.suwa3d.com/external_order_cover/2025/01/09/1x4pzvxolk6d6xflb8p8r779e0oo2myn.png
imagePath = res["data"]["texture_cover_img"]
#字符串替换
imagePath = imagePath.replace("https://www.suwa3d.com/","")
imagePath = imagePath.replace(".jpg",".png")
return imagePath
return res["data"]["guid"]
else:
return 0
def base_fix(pid,order_ids):
# 统一blender环境
print("BBBBBBBBBBBBB")
reload_obj(pid,order_ids)
# 统一模型方向、位置、大小...
pid_objname = find_pid_objname(pid)
obj = bpy.data.objects[pid_objname]
bpy.data.objects[pid_objname].rotation_euler = (0, 0, 0)
print("AAAAAAAAAAAAA",pid_objname)
obj = bpy.context.selected_objects[0] #bpy.data.objects[pid_objname]
obj.rotation_euler = (0, 0, 0)
# 检查当前模型是否正确使用 z 轴作为高度轴
if obj.dimensions.z < obj.dimensions.y:
# 如果 z 轴比 y 轴小,说明高度错误,应该旋转调整模型
@ -160,7 +157,7 @@ def export_and_update_glbs(pid,order_ids): @@ -160,7 +157,7 @@ def export_and_update_glbs(pid,order_ids):
#headcount = libs.getHeadCount(pid)
headcount = 1
pid_objname = find_pid_objname(pid)
obj = bpy.data.objects[pid_objname]
obj = bpy.context.selected_objects[0]
obj.select_set(True)
model_info = {}
@ -171,8 +168,8 @@ def export_and_update_glbs(pid,order_ids): @@ -171,8 +168,8 @@ def export_and_update_glbs(pid,order_ids):
# bpy.ops.wm.save_as_mainfile(filepath=os.path.join(config.workdir, pid, f'{pid}.blend'))
# 统一缩放到9cm标准尺寸
scale = 90 / bpy.data.objects[pid_objname].dimensions.y
bpy.data.objects[pid_objname].scale = (scale, scale, scale)
scale = 90 / obj.dimensions.y
obj.scale = (scale, scale, scale)
bpy.ops.object.transform_apply(scale=True)
# bpy.ops.wm.save_as_mainfile(filepath=os.path.join(config.workdir, pid, f'{pid}-9cm.blend'))
@ -191,7 +188,7 @@ def export_and_update_glbs(pid,order_ids): @@ -191,7 +188,7 @@ def export_and_update_glbs(pid,order_ids):
# 先生成审核模型
faces_dest = 500000 * headcount
# 减面
faces_current = len(bpy.data.objects[pid_objname].data.polygons)
faces_current = len(obj.data.polygons)
print(f'当前面数:{faces_current},目标面数:{faces_dest}')
bpy.ops.object.modifier_add(type='DECIMATE')
@ -208,7 +205,7 @@ def export_and_update_glbs(pid,order_ids): @@ -208,7 +205,7 @@ def export_and_update_glbs(pid,order_ids):
faces_dest = 120000 * headcount
# 减面
faces_current = len(bpy.data.objects[pid_objname].data.polygons)
faces_current = len(obj.data.polygons)
print(f'当前面数:{faces_current},目标面数:{faces_dest}')
bpy.ops.object.modifier_add(type='DECIMATE')
@ -231,8 +228,23 @@ def export_and_update_glbs(pid,order_ids): @@ -231,8 +228,23 @@ def export_and_update_glbs(pid,order_ids):
#更新该笔订单的状态为 3000
# order_ids 逗号隔开
print(order_ids)
order_ids = ",".join(order_ids)
requests.post("https://shop.api.suwa3d.com/api/printOrder/updateExternalOrderStatusV2", data={'pid': pid,"order_ids":order_ids})
order_ids = ",".join(map(str,order_ids))
strRequest = f"https://shop.api.suwa3d.com/api/printOrder/updateExternalOrderStatusV2?pid={pid}&order_ids={order_ids}"
print(strRequest)
res = requests.post("https://shop.api.suwa3d.com/api/printOrder/updateExternalOrderStatusV2", data={'pid': pid,"order_ids":order_ids})
print(res.text)
#执行获取obj缩略图
print("执行获取obj全身缩略图脚本")
os.system(f'python d:\\make2\\tools\pic_for_obj\image_rander_small.py -pid {pid} -i D://print/{pid} -o D://print/{pid}')
print("判断获取封面图是否存在0")
#判断文件是否存在,存在则上传到oss, 更新数据库内容
if os.path.exists(f'D://print/{pid}/{pid}_pic.png'):
#获取拍照订单的信息,从中得到拍照订单的信息
uuid = get_p3d_info(str(pid))
print("判断获取封面图是否存在1")
if uuid != 0 and uuid != None and uuid != "":
print("uuid",uuid)
config.oss_bucket_3d_view.put_object_from_file(f'{uuid}/3d_view.png', f'D://print/{pid}/{pid}_pic.png')
def createGlb(pid,order_ids):
@ -284,6 +296,7 @@ if __name__ == '__main__': @@ -284,6 +296,7 @@ if __name__ == '__main__':
info = json.loads(info)
print(info)
pid = info['pid']
order_ids = info['order_id']

41
timer/test.py

@ -8,27 +8,28 @@ info = json.loads('{"order_id":[858344,858345],"pid":271916}') @@ -8,27 +8,28 @@ info = json.loads('{"order_id":[858344,858345],"pid":271916}')
#获取 order_id 列表
order_id_list = info['order_id']
#获取 pid
pid = info['pid']
# pid = info['pid']
print(order_id_list)
print(",".join(order_id_list))
# print(pid)
# 获取订单信息
for order_id in order_id_list:
print(order_id)
#url 请求
url = f"https://mp.api.suwa3d.com/api/printOrder/infoByOrderId?id={order_id}"
response = requests.get(url)
response = response.json()
if response['code'] != 1000:
continue
# for order_id in order_id_list:
# print(order_id)
# #url 请求
# url = f"https://mp.api.suwa3d.com/api/printOrder/infoByOrderId?id={order_id}"
# response = requests.get(url)
# response = response.json()
# if response['code'] != 1000:
# continue
#获取打印尺寸
printdata = response['data']['data']
for key,value in printdata.items():
#去掉cm
key = key.replace('cm','')
key = float(key)*10
print(key)
print(f'执行脚本--- "python D:/make2/tools/cal_weight.py print {pid} {key} {order_id}"')
#发起计算请求
os.system(f"python D:/make2/tools/cal_weight.py print {pid} {key} {order_id}")
# #获取打印尺寸
# printdata = response['data']['data']
# for key,value in printdata.items():
# #去掉cm
# key = key.replace('cm','')
# key = float(key)*10
# print(key)
# print(f'执行脚本--- "python D:/make2/tools/cal_weight.py print {pid} {key} {order_id}"')
# #发起计算请求
# os.system(f"python D:/make2/tools/cal_weight.py print {pid} {key} {order_id}")

Loading…
Cancel
Save