From 07a63949132b16c46ff9f219f19e14e44452359e Mon Sep 17 00:00:00 2001 From: mozzie Date: Thu, 7 Sep 2023 10:07:39 +0800 Subject: [PATCH] feat: stl wall thickness --- DockerFile | 60 ------------------- PyBlender.dockerfile | 24 -------- add_thickness.py | 43 ------------- api_script.py | 19 ------ .../src/modules/Root/Viewer/Root/index.tsx | 2 +- 5 files changed, 1 insertion(+), 147 deletions(-) delete mode 100644 DockerFile delete mode 100644 PyBlender.dockerfile delete mode 100644 add_thickness.py delete mode 100644 api_script.py diff --git a/DockerFile b/DockerFile deleted file mode 100644 index 7dc7662..0000000 --- a/DockerFile +++ /dev/null @@ -1,60 +0,0 @@ -FROM ubuntu:latest - -# 使用阿里云的Ubuntu源替换默认源 -# RUN echo "deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse" > /etc/apt/sources.list && \ -# echo "deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list && \ -# echo "deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse" >> /etc/apt/sources.list && \ -# echo "deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse" >> /etc/apt/sources.list && \ -# echo "deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse" >> /etc/apt/sources.list - -# 更新软件包列表并安装依赖项 -RUN apt-get update && apt-get install -y \ - software-properties-common \ - libgl1-mesa-glx \ - libxi6 \ - libxxf86vm1 \ - libxfixes3 \ - libxrender1 \ - libx11-6 \ - libsdl2-2.0-0 \ - libopenal1 \ - libxrandr2 \ - libfreetype6 \ - libtiff5 \ - libjpeg8 \ - libpng16-16 \ - zlib1g \ - wget \ - python3 \ - python3-pip \ - libxi6 \ - libglu1-mesa \ - libxext6 - -# 下载并安装Blender -RUN wget https://mirrors.tuna.tsinghua.edu.cn/blender/release/Blender2.93/blender-2.93.1-linux-x64.tar.xz && \ - tar xf blender-2.93.1-linux-x64.tar.xz && \ - mv blender-2.93.1-linux-x64 /opt/blender && \ - rm blender-2.93.1-linux-x64.tar.xz - -# 将Blender的可执行文件路径添加到PATH中 -ENV PATH="$PATH:/opt/blender" - -# 安装Python依赖项 -RUN pip3 install fastapi[all] uvicorn - -# 工作目录 -WORKDIR /workspace - -RUN mkdir /workspace/temp - - -# 将你的API代码和Blender Python脚本复制到工作目录中 -COPY ./api_script.py /workspace/ -COPY ./add_thickness.py /workspace/ - -# 暴露API使用的端口 -EXPOSE 8000 - -# 启动API -CMD ["uvicorn", "api_script:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/PyBlender.dockerfile b/PyBlender.dockerfile deleted file mode 100644 index 86f58c1..0000000 --- a/PyBlender.dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -# 使用预先构建的Blender镜像 -FROM zocker160/blender-bpy:stable - -# 安装Python库和工具 -RUN apt-get update && apt-get install -y \ - python3-pip - -# 安装Python依赖 -RUN pip3 install fastapi uvicorn python-multipart - -# 设置工作目录 -WORKDIR /workspace - -RUN mkdir /workspace/temp - -# 复制API和处理脚本到容器内 -COPY ./api_script.py /workspace/ -COPY ./add_thickness.py /workspace/ - -# 暴露FastAPI使用的端口 -EXPOSE 8000 - -# 设置启动命令 -CMD ["uvicorn", "api_script:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/add_thickness.py b/add_thickness.py deleted file mode 100644 index 73be743..0000000 --- a/add_thickness.py +++ /dev/null @@ -1,43 +0,0 @@ -import bpy -import os - -def cleanup(): - # 删除所有meshes,这样我们可以从一个干净的环境开始 - bpy.ops.object.select_all(action='DESELECT') - bpy.ops.object.select_by_type(type='MESH') - bpy.ops.object.delete() - -def add_thickness_to_stl(input_file_path, output_file_path, thickness=0.1): - cleanup() - - # 激活STL导入插件 - bpy.ops.preferences.addon_enable(module="io_mesh_stl") - - # 导入STL - bpy.ops.import_mesh.stl(filepath=input_file_path) - - # 确保导入的模型是当前活跃的 - obj = bpy.context.selected_objects[0] - bpy.context.view_layer.objects.active = obj - - # 进入编辑模式 - bpy.ops.object.editmode_toggle() - - # 选择所有顶点 - bpy.ops.mesh.select_all(action='SELECT') - - # 使用Solidify修饰器来增加壁厚 - bpy.ops.object.modifier_add(type='SOLIDIFY') - solidify = obj.modifiers["Solidify"] - solidify.thickness = thickness - - # 应用修饰器 - bpy.ops.object.modifier_apply({"object": obj}, modifier="Solidify") - - # 返回对象模式 - bpy.ops.object.editmode_toggle() - - # 导出为STL - bpy.ops.export_mesh.stl(filepath=output_file_path) - - cleanup() diff --git a/api_script.py b/api_script.py deleted file mode 100644 index 1b96104..0000000 --- a/api_script.py +++ /dev/null @@ -1,19 +0,0 @@ -from fastapi import FastAPI, UploadFile, File -from add_thickness import add_thickness_to_stl - -app = FastAPI() - -@app.post("/process_stl/") -async def process_stl(file: UploadFile = File(...)): - input_file_path = f"temp/{file.filename}" - output_file_path = f"processed/{file.filename}" - - # 保存上传的文件 - with open(input_file_path, 'wb') as buffer: - buffer.write(file.file.read()) - - # 调用修改过的 add_thickness 函数 - add_thickness_to_stl(input_file_path, output_file_path) - - # 返回处理后的文件 - return FileResponse(output_file_path, headers={"Content-Disposition": f"attachment; filename={file.filename}"}) diff --git a/apps/aorta/src/modules/Root/Viewer/Root/index.tsx b/apps/aorta/src/modules/Root/Viewer/Root/index.tsx index 5d2ecad..0d7d1ba 100644 --- a/apps/aorta/src/modules/Root/Viewer/Root/index.tsx +++ b/apps/aorta/src/modules/Root/Viewer/Root/index.tsx @@ -7,7 +7,7 @@ interface RootViewerProps { export const RootViewer = (props: RootViewerProps) => { return (
- + 123
); };