fix: use scene scale correctly in Gcode to Preview Mesh node
This commit is contained in:
parent
2eaafd0c97
commit
6ac6fef685
1 changed files with 9 additions and 4 deletions
|
|
@ -34,6 +34,11 @@ class SLICENODE_GcodeToMesh(ExecSliceNode):
|
|||
edges = []
|
||||
e_rates = []
|
||||
|
||||
scale_length = 1.0
|
||||
if bpy.context.scene and bpy.context.scene.unit_settings:
|
||||
scale_length = bpy.context.scene.unit_settings.scale_length
|
||||
scale_factor = 0.001 / scale_length
|
||||
|
||||
last_x, last_y, last_z = 0.0, 0.0, 0.0
|
||||
last_e = 0.0
|
||||
|
||||
|
|
@ -71,10 +76,10 @@ class SLICENODE_GcodeToMesh(ExecSliceNode):
|
|||
for p in parts[1:]:
|
||||
if len(p) < 2: continue
|
||||
try:
|
||||
# Scale coordinates by 0.001 (mm to Blender units)
|
||||
# Scale coordinates by scene scale factor (mm to Blender units)
|
||||
val = float(p[1:])
|
||||
if p[0].upper() in 'XYZ':
|
||||
val *= 0.001
|
||||
val *= scale_factor
|
||||
params[p[0].upper()] = val
|
||||
except ValueError: continue
|
||||
|
||||
|
|
@ -89,12 +94,12 @@ class SLICENODE_GcodeToMesh(ExecSliceNode):
|
|||
|
||||
if show:
|
||||
# Subtract offsets (scaled to Blender units) to return to original space
|
||||
ox, oy = offset_x * 0.001, offset_y * 0.001
|
||||
ox, oy = offset_x * scale_factor, offset_y * scale_factor
|
||||
p1 = (last_x - ox, last_y - oy, last_z)
|
||||
p2 = (new_x - ox, new_y - oy, new_z)
|
||||
|
||||
# Calculate e_rate (proportion between E and default_extrusion_rate)
|
||||
seg_len_mm = segment_length_3d(p1, p2) * 1000.0
|
||||
seg_len_mm = segment_length_3d(p1, p2) * (1000.0 * scale_length)
|
||||
if seg_len_mm > 0 and custom_default_extrusion_rate > 0:
|
||||
e_rate = (new_e / seg_len_mm) / custom_default_extrusion_rate
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue