Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijenstina <lijenstina@gmail.com>2016-12-30 22:33:05 +0300
committerlijenstina <lijenstina@gmail.com>2016-12-30 22:33:05 +0300
commitc86080a455579a8c770545e33b95513b43e1a43b (patch)
tree6c392b16b914aa3264b373022602e57ad493e7d7 /add_mesh_extra_objects/add_mesh_honeycomb.py
parentc95e86bcef654c0686d3cf4d52446ff9ff8c819f (diff)
Add mesh extra objects: Update to version 0.3.1
General Pep8 cleanup Removed unused variables and imports Removed a panel from add_empty_as_parent Standardized the property definitions across all the scripts Moved scene props from third_domes_panel_271 to init for proper removal Added a Enum prop for mesh type in teapot Fixed a small issue with Geodesic domes self.reports (problem with value fields message spam) Fixed props names in Geodesic domes Consistent tooltips Reorganized menus: Mechanical Menu including Pipe joints, Mesh gear Added separators
Diffstat (limited to 'add_mesh_extra_objects/add_mesh_honeycomb.py')
-rw-r--r--add_mesh_extra_objects/add_mesh_honeycomb.py159
1 files changed, 97 insertions, 62 deletions
diff --git a/add_mesh_extra_objects/add_mesh_honeycomb.py b/add_mesh_extra_objects/add_mesh_honeycomb.py
index 3e30afe7..e93b3b86 100644
--- a/add_mesh_extra_objects/add_mesh_honeycomb.py
+++ b/add_mesh_extra_objects/add_mesh_honeycomb.py
@@ -1,6 +1,16 @@
# GPL # "author": "Kayo Phoenix"
+import bpy
+from bpy_extras import object_utils
from math import pi, sin, cos
+from bpy.props import (
+ IntProperty,
+ BoolProperty,
+ BoolVectorProperty,
+ FloatProperty,
+ FloatVectorProperty,
+ )
+
class honeycomb_geometry():
def __init__(self, rows, cols, D, E):
@@ -21,7 +31,6 @@ class honeycomb_geometry():
self.r = self.R - self.e
self.hr = 0.5 * self.r
-
self.H = self.R * (1.5 * self.rows + 0.5) + self.e
if self.rows > 1:
self.W = self.d * (self.cols + 0.5) + self.E
@@ -41,47 +50,64 @@ class honeycomb_geometry():
def vert(self, row, col):
# full cell
- if row >= 0 and row < self.rows and col >= 0 and col < self.cols: return [0, 1, 2, 3, 4, 5]
+ if row >= 0 and row < self.rows and col >= 0 and col < self.cols:
+ return [0, 1, 2, 3, 4, 5]
# right down corner
- if row == -1 and col == self.cols - 1: return [1, 2]
- if row == 0 and self.rows > 1 and col == self.cols: return [1, 2, 3]
+ if row == -1 and col == self.cols - 1:
+ return [1, 2]
+ if row == 0 and self.rows > 1 and col == self.cols:
+ return [1, 2, 3]
# left down corner
- if row == -1 and col == -1: return [0, 1]
+ if row == -1 and col == -1:
+ return [0, 1]
if self.rows % 2:
# left up corner
- if row == self.rows and col == -1: return [4, 5]
+ if row == self.rows and col == -1:
+ return [4, 5]
# right up corner
- if row == self.rows and col == self.cols - 1: return [3, 4]
- if row == self.rows - 1 and self.rows > 1 and col == self.cols: return [2, 3, 4]
+ if row == self.rows and col == self.cols - 1:
+ return [3, 4]
+ if row == self.rows - 1 and self.rows > 1 and col == self.cols:
+ return [2, 3, 4]
else:
# left up corner
- if row == self.rows and col == 0: return [4, 5]
- if row == self.rows - 1 and self.rows > 1 and col == -1: return [0, 4, 5]
+ if row == self.rows and col == 0:
+ return [4, 5]
+ if row == self.rows - 1 and self.rows > 1 and col == -1:
+ return [0, 4, 5]
# right up corner
- if row == self.rows and col == self.cols: return [3, 4]
+ if row == self.rows and col == self.cols:
+ return [3, 4]
# horizontal lines
if col >= 0 and col < self.cols:
- if row == -1: return [0, 1, 2]
- if row == self.rows: return [3, 4, 5]
+ if row == -1:
+ return [0, 1, 2]
+ if row == self.rows:
+ return [3, 4, 5]
# vertical lines
if row >= 0 and row < self.rows:
if col == -1:
- if row % 2: return [0, 1, 4, 5]
- else: return [0, 5]
+ if row % 2:
+ return [0, 1, 4, 5]
+ else:
+ return [0, 5]
if col == self.cols:
- if row % 2 or self.rows == 1: return [2, 3]
- else: return [1, 2, 3, 4]
+ if row % 2 or self.rows == 1:
+ return [2, 3]
+ else:
+ return [1, 2, 3, 4]
return []
def cell(self, row, col, idx):
- cp = [self.sx + self.dx * col, self.sy + self.dy * row, 0] # central point
- if row % 2: cp[0] += self.gx
- co = [] # vertexes coords
+ cp = [self.sx + self.dx * col, self.sy + self.dy * row, 0] # central point
+ if row % 2:
+ cp[0] += self.gx
+ co = [] # vertices coords
vi = self.vert(row, col)
ap = {}
for i in vi:
- a = pi / 6 + i * pi / 3 # angle
+ a = pi / 6 + i * pi / 3 # angle
ap[i] = idx + len(co)
co.append((cp[0] + cos(a) * self.r, cp[1] + sin(a) * self.r, cp[2]))
return co, ap
@@ -115,7 +141,8 @@ class honeycomb_geometry():
# top row
row = len(cells) - 1
cs = 0
- if row % 2: cs += 1
+ if row % 2:
+ cs += 1
for col in range(1 + cs, len(cells[row]) - 1):
s = cells[row][col]
l = cells[row][col - 1]
@@ -126,7 +153,8 @@ class honeycomb_geometry():
# middle rows
for row in range(1, len(cells) - 1):
cs = 0
- if row % 2: cs += 1
+ if row % 2:
+ cs += 1
for col in range(1, len(cells[row]) - 1):
s = cells[row][col]
l = cells[row][col - 1]
@@ -144,7 +172,8 @@ class honeycomb_geometry():
col = len(cells[row]) - 1
for row in range(1, len(cells) - 1):
cs = 0
- if row % 2: cs += 1
+ if row % 2:
+ cs += 1
s = cells[row][col]
l = cells[row][col - 1]
@@ -170,72 +199,78 @@ class honeycomb_geometry():
return verts, faces
-import bpy
-from bpy.props import *
-from bpy_extras import object_utils
def edge_max(diam):
return diam * sin(pi / 3)
+
class add_mesh_honeycomb(bpy.types.Operator):
- """Simple honeycomb mesh generator"""
- bl_idname = 'mesh.honeycomb_add'
- bl_label = 'Add HoneyComb'
+ bl_idname = "mesh.honeycomb_add"
+ bl_label = "Add HoneyComb"
+ bl_description = "Simple honeycomb mesh generator"
bl_options = {'REGISTER', 'UNDO'}
+ def fix_edge(self, context):
+ m = edge_max(self.diam)
+ if self.edge > m:
+ self.edge = m
+
rows = IntProperty(
- name = 'Num of rows', default = 2,
- min = 1, max = 100,
- description='Number of the rows')
+ name="Num of rows",
+ default=2,
+ min=1, max=100,
+ description='Number of the rows'
+ )
cols = IntProperty(
- name = 'Num of cols', default = 2,
- min = 1, max = 100,
- description='Number of the columns')
+ name='Num of cols',
+ default=2,
+ min=1, max=100,
+ description='Number of the columns'
+ )
layers = BoolVectorProperty(
- name="Layers",
- size=20,
- subtype='LAYER',
- options={'HIDDEN', 'SKIP_SAVE'},
- )
- def fix_edge(self, context):
- m = edge_max(self.diam)
- if self.edge > m: self.edge = m
-
+ name="Layers",
+ size=20,
+ subtype='LAYER',
+ options={'HIDDEN', 'SKIP_SAVE'},
+ )
diam = FloatProperty(
- name = 'Cell Diameter', default = 1.0,
- min = 0.0, update = fix_edge,
- description='Diameter of the cell')
-
+ name='Cell Diameter',
+ default=1.0,
+ min=0.0, update=fix_edge,
+ description='Diameter of the cell'
+ )
edge = FloatProperty(
- name = 'Edge Width', default = 0.1,
- min = 0.0, update = fix_edge,
- description='Width of the edge')
-
+ name='Edge Width',
+ default=0.1,
+ min=0.0, update=fix_edge,
+ description='Width of the edge'
+ )
# generic transform props
view_align = BoolProperty(
- name="Align to View",
- default=False)
+ name="Align to View",
+ default=False
+ )
location = FloatVectorProperty(
- name="Location",
- subtype='TRANSLATION')
+ name="Location",
+ subtype='TRANSLATION'
+ )
rotation = FloatVectorProperty(
- name="Rotation",
- subtype='EULER')
+ name="Rotation",
+ subtype='EULER'
+ )
- ##### POLL #####
@classmethod
def poll(cls, context):
return context.scene is not None
- ##### EXECUTE #####
def execute(self, context):
mesh = bpy.data.meshes.new(name='honeycomb')
comb = honeycomb_geometry(self.rows, self.cols, self.diam, self.edge)
verts, faces = comb.generate()
- mesh.from_pydata(vertices = verts, edges = [], faces = faces)
+ mesh.from_pydata(vertices=verts, edges=[], faces=faces)
mesh.update()
object_utils.object_data_add(context, mesh, operator=self)