222
This commit is contained in:
1 parent
0bac162361
commit
01c4dbfb08
1 file changed
+28
-21
@@ -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
|
from PIL import Image
|
||||||
import platform,redis
|
import platform,redis
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
@@ -86,41 +86,48 @@ def down_obj_from_oss(workdir, pid, action):
|
|||||||
return obj_filename
|
return obj_filename
|
||||||
|
|
||||||
def checkDownloadFile(pid):
|
def checkDownloadFile(pid):
|
||||||
mtlfilePath = os.path.join(config.workdir, "print", pid,f"{pid}.mtl")
|
mtlfilePath = os.path.join(config.workdir, "print", pid, f"{pid}.mtl")
|
||||||
objfilePath = os.path.join(config.workdir, "print", pid,f"{pid}.obj")
|
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()
|
def read_file_auto_encoding(path):
|
||||||
#检测mtl文件是否正常
|
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 == "":
|
if mtlContent == "":
|
||||||
print(f'{pid}的mtl文件检测出现问题了, 没有找到mtl文件')
|
print(f'{pid}的mtl文件检测出现问题了, 内容为空')
|
||||||
return False
|
return False
|
||||||
#判断mtl 包含几个 newmtl
|
|
||||||
newmtlCount = mtlContent.count('newmtl')
|
newmtlCount = mtlContent.count('newmtl')
|
||||||
if newmtlCount > 1:
|
if newmtlCount > 1:
|
||||||
print(f'{pid}的mtl文件检测出现问题了, 包含多个newmtl')
|
print(f'{pid}的mtl文件检测出现问题了, 包含多个newmtl')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
#判断mtlContent是否包含 {pid}Tex1.jpg
|
|
||||||
if f'{pid}Tex1.jpg' not in mtlContent:
|
if f'{pid}Tex1.jpg' not in mtlContent:
|
||||||
print(f'{pid}的mtl文件检测出现问题了, 没有找到{pid}Tex1.jpg')
|
print(f'{pid}的mtl文件检测出现问题了, 没有找到{pid}Tex1.jpg')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
#检测obj文件 里 是否包含 o {pid},
|
# 检测obj文件
|
||||||
isContain = False
|
isContain = False
|
||||||
with open(objfilePath, 'r',encoding='utf-8',errors='ignore') as file:
|
|
||||||
for line in file:
|
|
||||||
if line.startswith(f'o {pid}'):
|
|
||||||
isContain = True
|
|
||||||
print(f'{pid}的obj文件检测没问题')
|
|
||||||
break
|
|
||||||
|
|
||||||
if isContain == False:
|
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 not isContain:
|
||||||
print(f'{pid}的obj文件检测出现问题了, 没有找到o {pid} 的行')
|
print(f'{pid}的obj文件检测出现问题了, 没有找到o {pid} 的行')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
return isContain
|
|
||||||
|
|
||||||
#加载obj文件
|
#加载obj文件
|
||||||
def reload_obj(pid,order_ids):
|
def reload_obj(pid,order_ids):
|
||||||
@@ -293,7 +300,7 @@ def createGlb(pid,order_ids):
|
|||||||
|
|
||||||
#下载obj文件
|
#下载obj文件
|
||||||
down_obj_from_oss(config.workdir, pid, "print")
|
down_obj_from_oss(config.workdir, pid, "print")
|
||||||
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 下载obj文件完成...')
|
||||||
#检测mtl 文件是否正常,
|
#检测mtl 文件是否正常,
|
||||||
isNormal = checkDownloadFile(pid)
|
isNormal = checkDownloadFile(pid)
|
||||||
if isNormal == False:
|
if isNormal == False:
|
||||||
|
|||||||
Reference in new issue
Block a user