使用 CuraEngine 和 Python 對三種 STL 尺寸進行基準測試
Benchmarking three STL sizes with CuraEngine and Python
這項基準測試使用 CuraEngine 和 Python 比較三種 STL 尺寸,估算同一款小狗模型增高 20 mm 後的耗材用量變化。測試固定幾何形狀、方向、打印機和切片設定,只改變最終 Z 高度;所有數值均為切片器估算。文中的程式會根據 STL 頂點計算縮放比例,將最低點設為 Z = 0,並保留法線和屬性。
Posted on Nov 26 Fully Autonomous
Disclosure: This post was generated with AI for Stlify AI, a project from the TalkPix team. The benchmark ran locally on a publicly available STL export. All figures are slicer estimates.
This benchmark answers a simple question: how much more filament will the same figurine use if you make it 20 mm taller? The setup below keeps the geometry, orientation, machine and slicer settings fixed. Only the final Z height changes.
1. Rescale from the STL vertices
The input was the free corgi STL from Stlify, exported with the round base on. The filename said 80 mm, and the final mesh measured 82.8 mm including the base. Save the binary download as corgi.stl for the example below. This script computes the scale from the vertices, puts the lowest point at Z = 0, and preserves normals and attributes. A uniform positive scale leaves the normals unchanged.
from pathlib import Path
from struct import pack_into, unpack_from
data = Path("corgi.stl").read_bytes()
count, = unpack_from("<I", data, 80)
if len(data) != 84 + 50 * count:
raise ValueError("Expected binary STL")
offsets = [84 + 50 * i + v for i in range(count) for v in (12, 24, 36)]
zs = [unpack_from("<f", data, offset + 8)[0] for offset in offsets]
z_min, z_max = min(zs), max(zs)
for height in (60, 80, 100):
scale = height / (z_max - z_min)
resized = bytearray(data)
for offset in offsets:
x, y, z = unpack_from("<3f", data, offset)
pack_into("<3f", resized, offset, x * scale, y * scale, (z - z_min) * scale)
Path(f"corgi-{height}.stl").write_bytes(resized)
2. Slice with one frozen configuration
This uses CuraEngine 5.11.0 and the Ender-3 machine definition bundled with UltiMaker Cura. On macOS, the following paths come from the installed application. Set the machine definition search path to include extruders as well as definitions so the engine can resolve the printer’s extruder file. Set nozzle size and filament diameter after -e0 so they apply to that extruder.
APP='/Applications/UltiMaker Cura.app/Contents'
RES="$APP/Resources/share/cura/resources"
export CURA_ENGINE_SEARCH_PATH="$RES/definitions:$RES/extruders"
for size in 60 80 100; do
"$APP/Frameworks/CuraEngine" slice -m2 \
-j "$RES/definitions/creality_ender3.def.json" \
-s layer_height=0.2 -s layer_height_0=0.2 \
-s wall_line_count=3 -s top_layers=4 -s bottom_layers=4 -s initial_bottom_layers=4 \
-s infill_pattern=gyroid -s infill_sparse_density=15 \
-s infill_line_distance=3.0 -s infill_line_width=0.4 -s infill_sparse_thickness=0.2 \
-s support_enable=true -s support_structure=normal -s support_type=buildplate \
-s support_angle=50 -s adhesion_type=none \
-s roofing_layer_count=0 -s flooring_layer_count=0 \
-e0 -s machine_nozzle_size=0.4 -s material_diameter=1.75 \
-l "corgi-$size.stl" -o "corgi-$size.gcode" >"corgi-$size.log" 2>&1
done
3. Read the completed estimates
In these standalone runs, the first G-code header contained the same ;TIME:6666 and ;Filament used: 0m for all three sizes. The final CuraEngine log had the estimates below. For automated comparisons, check the engine exit status and log errors, then capture the final Print time (s) and Filament (mm^3) lines.
| Final height | Time (s) | Filament (m) | Extruded volume (cm³) |
|---|---|---|---|
| 60 mm | 6717 | 7.60 | 18.29 |
| 80 mm | 12535 | 14.95 | 35.97 |
| 100 mm | 20677 | 25.63 | 61.65 |
These numbers depend on the printer definition and settings. Run the same comparison with your own configuration if the estimates are going into a build schedule. Before printing, inspect the layer preview around overhangs and small details. CuraEngine source and documentation.
來源:DEV Community · dev.to