I have a *.csv file representing spherical coordinates of pixels picked up from a Fish-eye camera (185 DEG, all directions) looking like this:
x, y, z, R, G, B
0.1, 3.5, 4.0, 150, 150, 150
The source image is in gray scale ==> R=G=B. Thats why I wrote 150,150,150.
The total amount of coordinates is 752*480 (resolution).
I want to visualize the pixels in 3D space. We have applied the pixels on a sphere and generated the 3D position for each pixel around the center point (0,0,0) based on undistortion and calibration. I am not interested in rendering the end result but to view the result inside the view port.
Since a Vertex isn’t consuming any space and I can’t just place Vertexes and give them a RGB-color I figured that a Cube would be easiest and the most performance effective object (except for pyramid).
Cube = 8 vertexes, 6 sides * 2 triangles = 12 faces.
Pyramid = 5 vertexes, bottom 2 triangles + sides 4 triangles = 6 faces.
Plane = 4 vertexes, two triangles.
** Not considering the Object’s internal settings
An additional idea was to use planes facing the view port but that would probably consume a lot of real time in scene performance while rotating the view port in the center point to view the image.
A other idea could be to use particles but I am not sure of how that would work and the particles them self’s have to obtain some space based on a shape I think.
First I tried this in 3dsMax scripting and it was far to slow and heavy. But I have a feeling that Blender with pyton script is the tool for the job.
Problem is that the resolution requires so many objects and blender crashes (752x480= 360960 px). Code and files can be find bellow.
How can this be done in a more efficient way? How do I remove the shading etc? even though I use specular color 0,0,0 I still have shadings.
import bpy import csv # READ CSV DATA FILE file = csv.reader(open('\\Users\Jose Estevez\BlenderPY\\sphere.csv', newline=''), delimiter=',') curRow =  #empty placeholder for current row color = 0 magnifier = 500 # ATOM def returnMaterialByName(passedName): result = None for m in bpy.data.materials: if m.name == passedName: result = m break return result def createNewMaterial (passedName): tempMat = bpy.data.materials.new(passedName) if tempMat != None: tempMat.diffuse_color = (color/255,color/255,color/255) tempMat.diffuse_shader = 'LAMBERT' tempMat.diffuse_intensity = 1.0 tempMat.specular_color = (0.0,0.0,0.0) tempMat.specular_shader = 'COOKTORR' tempMat.specular_intensity = 0.5 tempMat.alpha = 1.0 tempMat.ambient = 0.3 tempMat.emit = 0.2 tempMat.use_shadeless = True return tempMat def aquireOrCreateMaterial(passedName): tempMat = returnMaterialByName(passedName) if tempMat == None: tempMat = createNewMaterial(passedName) return tempMat for idx, row in enumerate(file): if ((idx % 100) == 0): ## IMPORTANT! Constant 100 will only limit to create every 100'th Object. Change Constant to 1 to create all the objects of pixles. print(idx,row) curRow = row x = eval(curRow) y = eval(curRow) z = eval(curRow) color = eval(curRow) # create cube and transform resize bpy.ops.mesh.primitive_cube_add(view_align=False, enter_editmode=False, location=(x*magnifier, y*magnifier, z*magnifier), rotation=(0.0,0.0,0.0)) # store the location of current 3d cursor saved_location = bpy.context.scene.cursor_location.copy() # returns a copy of the vector # give 3dcursor new coordinates bpy.context.scene.cursor_location = (0,0,0) # set the origin on the current object to the 3dcursor location bpy.ops.object.origin_set(type='ORIGIN_CURSOR') # set 3dcursor location back to the stored location bpy.context.scene.cursor_location = saved_location myObj = bpy.context.active_object print(myObj) me = myObj.data mat = aquireOrCreateMaterial(curRow) me.materials.append(mat) # before applying below, you need to create material data slot first! myObj.material_slots.material = bpy.data.materials[curRow]