Browse Source

Allow custom names for ladder stems

pull/64/head
Adam Johnson 7 years ago
parent
commit
b3474effc6
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 47
      korman/operators/op_mesh.py

47
korman/operators/op_mesh.py

@ -31,6 +31,11 @@ class PlasmaAddLadderMeshOperator(PlasmaMeshOperator, bpy.types.Operator):
bl_description = "Adds a new Plasma Ladder"
bl_options = {"REGISTER", "UNDO"}
# Allows user to specify their own name stem
ladder_name = bpy.props.StringProperty(name="Name",
description="Ladder name stem",
default="Ladder")
# Basic stats
ladder_height = bpy.props.FloatProperty(name="Height",
description="Height of ladder in feet",
@ -74,10 +79,16 @@ class PlasmaAddLadderMeshOperator(PlasmaMeshOperator, bpy.types.Operator):
def draw(self, context):
layout = self.layout
space = bpy.context.space_data
if (not space.local_view):
if not space.local_view:
box = layout.box()
box.label("Geometry:")
box.label("Ladder Name:")
row = box.row()
row.alert = not self.ladder_name
row.prop(self, "ladder_name", text="")
box = layout.box()
box.label("Geometry:")
row = box.row()
row.alert = self.ladder_height % 2 != 0
row.prop(self, "ladder_height")
@ -116,13 +127,12 @@ class PlasmaAddLadderMeshOperator(PlasmaMeshOperator, bpy.types.Operator):
row.label("Warning: Operator does not work in local view mode", icon="ERROR")
def execute(self, context):
if bpy.context.mode == "OBJECT":
if context.mode == "OBJECT":
self.create_ladder_objects()
return {"FINISHED"}
else:
self.report({"WARNING"}, "Ladder creation only valid in Object mode")
return {"CANCELLED"}
return {"FINISHED"}
def create_guide_rungs(self):
bpyscene = bpy.context.scene
@ -146,8 +156,8 @@ class PlasmaAddLadderMeshOperator(PlasmaMeshOperator, bpy.types.Operator):
for rung_num in range(0, int(self.ladder_height)):
side = "L" if (rung_num % 2) == 0 else "R"
mesh = bpy.data.meshes.new("LadderRung_{}_{}".format(side, rung_num))
rungs = bpy.data.objects.new("LadderRung_{}_{}".format(side, rung_num), mesh)
mesh = bpy.data.meshes.new("{}_Rung_{}_{}".format(self.name_stem, side, rung_num))
rungs = bpy.data.objects.new("{}_Rung_{}_{}".format(self.name_stem, side, rung_num), mesh)
rungs.hide_render = True
rungs.draw_type = "BOUNDS"
@ -174,8 +184,9 @@ class PlasmaAddLadderMeshOperator(PlasmaMeshOperator, bpy.types.Operator):
cursor_shift = mathutils.Matrix.Translation(bpy.context.scene.cursor_location)
# Create an empty mesh and the object.
mesh = bpy.data.meshes.new("LadderBack")
back = bpy.data.objects.new("LadderBack", mesh)
name = "{}_Back".format(self.name_stem)
mesh = bpy.data.meshes.new(name)
back = bpy.data.objects.new(name, mesh)
back.hide_render = True
back.draw_type = "BOUNDS"
@ -205,8 +216,9 @@ class PlasmaAddLadderMeshOperator(PlasmaMeshOperator, bpy.types.Operator):
for pos in ("Upper", "Lower"):
# Create an empty mesh and the object.
mesh = bpy.data.meshes.new("LadderGround_{}".format(pos))
ground = bpy.data.objects.new("LadderGround_{}".format(pos), mesh)
name = "{}_Ground_{}".format(self.name_stem, pos)
mesh = bpy.data.meshes.new(name)
ground = bpy.data.objects.new(name, mesh)
ground.hide_render = True
ground.draw_type = "BOUNDS"
@ -238,8 +250,9 @@ class PlasmaAddLadderMeshOperator(PlasmaMeshOperator, bpy.types.Operator):
cursor_shift = mathutils.Matrix.Translation(bpy.context.scene.cursor_location)
# Create an empty mesh and the object.
mesh = bpy.data.meshes.new("LadderEntry_Upper")
upper_rgn = bpy.data.objects.new("LadderEntry_Upper", mesh)
name = "{}_Entry_Upper".format(self.name_stem)
mesh = bpy.data.meshes.new(name)
upper_rgn = bpy.data.objects.new(name, mesh)
upper_rgn.hide_render = True
upper_rgn.draw_type = "WIRE"
@ -278,8 +291,9 @@ class PlasmaAddLadderMeshOperator(PlasmaMeshOperator, bpy.types.Operator):
cursor_shift = mathutils.Matrix.Translation(bpy.context.scene.cursor_location)
# Create an empty mesh and the object.
mesh = bpy.data.meshes.new("LadderEntry_Lower")
lower_rgn = bpy.data.objects.new("LadderEntry_Lower", mesh)
name = "{}_Entry_Lower".format(self.name_stem)
mesh = bpy.data.meshes.new(name)
lower_rgn = bpy.data.objects.new(name, mesh)
lower_rgn.hide_render = True
lower_rgn.draw_type = "WIRE"
@ -334,6 +348,9 @@ class PlasmaAddLadderMeshOperator(PlasmaMeshOperator, bpy.types.Operator):
bpy.ops.group.create(name="LadderGroup")
bpy.ops.group.objects_add_active()
@property
def name_stem(self):
return self.ladder_name if self.ladder_name else "Ladder"
def origin_to_bottom(obj):
# Modified from https://blender.stackexchange.com/a/42110/3055

Loading…
Cancel
Save