import os import bpy import product_gen.generate_lamp_base import product_gen.generate_shades def generate(shape, height, radius, color, output_prefix, is_final=False): prefix = os.getcwd() + "/" + output_prefix + "/" + output_prefix # Set up scene objs = bpy.data.objects objs.remove(objs["Cube"], True) # Shade radius2 = 0.3 if shape == "cone": shade = product_gen.generate_shades.generate_cone_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) # Base radius1 = 0.3 radius2 = 0.2 depth = 0.2 location = (0.0, 0.0, 0.6*height) base = product_gen.generate_lamp_base.generate_cone_base(radius1, radius2, depth, location) # Chord radius = 0.05 height = 5.0 location = (0.0, 0.0, height/2.0) chord = product_gen.generate_lamp_base.generate_chord(height, radius, location) models = {shade.name: shade, chord.name: chord, base.name: base} # Smooth shapes for eachModel in models.values(): bpy.context.scene.objects.active = eachModel for poly in bpy.context.object.data.polygons: poly.use_smooth = True # Set up materials and textures # Get material colormap = {"shade": color, "base": (220.0/255.0, 220.0/255.0, 220.0/255.0), "chord": (20.0/255.0, 20.0/255.0, 20.0/255.0)} for eachName in colormap.keys(): mat = bpy.data.materials.get(eachName + "-material") if mat is None: mat = bpy.data.materials.new(name=eachName + "-material") mat.diffuse_color = colormap[eachName] mat.specular_color = colormap[eachName] mat.diffuse_intensity = 1.0 mat.specular_intensity = 1.0 if "shade" in eachName: mat.emit = 0.0 mat.translucency = 10 mat.use_transparency = True bpy.context.scene.objects.active = models[eachName] if bpy.context.active_object.data.materials: # assign to 1st material slot bpy.context.active_object.data.materials[0] = mat else: # no slots bpy.context.active_object.data.materials.append(mat) # Set up world bpy.context.scene.world.use_sky_paper = True bpy.context.scene.world.horizon_color = (0.9, 0.9, 0.9) #bpy.context.scene.world.light_settings.use_environment_light = True # Set up lamps and cameras objs["Lamp"].location = objs["Camera"].location objs["Lamp"].delta_location = (-3, 0, -1) # Set up and do the render bpy.context.scene.render.resolution_x = 600.0 bpy.context.scene.render.resolution_percentage = 99.0 if is_final: bpy.context.scene.render.filepath = prefix + "_kitchen.png" bpy.ops.render.render(write_still=True) bpy.context.scene.render.filepath = prefix + "_hall.png" bpy.ops.render.render(write_still=True) bpy.context.scene.render.filepath = prefix + "_landing.png" bpy.ops.render.render(write_still=True) else: bpy.context.scene.render.filepath = prefix + ".png" bpy.ops.render.render(write_still=True)