With the bmesh
module, I added a custom data layer to a mesh, holding information for each face.
bm = bmesh.new()
collision_flag_layer = bm.faces.layers.int.new("collision_flags")
for triangle in model.triangles:
vertices = model.get_triangle_vertices(triangle)
vert1 = bm.verts.new(vertices[0])
vert2 = bm.verts.new(vertices[1])
vert3 = bm.verts.new(vertices[2])
face = bm.faces.new((vert1, vert2, vert3))
face[collision_flag_layer] = triangle.collision_flags
Now, in Edit Mode, I created a panel to display this property in label
s:
class MarioKart8EditPanel(bpy.types.Panel):
bl_label = "Mario Kart 8"
bl_region_type = "UI"
bl_space_type = "VIEW_3D"
@classmethod
def poll(cls, context):
# Only allow in edit mode for a selected mesh.
return context.mode == "EDIT_MESH" and context.object is not None and context.object.type == "MESH"
def draw(self, context):
obj = context.object
bm = bmesh.from_edit_mesh(obj.data)
face = bm.faces.active
collision_flag_layer = bm.faces.layers.int.get("collision_flags")
if collision_flag_layer is None or face is None:
self.layout.row().label("No collision face selected.")
else:
#self.layout.prop(face, '["collision_flags"]')
row = self.layout.row()
row.label("Collision Flags")
row.label(str(face[collision_flag_layer]))
That's pretty awesome already, displaying the custom data like this:
However, since this is edit mode, I want the user to be able to edit this value of course. As you might have noticed from my code already, I commented out a line where I failed to create a number picker for this with the layout.prop
method.
How can I implement an edit control for this custom data?