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
2 changed files with 14 additions and 39 deletions
Showing only changes of commit 0e9582d3b7 - Show all commits

View File

@ -129,23 +129,6 @@ class SceneProperties(PropertyGroup):
min=0.0, min=0.0,
step=1, step=1,
) )
hollow_voxel_size: FloatProperty(
name="Voxel size",
description="Size of the voxel used for volume evaluation. Lower values preserve finer details",
default=1.0,
min=0.0001,
step=1,
subtype='DISTANCE',
)
make_hollow_duplicate: BoolProperty(
name="Hollow Duplicate",
description="Create hollowed out copy of the object",
)
make_hollow_inside: BoolProperty(
name="Inside",
description="Offset surface inside of the object",
default=True,
)
classes = ( classes = (

View File

@ -13,6 +13,7 @@ from bpy.props import (
IntProperty, IntProperty,
FloatProperty, FloatProperty,
BoolProperty, BoolProperty,
EnumProperty,
) )
import bmesh import bmesh
@ -828,8 +829,17 @@ class MESH_OT_print3d_hollow(Operator):
bl_idname = "mesh.print3d_hollow" bl_idname = "mesh.print3d_hollow"
bl_label = "Hollow" bl_label = "Hollow"
bl_description = "Create offset surface" bl_description = "Create offset surface"
bl_options = {'REGISTER', 'UNDO'} bl_options = {'REGISTER', 'UNDO', 'PRESET'}
offset_direction: EnumProperty(
items=[
('inside', "Inside", "Offset surface inside of object"),
('outside', "Outside", "Offset surface outside of object"),
],
name="Offset Direction",
description="Where the offset surface is created relative to the object",
default='inside',
)
MikhailRachinskiy marked this conversation as resolved

Enum values are supposed to be in UPPERCASE


I noticed inconsistent use of double vs single quotation marks, Blender code guidelines recommends: single quotes when using enum values, double quotes everything else.

Enum values are supposed to be in `UPPERCASE` --- I noticed inconsistent use of double vs single quotation marks, Blender code guidelines recommends: single quotes when using enum values, double quotes everything else.
Review

Sorry, my bad. It should be fixed now.

Sorry, my bad. It should be fixed now.
offset: FloatProperty( offset: FloatProperty(
name="Offset", name="Offset",
MikhailRachinskiy marked this conversation as resolved

default=1

default=1
description="Surface offset in relation to original mesh", description="Surface offset in relation to original mesh",
@ -841,7 +851,7 @@ class MESH_OT_print3d_hollow(Operator):
voxel_size: FloatProperty( voxel_size: FloatProperty(
name="Voxel size", name="Voxel size",
description="Size of the voxel used for volume evaluation. Lower values preserve finer details", description="Size of the voxel used for volume evaluation. Lower values preserve finer details",
default=5.0, default=1.0,
min=0.0001, min=0.0001,
step=1, step=1,
subtype='DISTANCE', subtype='DISTANCE',
@ -850,11 +860,6 @@ class MESH_OT_print3d_hollow(Operator):
name="Hollow Duplicate", name="Hollow Duplicate",
description="Create hollowed out copy of the object", description="Create hollowed out copy of the object",
) )
make_hollow_inside: BoolProperty(
name="Inside",
description="Offset surface inside of the object",
default=True,
)
def execute(self, context): def execute(self, context):
import numpy as np import numpy as np
@ -890,7 +895,7 @@ class MESH_OT_print3d_hollow(Operator):
levelset = vdb.FloatGrid.createLevelSetFromPolygons(verts, triangles=tris, transform=trans, halfWidth=half_width) levelset = vdb.FloatGrid.createLevelSetFromPolygons(verts, triangles=tris, transform=trans, halfWidth=half_width)
# Generate offset surface # Generate offset surface
if self.make_hollow_inside: if self.offset_direction == 'inside':
newverts, newquads = levelset.convertToQuads(-self.offset) newverts, newquads = levelset.convertToQuads(-self.offset)
else: else:
newverts, newquads = levelset.convertToQuads(self.offset) newverts, newquads = levelset.convertToQuads(self.offset)
@ -916,7 +921,7 @@ class MESH_OT_print3d_hollow(Operator):
bpy.context.collection.objects.link(obj_hollow) bpy.context.collection.objects.link(obj_hollow)
obj_hollow.matrix_world.translation = obj.matrix_world.translation obj_hollow.matrix_world.translation = obj.matrix_world.translation
obj_hollow.select_set(True) obj_hollow.select_set(True)
if self.make_hollow_inside: if self.offset_direction == 'inside':
mesh_offset.flip_normals() mesh_offset.flip_normals()
else: else:
mesh_target.flip_normals() mesh_target.flip_normals()
@ -925,23 +930,10 @@ class MESH_OT_print3d_hollow(Operator):
else: else:
bpy.data.meshes.remove(mesh_target) bpy.data.meshes.remove(mesh_target)
print_3d = context.scene.print_3d
print_3d.hollow_offset = self.offset
print_3d.hollow_voxel_size = self.voxel_size
print_3d.make_hollow_duplicate = self.make_hollow_duplicate
print_3d.make_hollow_inside = self.make_hollow_inside
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event): def invoke(self, context, event):
print_3d = context.scene.print_3d
self.offset = print_3d.hollow_offset
self.voxel_size = print_3d.hollow_voxel_size
self.make_hollow_duplicate = print_3d.make_hollow_duplicate
self.make_hollow_inside = print_3d.make_hollow_inside
if context.mode == 'EDIT_MESH': if context.mode == 'EDIT_MESH':
bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.mode_set(mode='OBJECT')
wm = context.window_manager wm = context.window_manager
return wm.invoke_props_dialog(self) return wm.invoke_props_dialog(self)