|
|
|
|
@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
|
|
|
|
|
import os, sys, time, bpy, math, requests, bmesh, json, shutil,oss2 |
|
|
|
|
import os, sys, time, bpy, math, requests, bmesh, json, shutil,oss2,chardet |
|
|
|
|
from PIL import Image |
|
|
|
|
import platform,redis |
|
|
|
|
if platform.system() == 'Windows': |
|
|
|
|
@ -86,41 +86,48 @@ def down_obj_from_oss(workdir, pid, action):
@@ -86,41 +86,48 @@ def down_obj_from_oss(workdir, pid, action):
|
|
|
|
|
return obj_filename |
|
|
|
|
|
|
|
|
|
def checkDownloadFile(pid): |
|
|
|
|
mtlfilePath = os.path.join(config.workdir, "print", pid,f"{pid}.mtl") |
|
|
|
|
objfilePath = os.path.join(config.workdir, "print", pid,f"{pid}.obj") |
|
|
|
|
#读取该笔文件的mtl文件 忽略编码问题 |
|
|
|
|
with open(mtlfilePath, 'r',encoding='utf-8',errors='ignore') as file: |
|
|
|
|
mtlContent = file.read() |
|
|
|
|
#检测mtl文件是否正常 |
|
|
|
|
mtlfilePath = os.path.join(config.workdir, "print", pid, f"{pid}.mtl") |
|
|
|
|
objfilePath = os.path.join(config.workdir, "print", pid, f"{pid}.obj") |
|
|
|
|
|
|
|
|
|
# 读取文件内容(自动检测编码) |
|
|
|
|
def read_file_auto_encoding(path): |
|
|
|
|
with open(path, 'rb') as f: |
|
|
|
|
raw_data = f.read() |
|
|
|
|
encoding = chardet.detect(raw_data)['encoding'] or 'utf-8' |
|
|
|
|
return raw_data.decode(encoding, errors='ignore') |
|
|
|
|
|
|
|
|
|
mtlContent = read_file_auto_encoding(mtlfilePath) |
|
|
|
|
|
|
|
|
|
if mtlContent == "": |
|
|
|
|
print(f'{pid}的mtl文件检测出现问题了, 没有找到mtl文件') |
|
|
|
|
print(f'{pid}的mtl文件检测出现问题了, 内容为空') |
|
|
|
|
return False |
|
|
|
|
#判断mtl 包含几个 newmtl |
|
|
|
|
|
|
|
|
|
newmtlCount = mtlContent.count('newmtl') |
|
|
|
|
if newmtlCount > 1: |
|
|
|
|
print(f'{pid}的mtl文件检测出现问题了, 包含多个newmtl') |
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
#判断mtlContent是否包含 {pid}Tex1.jpg |
|
|
|
|
if f'{pid}Tex1.jpg' not in mtlContent: |
|
|
|
|
print(f'{pid}的mtl文件检测出现问题了, 没有找到{pid}Tex1.jpg') |
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
#检测obj文件 里 是否包含 o {pid}, |
|
|
|
|
# 检测obj文件 |
|
|
|
|
isContain = False |
|
|
|
|
with open(objfilePath, 'r',encoding='utf-8',errors='ignore') as file: |
|
|
|
|
for line in file: |
|
|
|
|
|
|
|
|
|
objContent = read_file_auto_encoding(objfilePath) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for line in objContent.splitlines(): |
|
|
|
|
if line.startswith(f'o {pid}'): |
|
|
|
|
isContain = True |
|
|
|
|
print(f'{pid}的obj文件检测没问题') |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
if isContain == False: |
|
|
|
|
if not isContain: |
|
|
|
|
print(f'{pid}的obj文件检测出现问题了, 没有找到o {pid} 的行') |
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return isContain |
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
#加载obj文件 |
|
|
|
|
def reload_obj(pid,order_ids): |
|
|
|
|
@ -293,7 +300,7 @@ def createGlb(pid,order_ids):
@@ -293,7 +300,7 @@ def createGlb(pid,order_ids):
|
|
|
|
|
|
|
|
|
|
#下载obj文件 |
|
|
|
|
down_obj_from_oss(config.workdir, pid, "print") |
|
|
|
|
|
|
|
|
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 下载obj文件完成...') |
|
|
|
|
#检测mtl 文件是否正常, |
|
|
|
|
isNormal = checkDownloadFile(pid) |
|
|
|
|
if isNormal == False: |
|
|
|
|
|