I'm a teacher, and I'm designing an assignment in which students will analyze music to extract timing and loudness data from recordings, then import the information into a Python script, map the information to Blender objects, and then output a 3D-printable .stl file.

While I know exactly how to extract the musical information, I'd like to hear your opinions on good ways to map the data to Blender objects and export a printable .stl using Python.


1 Answer 1


Assuming you have already baked a sound file to curve, you could evalutate the f-curves values and assign them to a prepared object e.g. massivley loop-cut cube.

import bpy

obj = bpy.context.scene.objects["Cube"]
action = obj.animation_data.action

fcurves = action.fcurves
for f in fcurves:

coords = []
for vert in obj.data.vertices:
    if vert.co.z > 0:
        coords.append( vert.co )
        print( vert.co )

ysorted = sorted(coords, key=lambda element: (element[1] ))

for i in range(200,250):
    curve_val = f.evaluate(i)
    ysorted[cidx].z = curve_val
    cidx = cidx + 1
    ysorted[cidx].z = curve_val
    cidx = cidx + 1

enter image description here

The vertices are first filtered by positive z-coordinste and sorted by y-coordinate so that opposite (on x-axis) vertices follow in a sequence. After that the curve value is evaluated and assigned to the z component of the vertex.

The resulting mesh is manifold and can be exported to.STL format.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .