Add more general shape description.

This commit is contained in:
jmsgrogan 2017-10-24 20:18:12 +01:00
parent cfb558e540
commit 422f458469
27 changed files with 234 additions and 106 deletions

View file

@ -14,27 +14,103 @@ def UpOrDown(normal):
return True
return False
def generate_pendant_shade(radius1, radius2, depth):
def generate_pendant_shade(shape_parameters):
bpy.ops.mesh.primitive_cylinder_add(radius=radius1,
radius = shape_parameters["radius"]
depth = shape_parameters["height"]
print(depth)
bpy.ops.mesh.primitive_cylinder_add(radius=radius,
depth=depth)
cone = bpy.data.objects["Cylinder"]
cone.name = "shade"
bpy.ops.object.mode_set(mode='EDIT')
for idx in range(3):
num_subdivisions = 3
if len(shape_parameters["division_offsets"])>3:
num_subdivisions = 4
for idx in range(num_subdivisions):
bpy.ops.mesh.subdivide()
bm = bmesh.from_edit_mesh(cone.data)
for i in range( len( bm.verts ) ):
num_verts = len(bm.verts)
summed_offset = 0.0
for jdx in range(len(shape_parameters["division_offsets"])):
summed_offset += shape_parameters["division_offsets"][jdx]
print(summed_offset)
for idx in range(num_verts):
bm.verts.ensure_lookup_table()
vert = bm.verts[i]
vert = bm.verts[idx]
theta = math.atan2(vert.co.x, vert.co.y)
delta = abs(vert.co.z-depth/2.0)
vert.co.z = vert.co.z -depth/2.0
mapped_rad = radius2 + delta**2
vert.co.x = mapped_rad*math.sin(theta)
vert.co.y = mapped_rad*math.cos(theta)
delta = abs(vert.co.z)
frac = delta/depth
summed_offset = 0.0
prev_offset = 0.0
division_index = len(shape_parameters["division_offsets"])-1
for jdx in range(len(shape_parameters["division_offsets"])):
prev_offset = summed_offset
summed_offset += shape_parameters["division_offsets"][jdx]
if frac >=prev_offset and frac <= summed_offset:
division_index = jdx
if division_index==0:
print(vert.co.z, frac)
current_offset = shape_parameters["division_offsets"][division_index]
division_type = shape_parameters["division_patterns"][division_index]
if division_index==0:
print(vert.co.z, frac, division_index)
division_radius = shape_parameters["fixture_radius"]
previous_offset = 0.0
previous_radius = division_radius
else:
division_radius = shape_parameters["radius"]*shape_parameters["division_radii"][division_index]
previous_offset = shape_parameters["division_offsets"][division_index-1]
previous_radius = shape_parameters["radius"]*shape_parameters["division_radii"][division_index-1]
if previous_radius< shape_parameters["fixture_radius"]:
previous_radius = shape_parameters["fixture_radius"]
if division_radius<previous_radius:
division_radius = previous_radius
#print(division_radius, vert.co.z)
if division_type == "straight":
vert.co.x = division_radius*math.sin(theta)
vert.co.y = division_radius*math.cos(theta)
# elif division_type == "square":
# mapped_rad = division_radius + (delta/3.0)**2
# vert.co.x = mapped_rad*math.sin(theta)
# vert.co.y = mapped_rad*math.cos(theta)
# elif division_type == "inv_square":
# mapped_rad = division_radius + 1.0/(0.01+delta**2)
# vert.co.x = mapped_rad*math.sin(theta)
# vert.co.y = mapped_rad*math.cos(theta)
else:
# elif division_type == "sine":
mapped_rad = division_radius + math.sin(math.pi/2.0*frac)
vert.co.x = mapped_rad*math.sin(theta)
vert.co.y = mapped_rad*math.cos(theta)
# elif division_type == "inv_sine":
# mapped_rad = division_radius + 1.0/math.sin(delta)
# vert.co.x = mapped_rad*math.sin(theta)
# vert.co.y = mapped_rad*math.cos(theta)
# else:
# #elif division_type == "ramp":
# mapped_rad = division_radius + delta
# vert.co.x = mapped_rad*math.sin(theta)
# vert.co.y = mapped_rad*math.cos(theta)
# elif division_type == "inv_ramp":
# mapped_rad = division_radius + delta
# vert.co.x = mapped_rad*math.sin(theta)
# vert.co.y = mapped_rad*math.cos(theta)
for face in bm.faces:
if UpOrDown(face.normal):
@ -160,7 +236,7 @@ def make_square_ring(radius, depth, thickness):
bpy.ops.object.mode_set(mode='OBJECT')
return bpy.data.objects["square_ring"]
def generate_bio_shade(radius1, radius2, depth):
def generate_led_shade(radius1, radius2, depth):
ring1 = make_square_ring(3.0*radius1, depth/10.0, 0.2)
bpy.ops.transform.rotate(value=-math.pi/12.0, axis=(1.0,0.0,0.0))