Hi everyone,
I have a script which sets XYZ positions of a 5x5 grid according to OSC data being fed from max/msp. this runs fine in the GameEngine but i want to export the meshes i make in the engine into Blender so ican then export as .stls and make them on a lathe. ok so that was the background!
ok so the grid data is stored in 5lists which correspond to the 5 rows, each list has 5 sublists of each vertex’s XYZ.
ive figured out how to export these to a text file with cPickle, using the following code.
import cPickle as pickle
if own.dump==1:
# file = open("4.txt","w")
# ta_x = (str(time_a_xyz)+ "
")
# tb_x = (str(time_b_xyz)+ "
")
# tc_x = (str(time_c_xyz)+ "
")
# td_x = (str(time_d_xyz)+ "
")
# te_x = (str(time_e_xyz)+ "
")
# file.write("time_a_xyz")
# file.write(ta_x)
# file.write("time_b_xyz")
## file.write(tb_x)
# file.write("time_c_xyz")
# file.write(tc_x)
# file.write("time_d_xyz")
# file.write(td_x)
# file.write("time_e_xyz")
# file.write(te_x)
pickle.dump(time_a_xyz, file)
pickle.dump(time_b_xyz, file)
pickle.dump(time_c_xyz, file)
pickle.dump(time_d_xyz, file)
pickle.dump(time_e_xyz, file)
file.close()
own.dump=0
now that wites fine to the text file but im having trouble reading it back in “normal” Blender… using:
file = open("4.txt","r")
time_a_xyz = pickle.load(time_a_xyz, file)
time_b_xyz = pickle.load(time_b_xyz, file)
time_c_xyz = pickle.load(time_c_xyz, file)
time_d_xyz = pickle.load(time_d_xyz, file)
time_e_xyz = pickle.load(time_e_xyz, file)
file.close()
i get the error: name time_a_xyz is not defined…
i figure maybe i have to get cPickle to move to the next line(??) each before setting the next variable…
any help would be very much appreciated(otherwise i guess its writing a seperate .txt file for each variable)
#########################################
EDIT:
ok so ive got data in using cPickle but cant figure out how to set individual vertexes according to variables…
heres the code im playing about with, as you can see its late if only the GE api and the Blender API were a littlel similar
import Blender
from Blender import NMesh, Material
import cPickle as pickle
#### get vertex lists ####
file = open("7.txt","r")
fullfile = pickle.load(file)
file.close()
time_a_xyz = fullfile[0]
time_b_xyz = fullfile[1]
time_c_xyz = fullfile[2]
time_d_xyz = fullfile[3]
time_e_xyz = fullfile[4]
me = NMesh.GetRaw("Grid") # get the mesh data called "Plane"
if not me.materials: # if there are no materials ...
newmat = Material.New() # create one ...
me.materials.append(newmat) # and append it to the mesh's list of mats
print me.materials # print the list of materials
mat = me.materials[0] # grab the first material in the list
for v in me.verts: # loop the list of vertices
#v.co[0] *= 2.5 # multiply the coordinates CO IS COORDINATES
#v.co[1] *= 5.0
#v.co[2] *= 2.5
#print v,v.co,v.index
#print me.verts[1].co
#me.verts[0].co = time_a_xyz[0]
v.co[0] = time_a_xyz[0][0]
v.co[1] = time_a_xyz[0][1]
v.co[2] = time_a_xyz[0][2]
#v.co[3] = time_b_xyz[0][0]
#v.co[2] = time_a_xyz[2]
#v.co[3] = time_a_xyz[3]
#v.co[4] = time_a_xyz[4]
me.update()
#me.verts[1].co = time_a_xyz[0]
print time_a_xyz[1]
any ideas? cheers
will