3D Print Toolbox: Add hollow out #105194
@ -833,12 +833,12 @@ class MESH_OT_print3d_hollow(Operator):
|
|||||||
|
|
||||||
offset_direction: EnumProperty(
|
offset_direction: EnumProperty(
|
||||||
items=[
|
items=[
|
||||||
('inside', "Inside", "Offset surface inside of object"),
|
('INSIDE', "Inside", "Offset surface inside of object"),
|
||||||
('outside', "Outside", "Offset surface outside of object"),
|
('OUTSIDE', "Outside", "Offset surface outside of object"),
|
||||||
],
|
],
|
||||||
name="Offset Direction",
|
name="Offset Direction",
|
||||||
description="Where the offset surface is created relative to the object",
|
description="Where the offset surface is created relative to the object",
|
||||||
default='inside',
|
default='INSIDE',
|
||||||
)
|
)
|
||||||
MikhailRachinskiy marked this conversation as resolved
|
|||||||
offset: FloatProperty(
|
offset: FloatProperty(
|
||||||
name="Offset",
|
name="Offset",
|
||||||
MikhailRachinskiy marked this conversation as resolved
Mikhail Rachinskiy
commented
default=1 default=1
|
|||||||
@ -861,6 +861,18 @@ class MESH_OT_print3d_hollow(Operator):
|
|||||||
description="Create hollowed out copy of the object",
|
description="Create hollowed out copy of the object",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
layout.use_property_split = True
|
||||||
|
layout.use_property_decorate = False
|
||||||
|
|
||||||
|
layout.separator()
|
||||||
|
|
||||||
|
layout.prop(self, "offset_direction", expand=True)
|
||||||
|
layout.prop(self, "offset")
|
||||||
|
layout.prop(self, "voxel_size")
|
||||||
|
layout.prop(self, "make_hollow_duplicate")
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pyopenvdb as vdb
|
import pyopenvdb as vdb
|
||||||
@ -883,9 +895,9 @@ class MESH_OT_print3d_hollow(Operator):
|
|||||||
ntris = len(mesh_target.loop_triangles)
|
ntris = len(mesh_target.loop_triangles)
|
||||||
verts = np.zeros(3 * nverts, dtype=np.float32)
|
verts = np.zeros(3 * nverts, dtype=np.float32)
|
||||||
tris = np.zeros(3 * ntris, dtype=np.int32)
|
tris = np.zeros(3 * ntris, dtype=np.int32)
|
||||||
mesh_target.vertices.foreach_get('co', verts)
|
mesh_target.vertices.foreach_get("co", verts)
|
||||||
verts.shape = (-1, 3)
|
verts.shape = (-1, 3)
|
||||||
mesh_target.loop_triangles.foreach_get('vertices', tris)
|
mesh_target.loop_triangles.foreach_get("vertices", tris)
|
||||||
tris.shape = (-1, 3)
|
tris.shape = (-1, 3)
|
||||||
|
|
||||||
# Generate VDB levelset
|
# Generate VDB levelset
|
||||||
@ -895,7 +907,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.offset_direction == '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)
|
||||||
@ -905,12 +917,12 @@ class MESH_OT_print3d_hollow(Operator):
|
|||||||
# Instantiate new object in Blender
|
# Instantiate new object in Blender
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
bpy.ops.object.select_all(action='DESELECT')
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
mesh_offset = bpy.data.meshes.new(mesh_target.name + ' offset')
|
mesh_offset = bpy.data.meshes.new(mesh_target.name + " offset")
|
||||||
mesh_offset.from_pydata(newverts, [], polys)
|
mesh_offset.from_pydata(newverts, [], polys)
|
||||||
|
|
||||||
# For some reason OpenVDB has inverted normals
|
# For some reason OpenVDB has inverted normals
|
||||||
mesh_offset.flip_normals()
|
mesh_offset.flip_normals()
|
||||||
obj_offset = bpy.data.objects.new(obj.name + ' offset', mesh_offset)
|
obj_offset = bpy.data.objects.new(obj.name + " offset", mesh_offset)
|
||||||
obj_offset.matrix_world.translation = obj.matrix_world.translation
|
obj_offset.matrix_world.translation = obj.matrix_world.translation
|
||||||
bpy.context.collection.objects.link(obj_offset)
|
bpy.context.collection.objects.link(obj_offset)
|
||||||
obj_offset.select_set(True)
|
obj_offset.select_set(True)
|
||||||
@ -921,7 +933,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.offset_direction == 'inside':
|
if self.offset_direction == 'INSIDE':
|
||||||
mesh_offset.flip_normals()
|
mesh_offset.flip_normals()
|
||||||
else:
|
else:
|
||||||
mesh_target.flip_normals()
|
mesh_target.flip_normals()
|
||||||
|
Loading…
Reference in New Issue
Block a user
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.
Sorry, my bad. It should be fixed now.