import platform,sys,redis,time,requests,json,atexit import os, sys, time, argparse, requests, json, re, oss2 import bpy import open3d as o3d import shutil import psutil #生成预览图 def create_preview(obj_file_path,image_save_path,pid): start_time = time.time() print(f"{pid}-开始生成预览图-开始时间-{start_time}") # 加载 OBJ 文件 mesh = o3d.io.read_triangle_mesh(obj_file_path,enable_post_processing=True) mesh.compute_vertex_normals() # 创建视觉化窗口 # o3d.visualization.MeshColorOption = o3d.visualization.MeshColorOption.Default vis = o3d.visualization.Visualizer() # render = o3d.visualization.RenderOption() width = 50 height = 100 vis.create_window(width=width, height=height,visible=False) # 添加几何体到视觉化窗口 vis.add_geometry(mesh) vis.get_render_option().light_on = True # vis.get_render_option().mesh_color_option = o3d.visualization.MeshColorOption.Default vis.get_render_option().mesh_shade_option = o3d.visualization.MeshShadeOption.Default # render.background_color = [123,251,89] # 将光照强度设置为0.5或更低 # vis.get_render_option().ambient_intensity = 0.9 # 设置环境光强度 # vis.get_render_option().directional_light = False # 关闭定向光 # vis.get_render_option().line_width = 2.0 # 更新渲染器并捕获屏幕图像 vis.update_renderer() vis.poll_events() vis.capture_screen_image(image_save_path) # 关闭窗口 vis.destroy_window() print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}: {pid} Run time: ', time.time() - start_time) time.sleep(2) # 检测图片是否存在 if not os.path.exists(image_save_path): print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}: {pid} Error: {image_save_path} does not exist.') return False # #判断文件夹是否存在 # if not os.path.exists(f"{filePath}/preview/"): # os.makedirs(f"{filePath}/preview/") # #图片存在则复制到指定的文件夹中 # shutil.copy(image_save_path, f"{filePath}/preview/") return True # 定义函数来递归遍历文件夹下的所有文件 def list_files(directory): for root, dirs, files in os.walk(directory): for file in files: yield os.path.join(root, file) #生成预览图 target_folder = 'G://obj_fix/print/' source_folder = 'G://obj_fix/print/preview' #遍历文件夹下的所有文件 nums = 0 for file_path in list_files(target_folder): if ".obj" not in file_path: continue print("文件路径:",file_path) #判断文件是否存在 if not os.path.exists(file_path): continue print(file_path) arrData = file_path.split('/') pid = arrData[len(arrData)-2] #判断封面图片是否存在 # if os.path.exists(f'{target_folder}/{pid}_preview.png'): # print(f'{pid}_preview.png 已存在,跳过循环!!!') # continue nums += 1 print(f"正在处理{pid}","--剩余--",1530 - nums) create_preview(f'{file_path}',f'{source_folder}/{pid}_preview.png',pid)