diff --git a/src/product_gen/__pycache__/generate_lamp.cpython-35.pyc b/src/product_gen/__pycache__/generate_lamp.cpython-35.pyc index 557153d..7ca6b4e 100644 Binary files a/src/product_gen/__pycache__/generate_lamp.cpython-35.pyc and b/src/product_gen/__pycache__/generate_lamp.cpython-35.pyc differ diff --git a/src/product_gen/__pycache__/generate_product.cpython-35.pyc b/src/product_gen/__pycache__/generate_product.cpython-35.pyc index 7b27557..7d017e3 100644 Binary files a/src/product_gen/__pycache__/generate_product.cpython-35.pyc and b/src/product_gen/__pycache__/generate_product.cpython-35.pyc differ diff --git a/src/product_gen/__pycache__/generate_shades.cpython-35.pyc b/src/product_gen/__pycache__/generate_shades.cpython-35.pyc index e050024..980efa8 100644 Binary files a/src/product_gen/__pycache__/generate_shades.cpython-35.pyc and b/src/product_gen/__pycache__/generate_shades.cpython-35.pyc differ diff --git a/src/product_gen/generate_lamp.py b/src/product_gen/generate_lamp.py index 7a8747e..baa2d24 100644 --- a/src/product_gen/generate_lamp.py +++ b/src/product_gen/generate_lamp.py @@ -1,33 +1,24 @@ import os import bpy import product_gen.generate_lamp_base -import product_gen.generate_shades +import product_gen.generate_shades as gs -def generate_models(shape, height, radius): +def generate_models(shape_parameters): # Shade - radius2 = 0.3 - if shape == "cone": - shade = product_gen.generate_shades.generate_pendant_shade(radius, - radius2, - height) - elif shape == "mesh": - shade = product_gen.generate_shades.generate_mesh_shade(radius, - radius2, height) - elif shape == "bio": - shade = product_gen.generate_shades.generate_bio_shade(radius, - radius2, height) - elif shape == "pendant": - shade = product_gen.generate_shades.generate_pendant_shade(radius, - radius2, - height) + if shape_parameters["shape"] == "mesh": + shade = gs.generate_mesh_shade(shape_parameters) + elif shape_parameters["shape"] == "led": + shade = gs.generate_led_shade(shape_parameters) + else: # default pendant + shade = gs.generate_pendant_shade(shape_parameters) # Base - if "bio" not in shape: + if "bio" not in shape_parameters["shape"]: radius1 = 0.3 radius2 = 0.07 depth = 0.5 - location = (0.0, 0.0, height/2.0+depth/2.0) + location = (0.0, 0.0, depth/2.0) base = product_gen.generate_lamp_base.generate_cone_base(radius1, radius2, depth, diff --git a/src/product_gen/generate_product.py b/src/product_gen/generate_product.py index 0dcf632..0f18fb7 100644 --- a/src/product_gen/generate_product.py +++ b/src/product_gen/generate_product.py @@ -5,25 +5,21 @@ import product_gen.generate_lamp import rendering.setup_scene import rendering.setup_renderer -def generate(shape, - height, - radius, - color, - output_prefix, - is_final=False): +def generate(shape_parameters, output_prefix, is_final=False): - rendering.setup_renderer.setup_renderer() + rendering.setup_renderer.setup_renderer(shape_parameters) - rendering.setup_scene.initialize_scene() + rendering.setup_scene.initialize_scene(shape_parameters) # Generate models - models = product_gen.generate_lamp.generate_models(shape, height, radius) + models = product_gen.generate_lamp.generate_models(shape_parameters) # Optimize geometries for render product_gen.generate_lamp.optimize_for_render(models) # Set up materials and textures - if "bio" not in shape: + color = (0.1, 0.1, 0.1) + if "bio" not in shape_parameters["shape"]: colormap = {"shade": color, "base": (132.0/255.0, 64.0/255.0, 11.0/255.0), "chord": (5.0/255.0, 5.0/255.0, 5.0/255.0)} @@ -32,7 +28,7 @@ def generate(shape, product_gen.generate_lamp.apply_textures(colormap, models) - rendering.setup_scene.setup_scene() + rendering.setup_scene.setup_scene(shape_parameters) # Do rendering prefix = os.getcwd() + "/" + output_prefix + "/" + output_prefix @@ -52,4 +48,4 @@ def generate(shape, bpy.ops.wm.save_as_mainfile(filepath=prefix + ".blend") - return height, radius, color \ No newline at end of file + return shape_parameters \ No newline at end of file diff --git a/src/product_gen/generate_shades.py b/src/product_gen/generate_shades.py index e476b0d..91c1712 100644 --- a/src/product_gen/generate_shades.py +++ b/src/product_gen/generate_shades.py @@ -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