diff --git a/__pycache__/compute_print_net.cpython-312.pyc b/__pycache__/compute_print_net.cpython-312.pyc index 9c4e1e4..87fda83 100644 Binary files a/__pycache__/compute_print_net.cpython-312.pyc and b/__pycache__/compute_print_net.cpython-312.pyc differ diff --git a/__pycache__/config.cpython-312.pyc b/__pycache__/config.cpython-312.pyc index 57f1b28..a28892d 100644 Binary files a/__pycache__/config.cpython-312.pyc and b/__pycache__/config.cpython-312.pyc differ diff --git a/__pycache__/download_print.cpython-312.pyc b/__pycache__/download_print.cpython-312.pyc index 2c69d08..799fd11 100644 Binary files a/__pycache__/download_print.cpython-312.pyc and b/__pycache__/download_print.cpython-312.pyc differ diff --git a/__pycache__/general.cpython-312.pyc b/__pycache__/general.cpython-312.pyc index b1c9fb0..9acdc4c 100644 Binary files a/__pycache__/general.cpython-312.pyc and b/__pycache__/general.cpython-312.pyc differ diff --git a/__pycache__/point_cloud_layout.cpython-312.pyc b/__pycache__/point_cloud_layout.cpython-312.pyc index 35baa52..30523af 100644 Binary files a/__pycache__/point_cloud_layout.cpython-312.pyc and b/__pycache__/point_cloud_layout.cpython-312.pyc differ diff --git a/__pycache__/print_factory_type_setting_obj_run.cpython-312.pyc b/__pycache__/print_factory_type_setting_obj_run.cpython-312.pyc index 8aad927..9b069a8 100644 Binary files a/__pycache__/print_factory_type_setting_obj_run.cpython-312.pyc and b/__pycache__/print_factory_type_setting_obj_run.cpython-312.pyc differ diff --git a/__pycache__/test_load_json.cpython-312.pyc b/__pycache__/test_load_json.cpython-312.pyc index a143cc8..d14e8d7 100644 Binary files a/__pycache__/test_load_json.cpython-312.pyc and b/__pycache__/test_load_json.cpython-312.pyc differ diff --git a/compute_print_net.py b/compute_print_net.py index 712af42..f73bb49 100644 --- a/compute_print_net.py +++ b/compute_print_net.py @@ -487,14 +487,14 @@ def arrange_box_correctly(obj_transformed, voxel_size,total_matrix): pcd.points = o3d.utility.Vector3dVector(vertices) # 降采样与特征计算 - pcd_downsampled = down_sample(pcd, voxel_size) + # pcd_downsampled = down_sample(pcd, voxel_size) + # points = np.asarray(pcd_downsampled.points) + points = np.asarray(pcd.points) - points = np.asarray(pcd_downsampled.points) cov = np.cov(points.T) center = obj_transformed.get_center() - # 特征分解与方向约束(关键修改点) eigen_vals, eigen_vecs = np.linalg.eigh(cov) max_axis = eigen_vecs[:, np.argmax(eigen_vals)] @@ -730,7 +730,7 @@ class Platform: else: start_y = my + extend_dist_border_y_min final_y = self.depth - print("final_y2", model['name'], start_y, final_y, my, extend_dist_border_y_max, px) + # print("final_y2", model['name'], start_y, final_y, my, extend_dist_border_y_max, px) for y in range(start_y, final_y, +1): if self.can_place(px, y, z, model)==False: y -= 1 diff --git a/config.py b/config.py index 390eddc..997ab34 100644 --- a/config.py +++ b/config.py @@ -24,6 +24,7 @@ redis_config = { url_send_layout = 'https://mp.api.suwa3d.com/api/printTypeSettingOrder/printTypeSettingOrderSuccess' url_get_info_by_printIds = "https://mp.api.suwa3d.com/api/printOrder/getInfoByPrintIds?print_ids=" +url_get_oss_suffix_by_orderId = f"https://mp.api.suwa3d.com/api/order/getOssSuffixByOrderId?order_id=" # -------------------------- 结束:网络配置 ------------------------------- diff --git a/download_print.py b/download_print.py index c387513..aa28b94 100644 --- a/download_print.py +++ b/download_print.py @@ -16,6 +16,7 @@ import argparse from config import print_factory_type_dir from config import oss_config from config import print_data_dir +from config import url_get_oss_suffix_by_orderId from general import is_use_debug_oss from general import transform_save_o3d @@ -1291,19 +1292,13 @@ def read_pids_from_json(pid_file): return list_model_info, data def download_data_by_json(model_info, workdir, oss_client ): - ''' - 下载卡通化数据 - ''' + try: pid = model_info.pid model_height = model_info.model_height - # target_dir = f"{workdir}/{pid}_image" target_dir = f"{workdir}" - - # {"code":1000,"data":"base_cartoon/badge/101/3/init_obj","message":"success1"} - # https://mp.api.suwa3d.com/api/order/getOssSuffixByOrderId?order_id=879312 - url = f"https://mp.api.suwa3d.com/api/order/getOssSuffixByOrderId?order_id={model_info.order_id}" + url = f"{url_get_oss_suffix_by_orderId}{model_info.order_id}" res = requests.get(url) data = res.json()["data"] @@ -1334,7 +1329,6 @@ class BatchModelInfo: count: str def read_paths_from_batch(batch_id): - url = f"https://mp.api.suwa3d.com/api/printOrder/getInfoByPrintBatchId?batch_id={batch_id}" res = requests.get(url) diff --git a/download_print_out.py b/download_print_out.py index b9a29c6..03c0d1f 100644 --- a/download_print_out.py +++ b/download_print_out.py @@ -13,6 +13,8 @@ import requests import json import shutil +from config import url_get_oss_suffix_by_orderId + def download_transform_save_by_json(pid_file, workdir, oss_config): layout_data = download_datas_by_json(pid_file, workdir, oss_config) original_obj_pid_dir = workdir @@ -221,7 +223,7 @@ def download_data_by_json(model_info, workdir, oss_client ): model_height = model_info.model_height target_dir = f"{workdir}" - url = f"https://mp.api.suwa3d.com/api/order/getOssSuffixByOrderId?order_id={model_info.order_id}" + url = f"{url_get_oss_suffix_by_orderId}{model_info.order_id}" res = requests.get(url) data = res.json()["data"] diff --git a/general.py b/general.py index 027aed8..8be3749 100644 --- a/general.py +++ b/general.py @@ -258,7 +258,7 @@ def is_same_obj(obj_name1, obj_name2): pre_name1 = obj_name1.split("_x")[0] pre_name2 = obj_name2.split("_x")[0] - print(f"pre_name1={pre_name1}, pre_name2={pre_name2}") + # print(f"pre_name1={pre_name1}, pre_name2={pre_name2}") if (pre_name1==pre_name2): return True diff --git a/point_cloud_layout.py b/point_cloud_layout.py index 5194169..2b2934c 100644 --- a/point_cloud_layout.py +++ b/point_cloud_layout.py @@ -9,18 +9,12 @@ import open3d as o3d import numpy as np from plyfile import PlyData, PlyElement -from config import print_factory_type_dir - from general import mesh_tranform_to_pcd from general import need_upload_result from general import read_mesh -from compute_print_net import get_models_bbox from compute_print_net import arrange_models_on_platform -from compute_print_net import Platform -from compute_print_net import down_sample from compute_print_net import compute_bbox_all -from compute_print_net import compute_bbox_all_ext def make_bbox_for_print(base_original_obj_dir,dict_bad,dict_origin,is_downsample): """获取需要的盒子大小""" @@ -87,7 +81,6 @@ def get_pcd_by_matrix(dict_mesh_obj,dict_total_matrix,dict_ply_name): return dict_pcd_fix - def ply_print_layout_platform(dict_pcd_fix,dict_pcd_fix2,machine_size,dict_total_matrix,all_models): """根据排版结果移动点云到指定位置""" # placed_models,unplaced_models = get_models_box_size(dict_fix,machine_size) @@ -144,32 +137,6 @@ def ply_print_layout_platform(dict_pcd_fix,dict_pcd_fix2,machine_size,dict_total return placed_models -def get_models_bbox_net(dict_pcd_fix): - return get_models_bbox(dict_pcd_fix) - -""" -def get_models_box_size(dict_fix,machine_size): - #获取排版的盒子大小 - models = [] - for ply_file in dict_fix: - bbox_with_text = ply_file.split("=") - bbox_with = bbox_with_text[-1] - split_text = bbox_with.replace(".ply","").split("+") - extend_dist = 2 - x_length = int(float(split_text[2])*100) + extend_dist - y_length = int(float(split_text[0])*100) + extend_dist - z_length = int(float(split_text[1])*100) + extend_dist - #print("get_models_box_size",x_length,y_length,z_length) - models.append({'name':ply_file,'dimensions':(int(x_length/100),int(z_length/100),int(y_length/100))}) - print(models) - - platform = Platform(int(machine_size[0]), int(machine_size[1]), int(machine_size[2])) - print("开始计算排序...") - platform.arrange_models(models) - platform.print_results() - return platform.get_result() -""" - def compute_distance(pcd1, pcd2): """ 正确计算两个点云之间距离的函数。 @@ -187,44 +154,6 @@ def compute_distance(pcd1, pcd2): # return min_dist, mean_dist, distances return min_dist -def compute_distance_x(pcd1, pcd2): - points1 = np.asarray(pcd1.points)[:, 0] # 提取所有X坐标[3](@ref) - points2 = np.asarray(pcd2.points)[:, 0] - - x_diff = np.abs(points1[:, np.newaxis] - points2) - return np.min(x_diff) - -def compute_distance_y(pcd1, pcd2): - points1 = np.asarray(pcd1.points)[:, 1] # 提取所有Y坐标[3](@ref) - points2 = np.asarray(pcd2.points)[:, 1] - - y_diff = np.abs(points1.reshape(-1, 1) - points2) - return np.min(y_diff) - -def check_collision_x(pcd_moving, static_pcds,collision_threshold): - moving_points = np.asarray(pcd_moving.points) - min_distance_to_x_axis = np.min(np.abs(moving_points[:, 1])) # Y 坐标即为与 X 轴的距离 - #print(f"与 X 轴的最小距离: {min_distance_to_x_axis}") - #print(f"与 Y 轴的最小距离: {min_distance_to_y_axis}") - #print(f"pcd_moving{len(static_pcds)}") - if min_distance_to_x_axis < collision_threshold: - print(f"与 X 轴发生碰撞! 最小距离: {min_distance_to_x_axis}") - return True - - return check_collision_all(pcd_moving, static_pcds,collision_threshold) - -def check_collision_y(pcd_moving, static_pcds,collision_threshold): - moving_points = np.asarray(pcd_moving.points) - #print(f"与 X 轴的最小距离: {min_distance_to_x_axis}") - min_distance_to_y_axis = np.min(np.abs(moving_points[:, 0])) # X 坐标即为与 Y 轴的距离 - #print(f"与 Y 轴的最小距离: {min_distance_to_y_axis}") - #print(f"pcd_moving{len(static_pcds)}") - if min_distance_to_y_axis < collision_threshold: - print(f"与 Y 轴发生碰撞! 最小距离: {min_distance_to_y_axis}") - return True - - return check_collision_all(pcd_moving, static_pcds,collision_threshold) - import numpy as np def compute_aabb(pcd): @@ -349,9 +278,6 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma else: pcd_second.append(pcd) - # pcd_all.append(pcd_downsampled) - # name_list.append(model['name']) - # model_list.append(model) dict_name[pcd] = model['name'] dict_model[pcd] = model dx = model['dimensions'][0] @@ -374,7 +300,6 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma if max_delta_x < 10: draw_down = False - # for idx, pcd in enumerate(pcd_all): for idx, pcd in enumerate(pcd_first): if dict_model[pcd]['first_line']: @@ -1001,15 +926,6 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma #""" last_pcd_processed.append(pcd) - """ - print("is_x_top",is_x_top) - if not is_x_top: - last_pcd_processed.append(pcd) - print("last_pcd_processed.append",name) - else: - print("fail last_pcd_processed.append",name, is_x_top) - """ - # o3d.io.write_point_cloud(os.path.join(output_dir, name), pcd) dict_total_matrix[obj_name]= T_trans1 @ dict_total_matrix[obj_name] @@ -1029,19 +945,6 @@ def move_to_top_left(pcd, edge_x_min, edge_y_max): return T_transTemp -def move_to_bottom_left(pcd, edge_x_min, edge_y_min): - - points = np.asarray(pcd.points) - min_x = np.min(points[:, 0]) - min_y = np.min(points[:, 1]) - tx = edge_x_min - min_x - ty = edge_y_min - min_y - pcd.translate((tx, ty, 0), relative=True) - T_transTemp = np.eye(4) - T_transTemp[:3, 3] = [tx, ty, 0] - - return T_transTemp - def move_to_bottom_right(pcd, edge_x_max, edge_y_min): points = np.asarray(pcd.points) @@ -1066,229 +969,8 @@ def get_axis_aligned_bbox(pcd): 'z_max': np.max(points[:,2]) } -def down_obj_data_to_ply(weight_fix_out_obj_dir,weight_fix_out_ply_dir): - """""" - obj_file_list = [aa for aa in os.listdir(weight_fix_out_obj_dir) if aa.endswith(".obj")] - for obj_name in obj_file_list: - obj_path = os.path.join(weight_fix_out_obj_dir,obj_name) - - mesh_obj = read_mesh(obj_path) - - vertices = np.asarray(mesh_obj.vertices) - pcd = o3d.geometry.PointCloud() - pcd.points = o3d.utility.Vector3dVector(vertices) - voxel_size = 3 # 设置体素的大小,决定下采样的密度 - pcd_downsampled = down_sample(pcd, voxel_size) - ply_out_path = os.path.join(weight_fix_out_ply_dir,obj_name.replace(".obj",".ply")) - o3d.io.write_point_cloud(ply_out_path, pcd_downsampled) - print(ply_out_path,"下采样完成。") - -def compute_centroid_compact(pcd): - points = np.asarray(pcd.points) - centroid = np.mean(points, axis=0) - return centroid - -def compute_base_point(pcd): - points = np.asarray(pcd.points) - x_center = np.mean(points[:, 0]) - y_center = np.mean(points[:, 1]) - min_z = np.min(points[:, 2]) - return np.array([x_center, y_center, min_z]) - -import copy -def move_obj_to_compact_bounds(bounds_fix_out_dir,bounds_compact_out_dir,weight_fix_out_obj_dir,base_original_obj_dir,compact_obj_out_dir,dict_mesh_obj,dict_unplaced,placed_remove_dir,dict_bad,bad_dir,full_dir,dict_bounds_fix,dict_compact,dict_origin): - """""" - # obj_file_list = [aa for aa in os.listdir(weight_fix_out_obj_dir) if aa.endswith(".obj")] - obj_file_list = list(dict_mesh_obj.keys()) - ply_path_dict = {} - - # meshes = [] - # for ply_file_name in os.listdir(bounds_fix_out_dir): - for ply_file_name in dict_bounds_fix: - ply_dict_key = ply_file_name.split("=")[0] - ply_path_dict[ply_dict_key] = ply_file_name - for obj_name in obj_file_list: - obj_path = os.path.join(weight_fix_out_obj_dir, obj_name) - - # mesh_obj = read_mesh(obj_path, False) - mesh_obj = dict_mesh_obj[obj_name] - # mesh_obj = dict_origin[obj_origin_path] - - original_obj_pid_dir = base_original_obj_dir - obj_origin_path = os.path.join(original_obj_pid_dir, obj_name) - obj_origin = dict_origin[obj_origin_path] - # obj_origin = copy.deepcopy(dict_origin[obj_origin_path]) - - ply_name_pid = obj_name.replace(".obj","") - # ply_name = ply_path_dict[ply_name_pid] - ply_name = ply_path_dict.get(ply_name_pid,None) - print(ply_name_pid,ply_name) - if ply_name is None: - continue - print("move_obj_to_compact_bounds",ply_name,len(dict_unplaced)) - if not ply_name or ply_name in dict_unplaced: - print("unplaced",ply_name) - continue - ply_fix_path = os.path.join(bounds_fix_out_dir,ply_name) - ply_compact_path = os.path.join(bounds_compact_out_dir, ply_name) - # pcd_fix = o3d.io.read_point_cloud(ply_fix_path) - pcd_fix = dict_bounds_fix[ply_name] - - vertices = np.asarray(obj_origin.vertices) - pcd_origin = o3d.geometry.PointCloud() - pcd_origin.points = o3d.utility.Vector3dVector(vertices) - - # pcd_compact = o3d.io.read_point_cloud(ply_compact_path) - pcd_compact = dict_compact[ply_name] - - centroid_fix = compute_centroid_compact(pcd_fix) - centroid_compact = compute_centroid_compact(pcd_compact) - centroid_origin = compute_centroid_compact(pcd_origin) - displacement = centroid_compact - centroid_fix - # displacement = centroid_compact - centroid_origin - vertices = np.asarray(mesh_obj.vertices) - vertices_translated = vertices + displacement # 将位移应用到每个顶点 - mesh_obj.vertices = o3d.utility.Vector3dVector(vertices_translated) # 更新网格顶点 - - obj_pid = obj_name.split("_P")[0] - #compact_obj_pid_out_dir = os.path.join(compact_obj_out_dir,obj_pid) - compact_obj_pid_out_dir= compact_obj_out_dir - if not os.path.exists(compact_obj_pid_out_dir): - os.makedirs(compact_obj_pid_out_dir) - obj_path_compact = os.path.join(compact_obj_pid_out_dir,obj_name) - mesh_obj.compute_vertex_normals() - o3d.io.write_triangle_mesh(obj_path_compact, mesh_obj,write_triangle_uvs=True) - print(obj_path_compact, "移动后obj保存完成", displacement) - - # meshes.append(mesh_obj) - - #original_obj_pid_dir = os.path.join(base_original_obj_dir,obj_pid) - original_obj_pid_dir = base_original_obj_dir - for mtl in os.listdir(compact_obj_pid_out_dir): - if mtl.endswith(".mtl"): - if obj_pid in mtl: - mtl_path = os.path.join(compact_obj_pid_out_dir,mtl) - os.remove(mtl_path) - - mtl_name = None - tex_name = None - for file_name in os.listdir(original_obj_pid_dir): - if file_name.endswith(".mtl"): - if obj_pid in file_name: - mtl_name = file_name - if file_name.endswith(".jpg"): - if obj_pid in file_name: - tex_name = file_name - if file_name.endswith(".png"): - if obj_pid in file_name: - tex_name = file_name - - for file in os.listdir(original_obj_pid_dir): - #print(f"file{file}") - if file.endswith(".obj"): - continue - if obj_pid not in file: - continue - - origin_path = os.path.join(original_obj_pid_dir,file) - dis_path = os.path.join(compact_obj_pid_out_dir,file) - - if os.path.isfile(origin_path): - #print(f'origin_path{origin_path}') - #print(f'dis_path{dis_path}') - shutil.copy(origin_path,dis_path) - time.sleep(1) - #print("-"*50) - base_origin_obj_path = os.path.join(original_obj_pid_dir,obj_name) - #print(f"base_origin_obj_path{base_origin_obj_path}") - #print(f"obj_path_compact{obj_path_compact}") - update_obj_file(base_origin_obj_path, obj_path_compact) - - placed_remove_obj_path = os.path.join(placed_remove_dir, obj_name) - shutil.copy(base_origin_obj_path,placed_remove_obj_path) - os.remove(base_origin_obj_path) - - exist_obj_any = False - exist_obj = False - delete_mtl = False - for file_name in os.listdir(original_obj_pid_dir): - if file_name.endswith(".obj"): - if obj_pid in file_name: - exist_obj = True - exist_obj_any = True - - if not exist_obj_any: - delete_mtl = True - if not exist_obj: - delete_mtl = True - - if delete_mtl: - print("delete_mtl",mtl_name,tex_name) - if mtl_name!=None: - base_origin_mtl_path = os.path.join(original_obj_pid_dir,mtl_name) - placed_remove_mtl_path = os.path.join(placed_remove_dir, mtl_name) - shutil.copy(base_origin_mtl_path,placed_remove_mtl_path) - os.remove(base_origin_mtl_path) - - if tex_name!=None: - base_origin_tex_path = os.path.join(original_obj_pid_dir,tex_name) - placed_remove_tex_path = os.path.join(placed_remove_dir, tex_name) - shutil.copy(base_origin_tex_path,placed_remove_tex_path) - os.remove(base_origin_tex_path) - - print(f"排版错误模型数量::{len(dict_bad)}") - for obj_name in dict_bad: - print("--错误模型名:", obj_name) - process_obj_files(original_obj_pid_dir,bad_dir,obj_name) - - print(f"排版剩余模型数量::{len(dict_unplaced)}") - for ply_file_name in dict_unplaced: - obj_name = ply_file_name.split("=")[0]+".obj" - print("--剩余模型名:", obj_name) - process_obj_files(original_obj_pid_dir,full_dir,obj_name) - import json -def extract_angles(R): - # 提取绕X、Y、Z轴的旋转角度(弧度) - rx_rad = np.arctan2(R[2, 1], R[2, 2]) # X轴旋转 - ry_rad = np.arcsin(-R[2, 0]) # Y轴旋转 - rz_rad = np.arctan2(R[1, 0], R[0, 0]) # Z轴旋转 - - # 将弧度转换为角度(度数) - rx_deg = np.degrees(rx_rad) - ry_deg = np.degrees(ry_rad) - rz_deg = np.degrees(rz_rad) - - return rx_deg, ry_deg, rz_deg - -def compute_mesh_center(vertices): - """ - 计算网格质心 - - 参数: - vertices: 顶点坐标数组,形状为(N, 3)的NumPy数组或列表 - - 返回: - centroid: 质心坐标的NumPy数组 [x, y, z] - """ - if len(vertices) == 0: - raise ValueError("顶点数组不能为空") - - n = len(vertices) # 顶点数量 - # 初始化坐标累加器 - sum_x, sum_y, sum_z = 0.0, 0.0, 0.0 - - # 遍历所有顶点累加坐标值 - for vertex in vertices: - sum_x += vertex[0] - sum_y += vertex[1] - sum_z += vertex[2] - - # 计算各坐标轴的平均值 - centroid = np.array([sum_x / n, sum_y / n, sum_z / n]) - return centroid - import re def extract_numbers_from_filename(filename): """ @@ -1313,7 +995,7 @@ def extract_numbers_from_filename(filename): import requests def move_obj_to_compact_bounds_json(base_original_obj_dir,dict_mesh_obj,dict_unplaced,dict_bad,bad_dir,full_dir,dict_bounds_fix, - dict_total_matrix,save_mesh,batch_id, print_start_time,selected_machine,selected_mode,version): + dict_total_matrix,batch_id, print_start_time,selected_machine,selected_mode,version): """生成3D打印布局的JSON数据并保存为3DPrintLayout.json""" # 创建符合3DPrintLayout规范的JSON数据结构 layout_data = { @@ -1429,10 +1111,6 @@ def move_obj_to_compact_bounds_json(base_original_obj_dir,dict_mesh_obj,dict_unp print("--剩余模型名:", obj_name) process_obj_files(original_obj_pid_dir,full_dir,obj_name) - if save_mesh: - cache_type_setting_dir=f"{base_original_obj_dir}/arrange" - transform_save_o3d(layout_data, original_obj_pid_dir, cache_type_setting_dir) - return send_layout_data def process_obj_files(original_obj_pid_dir,placed_remove_dir,obj_name): @@ -1494,31 +1172,6 @@ def process_obj_files(original_obj_pid_dir,placed_remove_dir,obj_name): shutil.copy(base_origin_tex_path, placed_remove_tex_path) os.remove(base_origin_tex_path) -def update_obj_file(original_obj_path,compact_obj_path): - """""" - with open(original_obj_path, "r") as f: - lines_original = f.readlines() - mtllib_name = None - mat_name = None - for line in lines_original: - if line.startswith("mtllib"): - mtllib_name = line.split(" ")[1] - elif line.startswith("usemtl"): - mat_name = line.split(" ")[1] - if mtllib_name and mat_name: - break - with open(compact_obj_path, "r") as f: - lines = f.readlines() - new_lines = [] - for line2 in lines: - if line2.startswith("mtllib"): - line2 = f"mtllib {mtllib_name}\n" # 替换为原始 MTL 文件路径 - elif line2.startswith("usemtl"): - line2 = f"usemtl {mat_name}\n" # 替换为原始贴图路径 - new_lines.append(line2) - with open(compact_obj_path, "w") as f: - f.writelines(new_lines) - def pass_for_min_dis(placed_models, dict_unplaced, dict_bounds_fix): pcd_all = [] @@ -1546,23 +1199,3 @@ def pass_for_min_dis(placed_models, dict_unplaced, dict_bounds_fix): name = name_list[idx] print("fail to place (x=0)", name_list[idx], y, dy) dict_unplaced[name]=name - -if __name__ == '__main__': - out_dir = "/data/datasets_20t/type_setting_test_data/" - weight_fix_out_obj_dir = f"{out_dir}/print_weight_fix_data_obj" - weight_fix_out_ply_dir = f"{out_dir}/data/datasets_20t/type_ssetting_test_data/print_weight_fix_data_ply" - - base_original_obj_dir=f"{print_factory_type_dir}/8/" - if not os.path.exists(weight_fix_out_ply_dir): - os.makedirs(weight_fix_out_ply_dir) - bounds_fix_out_dir = f"{out_dir}/print_bounds_fix_data" - bounds_compact_out_dir = f"{out_dir}/print_bounds_compact_data" - compact_obj_out_dir = f"{out_dir}//print_compact_obj" - if not os.path.exists(bounds_fix_out_dir): - os.mkdir(bounds_fix_out_dir) - if not os.path.exists(bounds_compact_out_dir): - os.makedirs(bounds_compact_out_dir) - if not os.path.exists(compact_obj_out_dir): - os.makedirs(compact_obj_out_dir) - - move_obj_to_compact_bounds(bounds_fix_out_dir,bounds_compact_out_dir,weight_fix_out_obj_dir,base_original_obj_dir,compact_obj_out_dir) \ No newline at end of file diff --git a/print_factory_type_setting_obj_run.py b/print_factory_type_setting_obj_run.py index 7333707..77b244e 100644 --- a/print_factory_type_setting_obj_run.py +++ b/print_factory_type_setting_obj_run.py @@ -13,6 +13,7 @@ from test_load_json import load_show_save from download_print import upload_result from config import print_factory_type_dir +from config import print_data_dir from config import url_send_layout from config import big_machine_size from config import small_machine_size @@ -101,12 +102,11 @@ def print_type_setting_obj(base_original_obj_dir=None,batch_id=0,selected_mode=" os.makedirs(full_dir) is_small_machine = True if selected_machine=="小机型" else False - save_mesh = True if output_format=="模型" else False version = "print_type_setting25.local" send_layout_data = move_obj_to_compact_bounds_json(base_original_obj_dir,dict_mesh_obj,dict_unplaced,dict_bad,bad_dir,full_dir,dict_pcd_fix, - dict_total_matrix,save_mesh,batch_id,print_start_time,selected_machine,selected_mode,version) + dict_total_matrix,batch_id,print_start_time,selected_machine,selected_mode,version) end_time4 = time.time() print("排版完成") @@ -151,7 +151,6 @@ def print_type_setting_obj(base_original_obj_dir=None,batch_id=0,selected_mode=" print(f"need_upload_result={need_upload_result()}") if need_upload_result(): print(f"send_layout_data={send_layout_data}") - # url = 'https://mp.api.suwa3d.com/api/printTypeSettingOrder/printTypeSettingOrderSuccess' url = url_send_layout try: response = requests.post(url, json.dumps(send_layout_data), timeout=30) @@ -180,35 +179,19 @@ def print_type_setting_obj(base_original_obj_dir=None,batch_id=0,selected_mode=" return 0 -def preview(base_original_obj_dir=None, batch_id=0): - - load_show_save(base_original_obj_dir, {}, batch_id, True) - -def get_pcd(obj, is_down_sample=True): - vertices = np.asarray(obj.vertices) - pcd = o3d.geometry.PointCloud() - pcd.points = o3d.utility.Vector3dVector(vertices) - - if is_down_sample: - voxel_size = 3 - pcd_downsampled = down_sample(pcd, voxel_size, False) - return pcd_downsampled - else: - return pcd - if __name__ == '__main__': # parser = argparse.ArgumentParser() # parser.add_argument("--batch_id", type=str, required=True, help="batch_id") # args = parser.parse_args() # batch_id = args.batch_id - batch_id = "9910032" + batch_id = "1" src_dir = batch_id selected_mode="紧凑" # 标准 紧凑 output_format="JSON" # 模型 JSON selected_machine = "大机型" # 小机型 大机型 - base_original_obj_dir = f"{print_factory_type_dir}/{src_dir}" + base_original_obj_dir = f"{print_data_dir}/{src_dir}" print_type_setting_obj(base_original_obj_dir=base_original_obj_dir, batch_id=batch_id,selected_mode=selected_mode,output_format=output_format,selected_machine=selected_machine) diff --git a/test_load_json.py b/test_load_json.py index 1224fc5..b7768dc 100644 --- a/test_load_json.py +++ b/test_load_json.py @@ -357,7 +357,7 @@ def set_orthographic(meshes, width=1920, height=1080, del mesh del points gc.collect() - print(f"set_orthographic {index}") + # print(f"set_orthographic {index}") index = index + 1 del meshes @@ -406,7 +406,6 @@ def set_orthographic(meshes, width=1920, height=1080, view_control.set_up([0, 1, 0]) ortho_width = ortho_width or 10.0 - print("set_orthographic 1") #for _ in range(2): # vis.poll_events() # vis.update_renderer() @@ -414,10 +413,8 @@ def set_orthographic(meshes, width=1920, height=1080, # 设置正交投影 try: set_orthographic_camera(view_control) - print("set_orthographic 2") except AttributeError: set_orthographic_projection(view_control, ortho_scale=15.0) - print("set_orthographic 3") #for _ in range(5): # vis.poll_events()