I'm aware there are numerous posts/questions already been raised on this, but upon reading the previous posts, I'm not quite able to find exactly what I'm looking for. So apologies if there's a duplicate post that already answered this.
Basically, I have a CSV file with 3 columns =
y coordinate and
pixel value (based on 255 greyscale). All I want to do is import this CSV file in Blender and plot the points as vertices, using python script. That's it. So if there are 3 points in the CSV file, I want those 3 points created/plotted in their respective xy coordinates as vertices in Blender.
I've seen examples of python scripts for adding mesh objects. But I simply want to plot the points given the xy coordinates in the CSV file, as vertices. Not add existing 3D objects/meshes.
This is the code I have so far:
import bpy import csv with open(r'file path\img_pixel_coor.csv') as csvfile: csvread = csv.reader(csvfile) for i, row in enumerate (csvread): print("i = "+str(i)+". row = "+str(row))
i = 0. row = ['494', '216', '86'] i = 1. row = ['494', '217', '86'] i = 2. row = ['494', '218', '86'] i = 3. row = ['494', '219', '85'] i = 4. row = ['494', '220', '84'] i = 5. row = ['494', '221', '87'] i = 6. row = ['494', '222', '87'] i = 7. row = ['494', '223', '88'] i = 8. row = ['494', '224', '92']
The print is just to show what's in the file (logging purposes).
Also, would it be possible to put this script in a python file, and run it from a python file, without having to manually open Blender, i.e. can you control externally from a python file, to open Blender and run the script, without having to actually open Blender software manually yourself?
Any help would be greatly appreciated.
Here's a sample of how the CSV file looks like in the first few rows, to demonstrate how the x, y and
pixel values are structured:
Finally, how do I smooth the vertices more. As you can see from the image below, the surface of the mesh is very spikey. I used the code below, but it's still very rough/spikey surface.
for p in ob.data.polygons: #Set smooth shading (if needed) p.use_smooth = True
Many thanks in advance for any help.
Illustration (my understanding):
of the code:
# Vertices store the color values as Z vertices = [Vector( (x, y, int(z_max * random.random())) ) for x, y in product( range(x_size), range(y_size) )] # Get base face indices face_basis = ((x * y_size) + y for (x, y) in product( range(x_size-1), range(y_size-1) )) # Each face is a square for the base index turning around counterclockwise faces = [(v, v + 1, v + y_size + 1, v + y_size) for v in face_basis]