构建压平冰箱贴的处理
This commit is contained in:
1 parent
789b785377
commit
1db36e9f34
1 file changed
+118
@@ -0,0 +1,118 @@
|
|||||||
|
from ctypes import util
|
||||||
|
import os, oss2, time, redis, requests, shutil, sys, subprocess, json, platform
|
||||||
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
from retrying import retry
|
||||||
|
import atexit,platform
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
sys.path.append('e:\\libs\\')
|
||||||
|
import common
|
||||||
|
import config
|
||||||
|
def find_blender_bin_path():
|
||||||
|
if platform.system() == 'Linux': return 'blender'
|
||||||
|
base_path = 'C:\\Program Files\\Blender Foundation\\'
|
||||||
|
if os.path.exists(base_path):
|
||||||
|
for dir in os.listdir(base_path):
|
||||||
|
if dir.startswith('Blender'):
|
||||||
|
blender_bin_path = base_path + dir + '\\blender.exe'
|
||||||
|
return f'"{blender_bin_path}"'
|
||||||
|
else:
|
||||||
|
print('未找到blender安装目录')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
@retry(stop_max_attempt_number=10, wait_fixed=3000)
|
||||||
|
def down_obj_fromoss(pid):
|
||||||
|
print('开始下载obj文件...' , pid)
|
||||||
|
path = os.path.join(workdir, 'print', pid)
|
||||||
|
if not os.path.exists(path): os.makedirs(path)
|
||||||
|
# 根据前缀获取文件列表
|
||||||
|
prefix = f'objs/print/{pid}/base/fridge'
|
||||||
|
print(f'prefix:{prefix}')
|
||||||
|
filelist = oss2.ObjectIteratorV2(oss_client, prefix=prefix)
|
||||||
|
|
||||||
|
find = False
|
||||||
|
for file in filelist:
|
||||||
|
filename = file.key.split('/')[-1]
|
||||||
|
if filename == '': continue
|
||||||
|
if filename.endswith(f'.obj') and find == True:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if filename.endswith(f'{pid}.obj'):
|
||||||
|
find = True
|
||||||
|
localfile = os.path.join(path, filename)
|
||||||
|
res = oss_client.get_object_to_file(file.key, localfile)
|
||||||
|
print(f'下载文件:{file.key},状态:{res.status}')
|
||||||
|
if not find:
|
||||||
|
print('找不到obj文件,异常退出')
|
||||||
|
sys.exit(1)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def team_check(r):
|
||||||
|
try:
|
||||||
|
if r.llen('glb:flat_fridge_repair_order') == 0:
|
||||||
|
time.sleep(5)
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
|
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), 'redis连接异常,5秒后重试')
|
||||||
|
print(e)
|
||||||
|
time.sleep(5)
|
||||||
|
r = create_redis_connection()
|
||||||
|
return
|
||||||
|
pid = r.lpop('glb:flat_fridge_repair_order')
|
||||||
|
if pid is None: return
|
||||||
|
pid = pid.decode('utf-8')
|
||||||
|
#下载数据
|
||||||
|
down_obj_fromoss(pid)
|
||||||
|
|
||||||
|
obj_filename = f'{pid}.obj'
|
||||||
|
glb_filename = f'{pid}.glb'
|
||||||
|
print('开始转换obj文件为glb文件...')
|
||||||
|
os.system(f'gltfpack -c -i {os.path.join(workdir, "print", pid, obj_filename)} -o {os.path.join(workdir, "print", pid, glb_filename)} -vt 16 -vc 16')
|
||||||
|
#上传glb文件到oss
|
||||||
|
oss_client.put_object_from_file(f'glbs/print/flat_fridge/{glb_filename}', os.path.join(workdir, "print", pid, glb_filename))
|
||||||
|
shutil.rmtree(os.path.join(workdir, 'print', pid), ignore_errors=True)
|
||||||
|
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), f'pid:{pid} 压平冰箱贴的glb已生成 end')
|
||||||
|
|
||||||
|
def create_redis_connection():
|
||||||
|
"""创建 Redis 连接,若连接失败则重试"""
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
r = redis.Redis(host='106.14.158.208', password='kcV2000', port=6379, db=6)
|
||||||
|
# 尝试进行一次操作,检查连接是否有效
|
||||||
|
r.ping() # ping 操作是一个简单的连接测试
|
||||||
|
print("Redis连接成功!")
|
||||||
|
return r
|
||||||
|
except ConnectionError:
|
||||||
|
print("Redis连接失败,正在重试...")
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
|
def main(r):
|
||||||
|
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), '模型生成程序 start')
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
team_check(r)
|
||||||
|
except Exception as e:
|
||||||
|
print('出现异常:', e)
|
||||||
|
time.sleep(5)
|
||||||
|
r = create_redis_connection()
|
||||||
|
continue
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
atexit.register(common.notify,"R13-修模师审核通过,生成打印任务程序停止")
|
||||||
|
AccessKeyId = 'LTAI5tSReWm8hz7dSYxxth8f'
|
||||||
|
AccessKeySecret = '8ywTDF9upPAtvgXtLKALY2iMYHIxdS'
|
||||||
|
Endpoint = 'oss-cn-shanghai.aliyuncs.com'
|
||||||
|
Bucket = 'suwa3d-securedata'
|
||||||
|
oss_client = oss2.Bucket(oss2.Auth(AccessKeyId, AccessKeySecret), Endpoint, Bucket)
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
workdir = 'D:\\'
|
||||||
|
else:
|
||||||
|
workdir = '/data/datasets/'
|
||||||
|
blenderbin = find_blender_bin_path()
|
||||||
|
r = create_redis_connection()
|
||||||
|
main(r)
|
||||||
Reference in new issue
Block a user