3D Print Toolbox: Add hollow out #105194

Merged
Mikhail Rachinskiy merged 9 commits from usfreitas/blender-addons:hollow into main 2024-03-18 12:24:30 +01:00
3 changed files with 21 additions and 12 deletions
Showing only changes of commit 62e89347f9 - Show all commits

View File

@ -134,9 +134,9 @@ class SceneProperties(PropertyGroup):
min = 0.01,
subtype = 'DISTANCE',
)
hollow_join: BoolProperty(
name = "Join",
description = "Join the generated offset mesh to the original object, effectively hollowing it",
hollow_create: BoolProperty(
name = "Create Hollow Copy",
description = "Create a hollow copy of the target object, with applied modifiers and scale",
default = False
)

View File

@ -843,9 +843,9 @@ class MESH_OT_print3d_hollow(Operator):
min = 0.01,
subtype = 'DISTANCE',
MikhailRachinskiy marked this conversation as resolved

default=1

default=1
)
join: BoolProperty(
name = "Join",
description = "Join the generated offset mesh to the original object, effectively hollowing it",
create_hollow: BoolProperty(
name = "Create Hollow Copy",
description = "Create a hollow copy of the target object, with applied modifiers and scale",
default = False
)
@ -856,11 +856,15 @@ class MESH_OT_print3d_hollow(Operator):
if not self.offset:
return {'FINISHED'}
MikhailRachinskiy marked this conversation as resolved

It's better to not create unnecessary local variables, especially when they are rarely used.

It's better to not create unnecessary local variables, especially when they are rarely used.
# Target object
# Get target mesh with modifiers
obj = context.active_object
depsgraph = context.evaluated_depsgraph_get()
mesh_target = bpy.data.meshes.new_from_object(obj.evaluated_get(depsgraph))
mesh_target.transform(obj.matrix_world)
# Apply scale, but avoid translating the mesh
mat = obj.matrix_world.copy()
mat.translation = 0, 0, 0
mesh_target.transform(mat)
# Read mesh to numpy arrays
nverts = len(mesh_target.vertices)
@ -888,13 +892,15 @@ class MESH_OT_print3d_hollow(Operator):
obj_offset = bpy.data.objects.new(obj.name + ' offset', mesh_offset)
bpy.context.collection.objects.link(obj_offset)
if not self.join:
if not self.create_hollow:
# For some reason OpenVDB has inverted normals
mesh_offset.flip_normals()
# Translate surface object to target object's position
obj_offset.matrix_world.translation = obj.matrix_world.translation
# This mesh will not be used anymore
bpy.data.meshes.remove(mesh_target)
else:
# Create a copy of the target object with applied modifiers, scale
# Create a copy of the target object with applied modifiers and scale
obj_hollow = bpy.data.objects.new(obj.name + " hollow", mesh_target)
bpy.context.collection.objects.link(obj_hollow)
if self.offset < 0.0:
@ -913,6 +919,9 @@ class MESH_OT_print3d_hollow(Operator):
context.view_layer.objects.active = obj_hollow
bpy.ops.object.join()
# Translate hollow object to target object's position
obj_hollow.matrix_world.translation = obj.matrix_world.translation
return {'FINISHED'}
@ -920,7 +929,7 @@ class MESH_OT_print3d_hollow(Operator):
print_3d = context.scene.print_3d
self.offset = print_3d.hollow_offset
self.resolution = print_3d.hollow_resolution
self.join = print_3d.hollow_join
self.create_hollow = print_3d.hollow_create
if context.mode == 'EDIT_MESH':
bpy.ops.object.mode_set(mode='OBJECT')

View File

@ -120,7 +120,7 @@ class VIEW3D_PT_print3d_transform(View3DPrintPanel, Panel):
row.prop(print_3d, "use_alignxy_face_area")
layout.label(text="Hollow")
col = layout.column(align=True)
col.prop(print_3d, "hollow_join")
col.prop(print_3d, "hollow_create")
col.prop(print_3d, "hollow_offset")
col.prop(print_3d, "hollow_resolution")
col.operator("mesh.print3d_hollow", text="Create Offset Surface")