def turntable(options): center, radius = align_info() append_from_library("helix", "Object", "Camera") bpy.data.objects["Camera"].data.clip_start = 0.01 bpy.data.objects["Camera"].data.clip_end = radius * 9 bpy.context.scene.camera = bpy.data.objects["Camera"] bpy.data.objects["Camera-Helix-LookAt"].location = center bpy.data.objects["Camera-Helix-Ring"].location = (center.x, center.y, center.z + radius * 1.4) bpy.data.objects["Camera-Helix-Ring"].scale = (radius * 3, radius * 3, radius * 3) bpy.context.scene.frame_current = 1 bpy.data.objects["Camera"].constraints["Follow Path"].offset = 0 bpy.data.objects["Camera"].constraints["Follow Path"].keyframe_insert(data_path="offset") bpy.context.scene.frame_current = bpy.context.scene.frame_end bpy.data.objects["Camera"].constraints["Follow Path"].offset = 100 bpy.data.objects["Camera"].constraints["Follow Path"].keyframe_insert(data_path="offset") for fc in bpy.data.objects["Camera"].animation_data.action.fcurves: fc.extrapolation = "LINEAR" for kp in fc.keyframe_points: kp.interpolation = "LINEAR"
def turntable(options): center, radius = align_info() append_from_library("helix", "Object", "Camera") bpy.data.objects["Camera"].data.clip_start = 0.01 bpy.data.objects["Camera"].data.clip_end = radius * 9 bpy.context.scene.camera = bpy.data.objects["Camera"] bpy.data.objects["Camera-Helix-LookAt"].location = center bpy.data.objects["Camera-Helix-Ring"].location = (center.x, center.y, center.z + radius * 1.4) bpy.data.objects["Camera-Helix-Ring"].scale = (radius * 3, radius * 3, radius * 3) bpy.context.scene.frame_current = 1 bpy.data.objects["Camera"].constraints["Follow Path"].offset = 0 bpy.data.objects["Camera"].constraints["Follow Path"].keyframe_insert( data_path="offset") bpy.context.scene.frame_current = bpy.context.scene.frame_end bpy.data.objects["Camera"].constraints["Follow Path"].offset = 100 bpy.data.objects["Camera"].constraints["Follow Path"].keyframe_insert( data_path="offset") for fc in bpy.data.objects["Camera"].animation_data.action.fcurves: fc.extrapolation = "LINEAR" for kp in fc.keyframe_points: kp.interpolation = "LINEAR"
def section(options): # Avoid transparency glitches (section is based on transparency) # Might be still too little for some meshes # (encountered models which needed 42 bounces ...) bpy.context.scene.cycles.transparent_max_bounces = 16 axis = options.modifier_section_axis append_from_library("section", "NodeTree", "section") # TODO: DO THIS WITH SUPER CARE: # Find out what is the difference between # section_node_group vs. section_node_group_node # and check the implications for which one needs # to be used when and what it implies for actually # keeping the section node group working!!! # HINT: Group default value in n panel is not the same # as input on actualy group NODE (this is ignored??) section_node_group = bpy.data.node_groups["section"] for obj in bpy.data.objects: if obj.type == 'MESH': pass for mat in bpy.data.materials: section_node_group_node = mat.node_tree.nodes.new("ShaderNodeGroup") section_node_group_node.node_tree = bpy.data.node_groups["section"] if options.modifier_section_animated: bpy.context.scene.frame_current = 1 section_node_group.inputs[axis].default_value = options.modifier_section_animate_progress_from section_node_group.inputs[axis].keyframe_insert("default_value") bpy.context.scene.frame_current = bpy.context.scene.frame_end section_node_group.inputs[axis].default_value = options.modifier_section_animate_progress_to section_node_group.inputs[axis].keyframe_insert("default_value") # for fc in section_node_group.inputs[axis].animation_data.action.fcurves: # fc.extrapolation = 'LINEAR' # for kp in fc.keyframe_points: # kp.interpolation = 'LINEAR' else: section_node_group.inputs[axis].default_value = options.modifier_section_level surface_shader = None for node in mat.node_tree.nodes: if node.type == 'OUTPUT_MATERIAL': output_material_node = node for input in node.inputs: for link in input.links: surface_shader = link.from_node mat.node_tree.links.new(surface_shader.outputs[0], section_node_group_node.inputs["Shader"]) mat.node_tree.links.new(section_node_group_node.outputs["Shader"], output_material_node.inputs["Surface"])
def realistic(options): append_from_library("realistic", "Material", "realistic") append_from_library("realistic", "World", "realistic") realistic_material = bpy.data.materials["realistic"] for obj in bpy.data.objects: if obj.type == 'MESH': obj.data.materials.append(realistic_material) realistic_world = bpy.data.worlds["realistic"] bpy.context.scene.world = realistic_world
def setup_realistic(): append_from_library("realistic", "Material", "realistic") append_from_library("realistic", "World", "realistic") realistic_material = bpy.data.materials["realistic"] for obj in bpy.data.objects: if obj.type == 'MESH': obj.data.materials.append(realistic_material) realistic_world = bpy.data.worlds["realistic"] bpy.context.scene.world = realistic_world
def export_browser_preview(import_preview): # Place in center bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY') bpy.context.object.location = [0, 0, 0] # Normalize to size 1 max_dimension = max(bpy.context.object.dimensions) bpy.context.object.scale[0] /= max_dimension bpy.context.object.scale[1] /= max_dimension bpy.context.object.scale[2] /= max_dimension bpy.ops.object.transform_apply(scale=True) face_count = len(bpy.context.object.data.polygons) if face_count > 64000: bpy.ops.object.modifier_add(type='DECIMATE') bpy.context.object.modifiers["Decimate"].ratio = 64000 / face_count bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Decimate") # Append orientation widgets append_from_library("preview-widgets", "Object", "widget-flip-horizontally") append_from_library("preview-widgets", "Object", "widget-flip-vertically") append_from_library("preview-widgets", "Object", "widget-tilt") append_from_library("preview-widgets", "Object", "widget-turn") bpy.ops.object.select_all(action='SELECT') bpy.ops.export_scene.obj(filepath=import_preview, check_existing=False, use_materials=False, axis_forward="Y", axis_up="Z", use_triangles=True)
def section(options): # Avoid transparency glitches (section is based on transparency) # Might be still too little for some meshes # (encountered models which needed 42 bounces ...) bpy.context.scene.cycles.transparent_max_bounces = 16 axis = options.modifier_section_axis append_from_library("section", "NodeTree", "section") section_node_group = bpy.data.node_groups["section"] for mat in bpy.data.materials: section_node_group_node = mat.node_tree.nodes.new("ShaderNodeGroup") section_node_group_node.node_tree = bpy.data.node_groups["section"] if options.modifier_type == "animated-cross-section": bpy.context.scene.frame_current = 1 section_node_group_node.inputs[axis].default_value = options.modifier_section_level_from section_node_group_node.inputs[axis].keyframe_insert("default_value") bpy.context.scene.frame_current = bpy.context.scene.frame_end section_node_group_node.inputs[axis].default_value = options.modifier_section_level_to section_node_group_node.inputs[axis].keyframe_insert("default_value") for fc in section_node_group_node.inputs[axis].id_data.animation_data.action.fcurves: fc.extrapolation = 'LINEAR' for kp in fc.keyframe_points: kp.interpolation = 'LINEAR' else: section_node_group_node.inputs[axis].default_value = options.modifier_section_level surface_shader = None for node in mat.node_tree.nodes: if node.type == 'OUTPUT_MATERIAL': output_material_node = node for input in node.inputs: for link in input.links: surface_shader = link.from_node mat.node_tree.links.new(surface_shader.outputs[0], section_node_group_node.inputs["Shader"]) mat.node_tree.links.new(section_node_group_node.outputs["Shader"], output_material_node.inputs["Surface"])
def helix(options): center, radius = align_info() helix_scale = (radius * 3, radius * 3, radius * 3) append_from_library("helix", "Object", "Camera") bpy.data.objects["Camera"].data.clip_start = 0.01 bpy.data.objects["Camera"].data.clip_end = radius * 9 bpy.context.scene.camera = bpy.data.objects["Camera"] bpy.data.objects["Camera-Helix-LookAt"].location = center bpy.data.objects["Camera-Helix-Ring"].scale = helix_scale low_camera = (center.x, center.y, center.z - radius * 2) high_camera = (center.x, center.y, center.z + radius * 2) # Keyframe at the beginning - lowest point, follow circle 0% bpy.context.scene.frame_current = 1 bpy.data.objects["Camera-Helix-Ring"].location = low_camera bpy.data.objects["Camera-Helix-Ring"].keyframe_insert(data_path="location") bpy.data.objects["Camera"].constraints["Follow Path"].offset = 0 bpy.data.objects["Camera"].constraints["Follow Path"].keyframe_insert( data_path="offset") # Keyframe in the middle - highest point, follow circle 100% bpy.context.scene.frame_current = bpy.context.scene.frame_end / 2 bpy.data.objects["Camera-Helix-Ring"].location = high_camera bpy.data.objects["Camera-Helix-Ring"].keyframe_insert(data_path="location") # Keyframe at the end - lowest point, follow circle 200% bpy.context.scene.frame_current = bpy.context.scene.frame_end bpy.data.objects["Camera-Helix-Ring"].location = low_camera bpy.data.objects["Camera-Helix-Ring"].keyframe_insert(data_path="location") bpy.data.objects["Camera"].constraints["Follow Path"].offset = 200 bpy.data.objects["Camera"].constraints["Follow Path"].keyframe_insert( data_path="offset") # Make only the follow circle animation progression perfectly linear for fc in bpy.data.objects["Camera"].animation_data.action.fcurves: fc.extrapolation = "LINEAR" for kp in fc.keyframe_points: kp.interpolation = "LINEAR"
def helix(options): center, radius = align_info() helix_scale = (radius * 3, radius * 3, radius * 3) append_from_library("helix", "Object", "Camera") bpy.data.objects["Camera"].data.clip_start = 0.01 bpy.data.objects["Camera"].data.clip_end = radius * 9 bpy.context.scene.camera = bpy.data.objects["Camera"] bpy.data.objects["Camera-Helix-LookAt"].location = center bpy.data.objects["Camera-Helix-Ring"].scale = helix_scale low_camera = (center.x, center.y, center.z - radius * 2) high_camera = (center.x, center.y, center.z + radius * 2) # Keyframe at the beginning - lowest point, follow circle 0% bpy.context.scene.frame_current = 1 bpy.data.objects["Camera-Helix-Ring"].location = low_camera bpy.data.objects["Camera-Helix-Ring"].keyframe_insert(data_path="location") bpy.data.objects["Camera"].constraints["Follow Path"].offset = 0 bpy.data.objects["Camera"].constraints["Follow Path"].keyframe_insert(data_path="offset") # Keyframe in the middle - highest point, follow circle 100% bpy.context.scene.frame_current = bpy.context.scene.frame_end / 2 bpy.data.objects["Camera-Helix-Ring"].location = high_camera bpy.data.objects["Camera-Helix-Ring"].keyframe_insert(data_path="location") # Keyframe at the end - lowest point, follow circle 200% bpy.context.scene.frame_current = bpy.context.scene.frame_end bpy.data.objects["Camera-Helix-Ring"].location = low_camera bpy.data.objects["Camera-Helix-Ring"].keyframe_insert(data_path="location") bpy.data.objects["Camera"].constraints["Follow Path"].offset = 200 bpy.data.objects["Camera"].constraints["Follow Path"].keyframe_insert(data_path="offset") # Make only the follow circle animation progression perfectly linear for fc in bpy.data.objects["Camera"].animation_data.action.fcurves: fc.extrapolation = "LINEAR" for kp in fc.keyframe_points: kp.interpolation = "LINEAR"
def setup_realtime(): append_from_library("realtime", "Material", "Object") append_from_library("realtime", "World", "realtime") realtime_material = bpy.data.materials["Object"] for obj in bpy.data.objects: if obj.type == 'MESH': obj.data.materials.append(realtime_material) realtime_world = bpy.data.worlds["realtime"] bpy.context.scene.world = realtime_world append_from_library("realtime", "Object", "Plane")
def illustrated(options): append_from_library("illustrated", "FreestyleLineStyle", "Contour") append_from_library("illustrated", "FreestyleLineStyle", "Details") append_from_library("illustrated", "World", "illustrated") bpy.context.scene.render.use_freestyle = True for obj in bpy.data.objects: if obj.type == 'MESH': obj.cycles_visibility.camera = False illustrated_world = bpy.data.worlds["illustrated"] bpy.context.scene.world = illustrated_world bpy.context.scene.cycles.film_transparent = False
def setup_illustrated(): append_from_library("illustrated", "FreestyleLineStyle", "Contour") append_from_library("illustrated", "FreestyleLineStyle", "Details") append_from_library("illustrated", "World", "illustrated") bpy.context.scene.render.use_freestyle = True bpy.context.scene.svg_export.use_svg_export = True for obj in bpy.data.objects: if obj.type == 'MESH': obj.cycles_visibility.camera = False illustrated_world = bpy.data.worlds["illustrated"] bpy.context.scene.world = illustrated_world bpy.context.scene.cycles.film_transparent = False