Render

earthtojake/text-to-cad/skills/render

作者 earthtojake5b6f37afd5619b95b931b6967fa02f90900dc17bMIT28K 個星標收錄於 2026年11月20日更新於 2026年12月2日儲存庫今天更新

Renders photoreal images and videos of a text-to-cad model, a STEP or an xbf with Blender - a hero shot, a product or README picture, a turntable, or a film of a model's motion. Use when the person wants a picture or a video for people to look at. Not for checking geometry, which the cad skill's snapshot does.

僅含說明設計與創意
AI 產生的概覽

透過 Python 場景腳本在 Blender 中算圖 CAD 模型的擬真靜態影像、環繞動畫與影片。

功能
將 text-to-cad 模型、STEP 或 xbf 檔案匯出為 GLB,再撰寫 Python 腳本匯入 bpy,以 cad.blender.load 載入 GLB,並設定攝影機、燈光、世界與算圖引擎。透過 cad run 執行後產生主視覺圖、README 配圖、環繞動畫、姿勢靜態影像或模型動作的 mp4 影片。也涵蓋先草稿後定稿的流程、材質與外觀,以及儲存 .blend 檔案。
適用情境
當使用者想要供人觀看的 CAD 模型圖片或影片時使用,例如主視覺圖、產品圖、環繞動畫或動畫影片。不用於檢查幾何形狀,那由 cad 技能的 snapshot 負責。
執行需求
需要 cad 命令列工具(以 0.11.22 版為準)與 cad run,後者會準備 Python 3.13 上的 bpy 5.2.3,首次執行需下載 260 至 430 MB。EEVEE 需要圖形驅動程式;Cycles 可在 CPU 上執行。此技能未附腳本,算圖腳本由代理撰寫。

AI 概覽如何產生和驗證

Renders for people

A render is a picture for a person: a hero image, a README picture, a turntable, a film of a mechanism. The model goes to Blender as a GLB, loaded by cad.blender.load; the scene (camera, lights, world, engine, output) is an ordinary Python script that imports bpy, Blender as a Python module, and cad run runs it. Geometry is judged with cad model snapshot, never a render: lens, light and depth of field make it a poor measure.

Start with the task

TaskStart withReference
A still of a modelExport a GLB, write a render.py that loads it, cad run render.pyThe script, scene script [blocked]
Draft, then a finalAn EEVEE draft at 1080p, looked at, before CyclesDraft then final [blocked]
A pose, or a frame of an animationmodel.play(name) and the frameLoad the GLB
A turntableThe camera on an empty that turns onceTurntables [blocked]
A film of a motion or an animationmodel.play(name), then an mp4Films [blocked]
Motion blur, depth of field, a glowThe scene's and the camera's settings; a keyed emissionShots [blocked]
Looks and materialsSet in the model, exported againLooks
A .blend for the personbpy.ops.wm.save_as_mainfile at the end of the scriptA .blend [blocked]
The GPU, or a machine with no graphics driverCycles' device, chosen in the scriptEngines [blocked], no driver [blocked]

Setup

Written for cad==0.11.22. Before first use in a chat, run cad --version. If it fails, or cad is missing or older than 0.11.12, run uv tool install --force cad. If it is older than the release this skill was written for, run cad update.

If cad is a major or minor version newer than this skill, tell the person to update the text-to-cad plugin: https://github.com/earthtojake/text-to-cad A project written for an earlier version may need changes; the migration guides say what: https://github.com/earthtojake/text-to-cad/tree/main/docs/migrations

cad run sees import bpy and makes the script an environment with bpy 5.2.3 (Blender 5.2 LTS) on Python 3.13 beside cad, once: a download of 260 to 430 MB, so the first run is slow. Nothing starts the Blender app, and the person's own Blender settings and add-ons never load. bpy has no build for Intel Macs or Linux on ARM, where cad run refuses the script by name.

Export the model

cad model export "$ID" scene.glb --tolerance 0.02 --angle 5

$ID is the model's id; a STEP or an xbf exports the same way (cad step export part.step scene.glb --tolerance 0.02 --angle 5). The GLB is in metres, Z up once imported, with the assembly's tree as nested empties, a PBR material per look, and each motion and animation() as a clip. --tolerance (mm) and --angle (degrees) mesh it finer than the viewer's, so a close camera shows no facets, at the cost of triangles: start near 0.02 mm and 5 degrees for a close-up of a hand-sized part, coarser for a large assembly seen whole. The GLB is a copy: export again after every model change.

The script

# render.py: cad run render.py
import math
from pathlib import Path

import bpy
from mathutils import Vector

from cad.blender import load

HERE = Path(__file__).resolve().parent

bpy.ops.wm.read_factory_settings(use_empty=True)  # no person's startup file, no default cube
scene = bpy.context.scene
model = load(HERE / "scene.glb")  # every part where cad placed it

scene.render.resolution_x, scene.render.resolution_y = 1920, 1080
aim = bpy.data.objects.new("aim", None)
aim.location = model.center
camera = bpy.data.objects.new("camera", bpy.data.cameras.new("camera"))
camera.data.lens = 85
view = math.tan(camera.data.angle / 2) * min(1, scene.render.resolution_y / scene.render.resolution_x)
distance = model.size.length / 2 / view * 1.1  # the whole box in the frame's shorter side
camera.location = model.center + distance * Vector((1, -1, 0.6)).normalized()
camera.constraints.new("TRACK_TO").target = aim
sun = bpy.data.objects.new("sun", bpy.data.lights.new("sun", "SUN"))
sun.data.energy, sun.rotation_euler = 3.0, (0.8, 0.2, 0.6)
for item in (aim, camera, sun):
    scene.collection.objects.link(item)
scene.camera = camera
scene.world = bpy.data.worlds.new("world")
scene.world.node_tree.nodes["Background"].inputs["Strength"].default_value = 0.4

scene.render.engine = "BLENDER_EEVEE"  # a draft; "CYCLES" for the final
scene.render.filepath = str(HERE / "hero.png")
bpy.ops.render.render(write_still=True)
cad run render.py

The script is the scene: every run starts empty and adds its camera, lights and world in Python. Arguments after the script's name reach it as sys.argv[1:]. Lights, the world, colour management and the GPU are in the scene script [blocked].

Load the GLB

Load with cad.blender.load, never bpy.ops.import_scene.gltf alone: Blender's importer poses every part a clip moves at that clip's first frame, with no error, leaves only the first clip live and keys from frame 0. load runs that importer, puts every node back where the GLB places it, and plays the clip asked for. It opens any GLB, not only cad's.

CallGives
load(path, clip=None, fps=24)Imports into the current scene and returns the model; clip plays one, fps keys its seconds. Give a film's rate here: render.fps set after the import plays every clip at the wrong speed, with no error
model.rootThe document's root empty, at the origin, scale 0.001 (parts are in mm below it); model.roots for a file with several
model.objects["arm/head"]A node's object by its path below the root, as the GLB names it; of two nodes with one name it is the last (model.nodes[i] reaches each)
model.nodes[7]A node's object by its index in the file, which tells two of one name apart
model.clipsEach clip by name: kind (motion or animation) and duration in seconds
model.box, model.center, model.sizeThe world box of the pose cad wrote, in metres, for framing
model.play("sweep")That clip from frame 0, the scene's range set to its duration; model.play(None) stands every part as placed
model.bounds()The world box at the current frame

A still of a pose is a clip's frame: model.play("sweep"), scene.frame_set(24), render.

Looks

A part's look is the model's: set it there and export again. bd_materials gives physics and a look; cad.build123d.materials adds named looks Blender draws well (solder mask, ENIG, anodized, powder coat, LED lenses). Blender's importer draws base colour, metalness, roughness, IOR, opacity, transmission, clear coat, sheen, specular and emission; it does not draw anisotropy (brushed metal draws plain), dispersion or texture maps.

A Blender material is named by the model's look (bpy.data.materials["frame_black"]), so a script can restyle a look wherever it is worn, and the physical material it is a look of is its custom property (material["cad"]["material"]). Change one in the script only for the render's sake (a glow, a backdrop). A transmissive look's base colour tints what passes through, so smoked glass written as a near-black colour with partial transmission renders black: write glass as transmission=1 with the tint as its colour, and judge it in a Cycles draft.

Engines

EEVEE (BLENDER_EEVEE) draws a 1080p frame in seconds: drafts, framing, light. Cycles with OIDN denoising is the final, on the GPU where there is one, at minutes a frame. They disagree on glass and translucent parts, so draft those in Cycles at a few samples.

EEVEE needs a graphics driver. On a machine without one (a headless Linux server or container), an EEVEE render prints Couldn't open libEGL.so.1 and ends the process with exit 134 and no Python exception, as does the compositor on its default device: draft in Cycles at 8 to 16 samples and set scene.render.compositor_device = "CPU" (no graphics driver [blocked]).

Check each change

ChangeCheck
Camera, framing, lights, worldAn EEVEE draft at 1080p, opened and looked at
A pose, a clip's framemodel.play(...), the frame, then a draft; a moved part's world position (model.objects[path].matrix_world.translation) against the model's
Looks, glass, emissionA small Cycles draft (32 to 64 samples)
A turntable or a filmThree frames (first, middle, last) as stills before the whole film
The finalAgainst its draft: same framing, nothing missing
  • An empty or black image is the camera inside, behind or too near the model, or no light: print model.box and the camera's location.
  • A part in the wrong pose is a GLB imported without load, or a frame taken before model.play.
  • First runs are slow once each: import bpy (10 to 20 s), EEVEE's shaders (about 13 s), Cycles' GPU kernels on a Mac (minutes). Run a final in the background with a long timeout, and each final in a run of its own, since Blender keeps a Cycles render's memory until its process ends.

來源與署名

來源:earthtojake/text-to-cad位於skills/render提交5b6f37a

授權條款: MIT

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

在 README 中新增徽章

向讀者展示該技能已收錄於 SourceWeft,徽章連結到本頁。

「Listed on SourceWeft」徽章預覽
[![Listed on SourceWeft](https://sourceweft.com/badge/skills/gh-earthtojake-text-to-cad-render-skills-render-23f7d99852528d11.svg)](https://sourceweft.com/skills/gh-earthtojake-text-to-cad-render-skills-render-23f7d99852528d11?utm_source=readme&utm_medium=badge)

檢舉或申請下架