feat: stl wall thickness
This commit is contained in:
parent
8fb43bd479
commit
07a6394913
60
DockerFile
60
DockerFile
|
@ -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"]
|
|
@ -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"]
|
|
@ -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()
|
|
@ -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}"})
|
|
@ -7,7 +7,7 @@ interface RootViewerProps {
|
|||
export const RootViewer = (props: RootViewerProps) => {
|
||||
return (
|
||||
<div>
|
||||
<STLViewer />
|
||||
123
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user