|
|
|
@ -39,7 +39,9 @@ def bmesh_copy_from_object(obj, transform=True, triangulate=True, apply_modifier |
|
|
|
return bm |
|
|
|
return bm |
|
|
|
|
|
|
|
|
|
|
|
def find_pid_objname(pid): |
|
|
|
def find_pid_objname(pid): |
|
|
|
|
|
|
|
print(bpy.data.objects) |
|
|
|
for obj in bpy.data.objects: |
|
|
|
for obj in bpy.data.objects: |
|
|
|
|
|
|
|
print(obj) |
|
|
|
if obj.name.startswith(str(pid)): |
|
|
|
if obj.name.startswith(str(pid)): |
|
|
|
return obj.name |
|
|
|
return obj.name |
|
|
|
|
|
|
|
|
|
|
|
@ -118,25 +120,20 @@ def get_p3d_info(pid): |
|
|
|
res = requests.get(url) |
|
|
|
res = requests.get(url) |
|
|
|
res = res.json() |
|
|
|
res = res.json() |
|
|
|
if res["code"] == 1000: |
|
|
|
if res["code"] == 1000: |
|
|
|
|
|
|
|
return res["data"]["guid"] |
|
|
|
#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 |
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
return 0 |
|
|
|
return 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def base_fix(pid,order_ids): |
|
|
|
def base_fix(pid,order_ids): |
|
|
|
# 统一blender环境 |
|
|
|
# 统一blender环境 |
|
|
|
|
|
|
|
print("BBBBBBBBBBBBB") |
|
|
|
reload_obj(pid,order_ids) |
|
|
|
reload_obj(pid,order_ids) |
|
|
|
# 统一模型方向、位置、大小... |
|
|
|
# 统一模型方向、位置、大小... |
|
|
|
pid_objname = find_pid_objname(pid) |
|
|
|
pid_objname = find_pid_objname(pid) |
|
|
|
obj = bpy.data.objects[pid_objname] |
|
|
|
print("AAAAAAAAAAAAA",pid_objname) |
|
|
|
bpy.data.objects[pid_objname].rotation_euler = (0, 0, 0) |
|
|
|
obj = bpy.context.selected_objects[0] #bpy.data.objects[pid_objname] |
|
|
|
|
|
|
|
obj.rotation_euler = (0, 0, 0) |
|
|
|
# 检查当前模型是否正确使用 z 轴作为高度轴 |
|
|
|
# 检查当前模型是否正确使用 z 轴作为高度轴 |
|
|
|
if obj.dimensions.z < obj.dimensions.y: |
|
|
|
if obj.dimensions.z < obj.dimensions.y: |
|
|
|
# 如果 z 轴比 y 轴小,说明高度错误,应该旋转调整模型 |
|
|
|
# 如果 z 轴比 y 轴小,说明高度错误,应该旋转调整模型 |
|
|
|
@ -160,7 +157,7 @@ def export_and_update_glbs(pid,order_ids): |
|
|
|
#headcount = libs.getHeadCount(pid) |
|
|
|
#headcount = libs.getHeadCount(pid) |
|
|
|
headcount = 1 |
|
|
|
headcount = 1 |
|
|
|
pid_objname = find_pid_objname(pid) |
|
|
|
pid_objname = find_pid_objname(pid) |
|
|
|
obj = bpy.data.objects[pid_objname] |
|
|
|
obj = bpy.context.selected_objects[0] |
|
|
|
obj.select_set(True) |
|
|
|
obj.select_set(True) |
|
|
|
|
|
|
|
|
|
|
|
model_info = {} |
|
|
|
model_info = {} |
|
|
|
@ -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')) |
|
|
|
# bpy.ops.wm.save_as_mainfile(filepath=os.path.join(config.workdir, pid, f'{pid}.blend')) |
|
|
|
|
|
|
|
|
|
|
|
# 统一缩放到9cm标准尺寸 |
|
|
|
# 统一缩放到9cm标准尺寸 |
|
|
|
scale = 90 / bpy.data.objects[pid_objname].dimensions.y |
|
|
|
scale = 90 / obj.dimensions.y |
|
|
|
bpy.data.objects[pid_objname].scale = (scale, scale, scale) |
|
|
|
obj.scale = (scale, scale, scale) |
|
|
|
bpy.ops.object.transform_apply(scale=True) |
|
|
|
bpy.ops.object.transform_apply(scale=True) |
|
|
|
|
|
|
|
|
|
|
|
# bpy.ops.wm.save_as_mainfile(filepath=os.path.join(config.workdir, pid, f'{pid}-9cm.blend')) |
|
|
|
# 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): |
|
|
|
# 先生成审核模型 |
|
|
|
# 先生成审核模型 |
|
|
|
faces_dest = 500000 * headcount |
|
|
|
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}') |
|
|
|
print(f'当前面数:{faces_current},目标面数:{faces_dest}') |
|
|
|
|
|
|
|
|
|
|
|
bpy.ops.object.modifier_add(type='DECIMATE') |
|
|
|
bpy.ops.object.modifier_add(type='DECIMATE') |
|
|
|
@ -208,7 +205,7 @@ def export_and_update_glbs(pid,order_ids): |
|
|
|
faces_dest = 120000 * headcount |
|
|
|
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}') |
|
|
|
print(f'当前面数:{faces_current},目标面数:{faces_dest}') |
|
|
|
|
|
|
|
|
|
|
|
bpy.ops.object.modifier_add(type='DECIMATE') |
|
|
|
bpy.ops.object.modifier_add(type='DECIMATE') |
|
|
|
@ -231,8 +228,23 @@ def export_and_update_glbs(pid,order_ids): |
|
|
|
#更新该笔订单的状态为 3000 |
|
|
|
#更新该笔订单的状态为 3000 |
|
|
|
# order_ids 逗号隔开 |
|
|
|
# order_ids 逗号隔开 |
|
|
|
print(order_ids) |
|
|
|
print(order_ids) |
|
|
|
order_ids = ",".join(order_ids) |
|
|
|
order_ids = ",".join(map(str,order_ids)) |
|
|
|
requests.post("https://shop.api.suwa3d.com/api/printOrder/updateExternalOrderStatusV2", data={'pid': pid,"order_ids":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): |
|
|
|
def createGlb(pid,order_ids): |
|
|
|
|
|
|
|
|
|
|
|
@ -284,6 +296,7 @@ if __name__ == '__main__': |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info = json.loads(info) |
|
|
|
info = json.loads(info) |
|
|
|
|
|
|
|
print(info) |
|
|
|
pid = info['pid'] |
|
|
|
pid = info['pid'] |
|
|
|
order_ids = info['order_id'] |
|
|
|
order_ids = info['order_id'] |
|
|
|
|
|
|
|
|
|
|
|
|