diff options
author | lijenstina <lijenstina@gmail.com> | 2017-06-10 00:06:28 +0300 |
---|---|---|
committer | lijenstina <lijenstina@gmail.com> | 2017-06-10 00:06:28 +0300 |
commit | aa8f255c0eaf31b2665d6adf0569da4892d8d1a4 (patch) | |
tree | c2bfef22a0c8b3329d45e93f8722b2e2f3884c90 /add_mesh_extra_objects/add_mesh_pyramid.py | |
parent | 84baf76f48e023eafde8d567490b7b0ba901e9fb (diff) |
Add Mesh Extra Objects: Update, Fix crash with Wall Factory
Bumped version to 0.3.2
Wall Factory:
Fix crash with Wall Factory when openings and slots
are enabled (unorderable types: opening() < opening())
with the repeat option on as the sort function compared
stored classes instead of the numerical values
Fix the module not working properly after (F8) reload
Cleanup - consistent prop definitions
Remove star imports
Small UI reorganization to save vertical space
The code will probably need some further refactor
as the usage of globals is not so clear
add_mesh_triangles:
cleanup, remove unused vars add missing GPL notice,
some UI tweaks, add tooltip
add_mesh_pyramid: indentation cleanup
add_mesh_beam_builder: add an option to snap to cursor
add_mesh_teapot: use defs instead of assigning lambdas (E731)
Diffstat (limited to 'add_mesh_extra_objects/add_mesh_pyramid.py')
-rw-r--r-- | add_mesh_extra_objects/add_mesh_pyramid.py | 152 |
1 files changed, 80 insertions, 72 deletions
diff --git a/add_mesh_extra_objects/add_mesh_pyramid.py b/add_mesh_extra_objects/add_mesh_pyramid.py index 5c054c9f..680267cb 100644 --- a/add_mesh_extra_objects/add_mesh_pyramid.py +++ b/add_mesh_extra_objects/add_mesh_pyramid.py @@ -2,35 +2,43 @@ import bpy import bmesh +from bpy.types import Operator from bpy.props import ( FloatProperty, IntProperty, ) from math import pi -from mathutils import Quaternion, Vector -from bpy_extras.object_utils import AddObjectHelper, object_data_add +from mathutils import ( + Quaternion, + Vector, + ) +from bpy_extras.object_utils import ( + AddObjectHelper, + object_data_add, + ) def create_step(width, base_level, step_height, num_sides): - axis = [0, 0, -1] - PI2 = pi * 2 - rad = width / 2 + axis = [0, 0, -1] + PI2 = pi * 2 + rad = width / 2 + + quat_angles = [(cur_side / num_sides) * PI2 + for cur_side in range(num_sides)] - quat_angles = [(cur_side / num_sides) * PI2 - for cur_side in range(num_sides)] + quaternions = [Quaternion(axis, quat_angle) + for quat_angle in quat_angles] - quaternions = [Quaternion(axis, quat_angle) - for quat_angle in quat_angles] + init_vectors = [Vector([rad, 0, base_level])] * len(quaternions) - init_vectors = [Vector([rad, 0, base_level])] * len(quaternions) + quat_vector_pairs = list(zip(quaternions, init_vectors)) + vectors = [quaternion * vec for quaternion, vec in quat_vector_pairs] + bottom_list = [(vec.x, vec.y, vec.z) for vec in vectors] + top_list = [(vec.x, vec.y, vec.z + step_height) for vec in vectors] + full_list = bottom_list + top_list - quat_vector_pairs = list(zip(quaternions, init_vectors)) - vectors = [quaternion * vec for quaternion, vec in quat_vector_pairs] - bottom_list = [(vec.x, vec.y, vec.z) for vec in vectors] - top_list = [(vec.x, vec.y, vec.z + step_height) for vec in vectors] - full_list = bottom_list + top_list - return full_list + return full_list def split_list(l, n): @@ -52,83 +60,83 @@ def get_connector_pairs(lst, n_sides): def add_pyramid_object(self, context): - all_verts = [] + all_verts = [] - height_offset = 0 - cur_width = self.width + height_offset = 0 + cur_width = self.width - for i in range(self.num_steps): - verts_loc = create_step(cur_width, height_offset, self.height, - self.num_sides) - height_offset += self.height - cur_width -= self.reduce_by - all_verts.extend(verts_loc) + for i in range(self.num_steps): + verts_loc = create_step(cur_width, height_offset, self.height, + self.num_sides) + height_offset += self.height + cur_width -= self.reduce_by + all_verts.extend(verts_loc) - mesh = bpy.data.meshes.new("Pyramid") - bm = bmesh.new() + mesh = bpy.data.meshes.new("Pyramid") + bm = bmesh.new() - for v_co in all_verts: - bm.verts.new(v_co) + for v_co in all_verts: + bm.verts.new(v_co) - def add_faces(n, block_vert_sets): - for bvs in block_vert_sets: - for i in range(self.num_sides - 1): - bm.faces.new([bvs[i], bvs[i + n], bvs[i + n + 1], bvs[i + 1]]) - bm.faces.new([bvs[n - 1], bvs[(n * 2) - 1], bvs[n], bvs[0]]) + def add_faces(n, block_vert_sets): + for bvs in block_vert_sets: + for i in range(self.num_sides - 1): + bm.faces.new([bvs[i], bvs[i + n], bvs[i + n + 1], bvs[i + 1]]) + bm.faces.new([bvs[n - 1], bvs[(n * 2) - 1], bvs[n], bvs[0]]) - # get the base and cap faces done. - bm.faces.new(bm.verts[0:self.num_sides]) - bm.faces.new(reversed(bm.verts[-self.num_sides:])) # otherwise normal faces intern... T44619. + # get the base and cap faces done. + bm.faces.new(bm.verts[0:self.num_sides]) + bm.faces.new(reversed(bm.verts[-self.num_sides:])) # otherwise normal faces intern... T44619. - # side faces - block_vert_sets = split_list(bm.verts, self.num_sides) - add_faces(self.num_sides, block_vert_sets) + # side faces + block_vert_sets = split_list(bm.verts, self.num_sides) + add_faces(self.num_sides, block_vert_sets) - # connector faces between faces and faces of the block above it. - connector_pairs = get_connector_pairs(bm.verts, self.num_sides) - add_faces(self.num_sides, connector_pairs) + # connector faces between faces and faces of the block above it. + connector_pairs = get_connector_pairs(bm.verts, self.num_sides) + add_faces(self.num_sides, connector_pairs) - bm.to_mesh(mesh) - mesh.update() - res = object_data_add(context, mesh, operator=self) + bm.to_mesh(mesh) + mesh.update() + res = object_data_add(context, mesh, operator=self) -class AddPyramid(bpy.types.Operator, AddObjectHelper): +class AddPyramid(Operator, AddObjectHelper): bl_idname = "mesh.primitive_steppyramid_add" bl_label = "Pyramid" bl_description = "Construct a step pyramid mesh" bl_options = {'REGISTER', 'UNDO', 'PRESET'} num_sides = IntProperty( - name="Number Sides", - description="How many sides each step will have", - min=3, max=20, - default=4 - ) + name="Number Sides", + description="How many sides each step will have", + min=3, max=20, + default=4 + ) num_steps = IntProperty( - name="Number of Steps", - description="How many steps for the overall pyramid", - min=1, max=20, - default=10 - ) + name="Number of Steps", + description="How many steps for the overall pyramid", + min=1, max=20, + default=10 + ) width = FloatProperty( - name="Initial Width", - description="Initial base step width", - min=0.01, max=100.0, - default=2 - ) + name="Initial Width", + description="Initial base step width", + min=0.01, max=100.0, + default=2 + ) height = FloatProperty( - name="Height", - description="How tall each step will be", - min=0.01, max=100.0, - default=0.1 - ) + name="Height", + description="How tall each step will be", + min=0.01, max=100.0, + default=0.1 + ) reduce_by = FloatProperty( - name="Reduce Step By", - description="How much to reduce each succeeding step by", - min=.01, max=2.0, - default=.20 - ) + name="Reduce Step By", + description="How much to reduce each succeeding step by", + min=.01, max=2.0, + default=.20 + ) def execute(self, context): add_pyramid_object(self, context) |