|
|
|
|
@ -76,6 +76,15 @@ def fix_link_texture(pid):
@@ -76,6 +76,15 @@ def fix_link_texture(pid):
|
|
|
|
|
|
|
|
|
|
f.close() |
|
|
|
|
|
|
|
|
|
def imagePiex(filePath,piex): |
|
|
|
|
# 打开图片 |
|
|
|
|
image = Image.open(filePath) |
|
|
|
|
# 设置新的最大宽度和高度 |
|
|
|
|
max_size = (piex, piex) |
|
|
|
|
# 保持宽高比缩放图片 |
|
|
|
|
image.thumbnail(max_size) |
|
|
|
|
# 保存调整后的图片 |
|
|
|
|
image.save(filePath) |
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
|
start = time.time() |
|
|
|
|
@ -91,6 +100,7 @@ def main():
@@ -91,6 +100,7 @@ def main():
|
|
|
|
|
pid = res.json()['data']['pid'] |
|
|
|
|
path = os.path.join(workdir, 'print', f'{pid}_{orderId}') |
|
|
|
|
filename = os.path.join(path, f'{pid}.obj') |
|
|
|
|
imagePath = os.path.join(path, f'{pid}Tex1.jpg') |
|
|
|
|
bpy.ops.object.delete(use_global=False, confirm=False) |
|
|
|
|
bpy.context.scene.unit_settings.scale_length = 0.001 |
|
|
|
|
bpy.context.scene.unit_settings.length_unit = 'CENTIMETERS' |
|
|
|
|
@ -104,7 +114,7 @@ def main():
@@ -104,7 +114,7 @@ def main():
|
|
|
|
|
print('应用后模型尺寸:', obj.dimensions) |
|
|
|
|
shutil.copy(filename, os.path.join(path, f'{pid}_original.obj')) |
|
|
|
|
filename_original = os.path.join(path, f'{pid}_original.obj') |
|
|
|
|
|
|
|
|
|
headcount = res.json()['data']['headcount'] |
|
|
|
|
for f in res.json()['data']['fileList']: |
|
|
|
|
|
|
|
|
|
if "undefined" in f: |
|
|
|
|
@ -118,19 +128,38 @@ def main():
@@ -118,19 +128,38 @@ def main():
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
obj = bpy.context.selected_objects[0] |
|
|
|
|
bpy.context.view_layer.objects.active = obj |
|
|
|
|
print(f'{f}处理前{height}mm模型尺寸: {obj.dimensions}') |
|
|
|
|
scale = height / obj.dimensions.z |
|
|
|
|
obj.scale = (scale, scale, scale) |
|
|
|
|
bpy.ops.object.transform_apply(scale=True) |
|
|
|
|
print(f'{f}处理后{height}mm模型尺寸: {obj.dimensions}') |
|
|
|
|
|
|
|
|
|
if headcount == 1 and height <= 80: |
|
|
|
|
pixs = 4096 |
|
|
|
|
faces_dest = 125000 |
|
|
|
|
if height <= 50: |
|
|
|
|
pixs = 2048 |
|
|
|
|
faces_dest = 63000 |
|
|
|
|
print(f'减面到{faces_dest}') |
|
|
|
|
faces_dest = faces_dest * headcount |
|
|
|
|
# 减面 |
|
|
|
|
faces_current = len(obj.data.polygons) |
|
|
|
|
bpy.ops.object.modifier_add(type='DECIMATE') |
|
|
|
|
bpy.context.object.modifiers["Decimate"].ratio = faces_dest / faces_current |
|
|
|
|
bpy.ops.object.modifier_apply(modifier="Decimate") |
|
|
|
|
# imagePiex(imagePath,pixs) |
|
|
|
|
|
|
|
|
|
bpy.ops.export_scene.obj(filepath=os.path.join(path, f'{pid}.obj')) |
|
|
|
|
if os.path.exists(os.path.join(path, f)): |
|
|
|
|
os.remove(os.path.join(path, f)) |
|
|
|
|
os.rename(os.path.join(path, f'{pid}.obj'), os.path.join(path, f)) |
|
|
|
|
config.oss_bucket.put_object_from_file(f'objs/print/{pid}/{f}', os.path.join(path, f)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 重新加载模型,然后生成数字模型 |
|
|
|
|
bpy.ops.object.delete(use_global=False, confirm=False) |
|
|
|
|
fix_link_texture(pid) |
|
|
|
|
@ -148,7 +177,7 @@ def main():
@@ -148,7 +177,7 @@ def main():
|
|
|
|
|
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) |
|
|
|
|
# if str(pid) == '120745': bpy.ops.wm.save_as_mainfile(filepath=os.path.join(path, f'{pid}_{orderId}.blend')) |
|
|
|
|
|
|
|
|
|
headcount = res.json()['data']['headcount'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bm = bmesh_copy_from_object(obj) |
|
|
|
|
obj_volume = round(bm.calc_volume() / 1000, 3) |
|
|
|
|
|