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

Loading…
Cancel
Save