admin管理员组

文章数量:1389749

I have a Dockerfile(blender-container as image) in which I am running Blender in headless mode. I want to export the output I get from my bpy code.

Right now, I have a node.js server: server.js, which takes bpy code from client, make a temporary directory and under it make a server.py where client bpy code will be stored.

Using exec, I run: (`docker run --rm -v ${tempDir}:/workspace blender-container`)

This is my Dockerfile code:

FROM ubuntu:22.04

RUN apt update && apt install -y \
    blender xvfb libgl1-mesa-glx libx11-xcb1 libxcb-dri3-0 libxcb-dri2-0 \
    libxcb-glx0 libxcb-present0 libxrender1 libxrandr2 libxcursor1 \
    libxkbcommon0 libxi6 libxxf86vm1 libasound2 libpulse0 \
    libopenal1 libvulkan1 x11-utils sudo wget curl unzip xz-utils \
    mesa-utils && apt clean

RUN mkdir -p /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix

RUN wget .6/blender-3.6.5-linux-x64.tar.xz && \
    tar -xvf blender-3.6.5-linux-x64.tar.xz && \
    mv blender-3.6.5-linux-x64 /opt/blender && \
    ln -sf /opt/blender/blender /usr/local/bin/blender

WORKDIR /workspace

COPY script.py /workspace/script.py

ENV OCIO=/opt/blender/3.6/datafiles/colormanagement/config.ocio

CMD Xvfb :99 -screen 0 1920x1080x24 & export DISPLAY=:99 && blender --background --python /workspace/script.py

My expectation: I want to get 3d output which will be displayed in blender, which I could run in my custom 3d viewer. Ensure the output should be same as I get in blender.

I have a Dockerfile(blender-container as image) in which I am running Blender in headless mode. I want to export the output I get from my bpy code.

Right now, I have a node.js server: server.js, which takes bpy code from client, make a temporary directory and under it make a server.py where client bpy code will be stored.

Using exec, I run: (`docker run --rm -v ${tempDir}:/workspace blender-container`)

This is my Dockerfile code:

FROM ubuntu:22.04

RUN apt update && apt install -y \
    blender xvfb libgl1-mesa-glx libx11-xcb1 libxcb-dri3-0 libxcb-dri2-0 \
    libxcb-glx0 libxcb-present0 libxrender1 libxrandr2 libxcursor1 \
    libxkbcommon0 libxi6 libxxf86vm1 libasound2 libpulse0 \
    libopenal1 libvulkan1 x11-utils sudo wget curl unzip xz-utils \
    mesa-utils && apt clean

RUN mkdir -p /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix

RUN wget https://mirror.clarkson.edu/blender/release/Blender3.6/blender-3.6.5-linux-x64.tar.xz && \
    tar -xvf blender-3.6.5-linux-x64.tar.xz && \
    mv blender-3.6.5-linux-x64 /opt/blender && \
    ln -sf /opt/blender/blender /usr/local/bin/blender

WORKDIR /workspace

COPY script.py /workspace/script.py

ENV OCIO=/opt/blender/3.6/datafiles/colormanagement/config.ocio

CMD Xvfb :99 -screen 0 1920x1080x24 & export DISPLAY=:99 && blender --background --python /workspace/script.py

My expectation: I want to get 3d output which will be displayed in blender, which I could run in my custom 3d viewer. Ensure the output should be same as I get in blender.

Share Improve this question asked Mar 13 at 16:00 Saksham webSaksham web 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

I got the answer.

In the bpy code at last I am doing:

const finalCode = `${userCode}\n\nfor obj in bpy.context.scene.objects:\n    obj.select_set(True)\nbpy.ops.wm.usd_export(filepath="/workspace/${outputName}", export_textures=True, export_materials=True, export_animation=True)`

this exports in Universal Scene Description(USD) and save in a file(/workspace/outputName). Since ${tempDir}:/workspace, which is why the file is stored in ${tempDir}/${outputName}

I could give the output to user now.

Solved!

本文标签: nodejsHow to Export 3D Output from bpy in Headless Blender (Docker)Stack Overflow