Skip to content

Commit

Permalink
Migrate to Blender 2.8
Browse files Browse the repository at this point in the history
* Properties now have to be type annotations
* material.diffuse_color needs 4th value (for alpha?)
* materials.pop() doesnt take update_data anymore, use .clear() instead
  • Loading branch information
kugelrund committed Jul 6, 2020
1 parent 87c250a commit 33514e7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
59 changes: 30 additions & 29 deletions src/mesh_segmentation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bl_info = {
"name": "Mesh Segmentation",
"description": "Segments an object and applies an action on each segment",
"blender": (2, 80, 0),
"category": "Mesh"}

import bpy
Expand All @@ -20,38 +21,38 @@ class MeshSegmentation(bpy.types.Operator):
bl_options = {'REGISTER', 'UNDO'}

# parameters
action = bpy.props.EnumProperty(name ="Action",
items = [('assignMaterials',
action: bpy.props.EnumProperty(name ="Action",
items = [('assignMaterials',
"Assign materials",
"Assigns a different material for "
"each found segment")],
description = "What to do with the "
"segmentation",
default = 'assignMaterials')
k = bpy.props.IntProperty(name = "Clusters",
description = "Amount of clusters",
min = 2,
default = 2)
delta = bpy.props.FloatProperty(name = "Delta",
description = "Set close to zero for more "
"importance on the angular "
"distance, set close to one "
"for more importance on the "
"geodesic distance.",
default = 0.03,
min = 0,
max = 1,
subtype = 'FACTOR')
eta = bpy.props.FloatProperty(name = "Weight of convexity",
description = "Set close to zero for more "
"importance on concave angles, "
"set close to one to treat "
"concave and convex angles "
"equally.",
default = 0.15,
min = 1e-10,
max = 1,
subtype = 'FACTOR')
description = "What to do with the "
"segmentation",
default = 'assignMaterials')
k: bpy.props.IntProperty(name = "Clusters",
description = "Amount of clusters",
min = 2,
default = 2)
delta: bpy.props.FloatProperty(name = "Delta",
description = "Set close to zero for more "
"importance on the angular "
"distance, set close to one "
"for more importance on the "
"geodesic distance.",
default = 0.03,
min = 0,
max = 1,
subtype = 'FACTOR')
eta: bpy.props.FloatProperty(name = "Weight of convexity",
description = "Set close to zero for more "
"importance on concave angles, "
"set close to one to treat "
"concave and convex angles "
"equally.",
default = 0.15,
min = 1e-10,
max = 1,
subtype = 'FACTOR')

def execute(self, context):
"""Executes the segmentation"""
Expand Down
8 changes: 3 additions & 5 deletions src/mesh_segmentation/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ def assignMaterials(mesh, k, idx):
"""Assigns a random colored material for each found segment"""

# clear all existing materials
while mesh.materials:
mesh.materials.pop(0, update_data=True)
mesh.materials.clear()

for i in range(k):
material = bpy.data.materials.new(''.join(['mat', mesh.name, str(i)]))
material.diffuse_color = (random.random(),
random.random(),
random.random())
material.diffuse_color = (random.random(), random.random(),
random.random(), 1.0)
mesh.materials.append(material)

for i, id in enumerate(idx):
Expand Down

0 comments on commit 33514e7

Please sign in to comment.