import os import time from PIL import Image from selenium import webdriver from selenium.webdriver.common.by import By import pywinauto import pyautogui def slcer_3Dtiles(root, file): browser = webdriver.Chrome() browser.maximize_window() browser.get('http://localhost:9003/index.html#/data/model') # 选择 通用模型切片 time.sleep(2) browser.find_element(By.XPATH, '//*[@id="right_box"]/div/div[1]/ul/a[8]/li/button').click() time.sleep(2) # 选择输入文件 obj browser.find_element(By.XPATH, '//*[@id="input_button"]/button[1]').click() time.sleep(1) # 使用pywinauto来选择文件 app = pywinauto.Desktop() # 选择文件上传的窗口 dlg = app["打开"] # 选择文件地址输入框,点击激活 # dlg["Toolbar3"].click() # 键盘输入上传文件的路径 # send_keys(r"D:\osg\wenxingyuan\test\tyzzkcc001.obj") # 键盘输入回车,打开该路径 # send_keys("{VK_RETURN}") # 选中文件名输入框,输入文件名 dlg["文件名(&N):Edit"].type_keys(os.path.join(root, file)) # dlg["文件名(&N):Edit"].type_keys(r'D:\osg\wenxingyuan\test\tyzzkcc001.obj') # 点击打开 dlg["打开(&O)"].click() time.sleep(2) # obj设置取消翻转YZ browser.find_element(By.XPATH, '//*[@id="setting_general"]').click() time.sleep(2) input = browser.find_element(By.XPATH, '//*[@id="switch_style"]') time.sleep(2) if not input.is_selected(): browser.find_element(By.XPATH, '//*[@id="all_right"]/div[3]/div/div/div[2]/div/div/div[3]/div[1]/div[1]').click() time.sleep(2) browser.find_element(By.XPATH, '//*[@id="all_right"]/div[3]/div/div/div[3]/button[2]').click() # 操作鼠标选择存储类型 # 获取鼠标位置(x,y) # pyautogui.position() time.sleep(2) pyautogui.moveTo(3552, 667) pyautogui.click() time.sleep(2) pyautogui.moveTo(3553, 732) pyautogui.click() time.sleep(2) # 数据存储 browser.find_element(By.XPATH, '//*[@id="all_right"]/div[1]/div/div[16]/div/div[3]/div[4]/div[1]/button').click() app = pywinauto.Desktop() # 选择文件上传的窗口 dlg = app["选择文件夹"] # print(dlg.print_control_identifiers()) # 选择文件地址输入框,点击激活 dlg["Toolbar3"].click() # 键盘输入上传文件的路径 # send_keys(r"D:\osg\wenxingyuan\test\111") # 键盘输入回车,打开该路径 # send_keys("{VK_RETURN}") # 选中文件名输入框,输入文件名 if not os.path.exists(os.path.join(root, file.split('.')[0])): os.makedirs(os.path.join(root, file.split('.')[0])) time.sleep(3) dlg["文件夹:Edit"].type_keys(os.path.join(root, file.split('.')[0])) # 点击打开 dlg["选择文件夹2"].click() time.sleep(1) # 提交处理 browser.find_element(By.XPATH, '//*[@id="newfile_button"]/button').click() if __name__ == '__main__': input_path = r'C:\Users\admin\Desktop\新建文件夹' output_path = r'C:\Users\admin\Desktop\新建文件夹' # dds旋转转png、osg转obj for root, dirs, files in os.walk(input_path): for file in files: if os.path.splitext(file)[-1] in ['.dds']: im = Image.open(os.path.join(root, file)) im2 = im.transpose(Image.Transpose.FLIP_TOP_BOTTOM) if not os.path.exists(os.path.join(output_path)): os.makedirs(os.path.join(output_path)) im2.save(os.path.join(output_path, file.replace('dds', 'png'))) if os.path.splitext(file)[-1] in ['.osg']: cmd = r'osgconv.exe {osg_input_path} {osg_output_path}'.format(osg_input_path=os.path.join(root, file), osg_output_path=os.path.join(output_path, file.replace('osg', 'obj'))) os.system(cmd) # mtl文件 dds替换为png for root, dirs, files in os.walk(output_path): for file in files: if os.path.splitext(file)[-1] in ['.mtl']: with open(os.path.join(root, file), 'r') as f: mtl_data = f.read() with open(os.path.join(root, file), 'w') as f1: f1.write(mtl_data.replace('dds', 'png')) # 3Dtiles 切片 for root, dirs, files in os.walk(output_path): for file in files: if os.path.splitext(file)[-1] in ['.obj']: if file.split('.')[0] not in os.listdir(os.path.join(root)): slcer_3Dtiles(root, file)