I've run into a few issues regarding a blender script I am working on to accompany another program I wrote that transforms analog sound into a data set representing the amplitudes of the frequencies in that sound sample over time. I now want to use blender to transform my data into a 3D model that would, effectively, be a 3D representation of music. It's my first time working with Blender/Python scripting, so your patience is appreciated!
Context From a conceptual standpoint, here is what the script should do:
- Create 513 (number of frequencies sampled) collinear vertices
- Connect the vertices with a line(face?)
- Set the z value of each vertex to the corresponding amplitude for that specific frequency at t=1 represented by the vertex (we now have a 2D jagged plane)
- Extrude the plane by delta time
- Adjust the new set of vertices for amps at t=2
...repeat this process of adjusting and extruding until all t values are exhausted
The issue I repeatedly encounter as I work on this code is referencing / selecting individual vertices. In the 3D editor, I can simply right click, or control right click, to select point(s), and that is basically the functionality I need to replicate at many steps in this process.
For example, to create the first row of vertices, I wrote the following code:
counter = 0 bpy.context.scene.cursor_location = (0.0, 0.0, 0.0) for x in range (0,513): bpy.ops.mesh.primitive_vert_add() counter = counter - 0.1 bpy.context.scene.cursor_location = (counter, 0.0, 0.0)
Then, to connect these collinear vertices, I have:
bpy.ops.mesh.select_all(action='TOGGLE') bpy.ops.mesh.select_all(action='TOGGLE') bpy.ops.mesh.edge_face_add()
Now, though, I need to go back and start adjusting z value for each vertex I created in this line, and I do not know how to reference them. Ideally, I want to store them in an array at the time of creating them, but again, I am at a loss for associating these vertices with object references that can be operated upon.
I will also encounter an issue following the extrusion, where a new set of 513 vertices is formed. For those, I will only know their xyz location and will have had no opportunity to build references to them unless Blender already does that by storing references to all vertices in a mesh (I've read about it, but still cannot access that data set if it exists). When it is time to set z values for these points, I will not know how to reference them.
Question How do I reference individual vertices knowing only their xyz location in space and operate on them either individually (for z movements) or as a set (at extrusion time)?
Thank you for your help! I can't wait to finally see (or print!) my audio data set in three dimensional space.