Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- from math import radians
- rows = 5
- columns = 1
- file_path = "Location_Here"
- r = 0
- c = 0
- highFreq = 1000
- lowFreq = 0
- lowF = 0.1
- mediumF = 0.4
- highF = 0.5
- endFrame = 600
- bpy.context.area.type = 'TIMELINE'
- bpy.ops.anim.change_frame(frame=0)
- bpy.data.scenes[-1].frame_start = 1
- bpy.data.scenes[-1].frame_end = endFrame
- for i in range (0, rows*columns):
- if c == columns:
- r += 1
- c = 0
- bpy.ops.mesh.primitive_cube_add(location = (r * 2 - rows + 1, c * 2 - columns + 1, 1))
- bpy.context.scene.cursor_location = bpy.context.active_object.location
- bpy.context.scene.cursor_location.z -= 1
- bpy.ops.object.origin_set(type = 'ORIGIN_CURSOR')
- bpy.context.active_object.scale.x = 0.5
- bpy.context.active_object.scale.y = 0.5
- bpy.context.active_object.scale.z = 5
- bpy.ops.object.transform_apply( scale = True)
- bpy.ops.anim.keyframe_insert_menu(type = 'Scaling')
- bpy.context.active_object.animation_data.action.fcurves [0]. lock = True
- bpy.context.active_object.animation_data.action.fcurves [1]. lock = True
- bpy.context.area.type = 'GRAPH_EDITOR'
- step = ((highFreq - lowFreq) / (rows * columns)) + lowFreq
- bpy.ops.graph.sound_bake(filepath = file_path, low = i * step, high = i * step + step)
- bpy.context.active_object.animation_data.action.fcurves [2]. lock = True
- materialName = "Visualizer " + str(i)
- bpy.ops.material.new(name = materialName)
- material = bpy.data.materials[-1]
- nodes = material.node_tree.nodes
- diffuse = nodes.get("Diffuse BSDF")
- for f in range(1, endFrame):
- bpy.context.scene.frame_set(f)
- height = bpy.context.active_object.scale.z
- diffuse.inputs[0].keyframe_insert("default_value")
- if height > highF:
- diffuse.inputs[0].default_value = 1.000, 0.000, 0.000 , 1.000
- elif height > mediumF:
- colorG = 1 - (height - mediumF) / (highF - mediumF)
- diffuse.inputs[0].default_value = 1.000, colorG, 0.000, 1.000
- elif height > lowF:
- colorR = (height - lowF) / (mediumF - lowF)
- diffuse.inputs[0].default_value = colorR, 1.000, 0.000, 1.000
- else:
- diffuse.inputs[0].default_value = 0.000, 1.000, 0.000, 1.000
- diffuse.inputs[0].keyframe_insert("default_value")
- bpy.context.active_object.active_material = material
- bpy.context.area.type = 'TIMELINE'
- bpy.ops.anim.change_frame(frame=0)
- c +=1
- bpy.ops.object.camera_add(location = (0, -20, 5), rotation = (radians(87.5), 0, 0))
- bpy.ops.object.lamp_add(location = (0, 0, 9), rotation = (radians(50), radians(-50), 0), type = 'SUN')
- bpy.context.area.type = 'VIEW_3D'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement