import platform,sys,redis,time,requests,json,atexit sys.path.append('../libs/') import config,libs,libs_db_temp,common import os, sys, time, argparse, requests, json, re, oss2, probreg import bpy, bmesh import open3d as o3d import numpy as np import cupy as cp from mathutils import Matrix import math import logging import matplotlib.pyplot as plt #获取真实身高 def get_real_height(input_path): get_real_height_url = 'https://mp.api.suwa3d.com/api/physical/infoByPid' print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}: Getting real height from {input_path}') pid = re.findall(r'(\d+)', input_path)[0] print(f'pid: {pid}') res = requests.get(get_real_height_url, params={'pid': pid}) res = json.loads(res.text) if res['code'] == -1: print(f'Error: {res["message"]}, return default height 160') return 160 height = res['data']['height'] if height == 0: print(f'Error: height=0, return default height 160') return 160 print(f'height: {height}') return height def base_fix(input_path): if not os.path.exists(input_path): print(f'Error: {input_path} does not exist.') sys.exit(1) bpy.ops.wm.read_homefile() bpy.ops.object.delete(use_global=False, confirm=False) bpy.ops.wm.obj_import(filepath=input_path) bpy.context.scene.unit_settings.scale_length = 1 bpy.context.scene.unit_settings.length_unit = 'CENTIMETERS' bpy.context.scene.unit_settings.mass_unit = 'GRAMS' obj = bpy.context.selected_objects[0] bpy.context.view_layer.objects.active = obj obj.select_set(True) # 脚底贴地 bpy.ops.object.align(align_mode='OPT_1', relative_to='OPT_1', align_axis={'Z'}) bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) real_height = get_real_height(input_path) print(obj.dimensions) scale = real_height / obj.dimensions[2] / 100 # 除以100是因为单位是厘米 bpy.context.object.scale = (scale, scale, scale) bpy.context.object.rotation_euler = (0, 0, 0) bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_VOLUME', center='MEDIAN') bpy.context.object.location[0] = 0 # 移动到特定位置(1m, 1m)是为了让human3d可以正确识别 bpy.context.object.location[1] = 0 bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) # # bpy.ops.wm.save_mainfile(filepath=args.input_path.replace('.obj', '.blend')) output_file = input_path.replace('.obj', '_baseFixed.obj') bpy.ops.wm.obj_export(filepath=output_file) return obj def readTask(): # #读取数据库的任务 # pid = libs_db_temp.get_task_by_level() # pid = str(pid) # #下载pid的对应的oss端的文件 # tempName = libs.down_obj_from_oss_for_fix("E://obj_fix", pid, "print") # if tempName == "": # print("找不到对应的obj文件") # #记录状态为异常 -1 # libs_db_temp.update_fix_status(pid,-1) # return "" # #记录状态为处理中 # libs_db_temp.update_fix_status(pid,1) # #处理逻辑 # return pid pid=7013 base_fix(f'E://obj_fix/{pid}/{pid}.obj') # print(pid) # print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"-读取数据库任务") #程序主入口 if __name__ == '__main__': #atexit.register(common.notify,"处理数据校准任务已经停止") readTask() # while True: # print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"-开始执行任务") # pid = readTask() # if pid != "": # break