GeomVertexDataArray from Numpy array

I am trying to create a geom with vertex data that is stored in a numpy array.
On this topic: [url]Particle simulation nBody] i found the Information that i have to pack the data of the numpy array into a string buffer, and assign it to the geomverteddataarray of the geom.
This works all well (no exception, wrong result) with the exception that some vertices aren’t in the right place.
I guess that the chosen vertex format of panda and my numpy array format doesn’t match exactly (v3n3t2 <> 8*float32).

This is the critical part of the code:

		format=GeomVertexFormat.getV3n3t2() #vertex 3 normal 3 texture 2 (v3n3t2)
		vdata=GeomVertexData('geometry', format, Geom.UHStatic)

 		geomVertexNumpyData = np.empty((vertListLength,8),dtype=np.float32)
 		#add some data to the array and tri

 		data = geomVertexNumpyData.tostring()


I want to use pyopencl to calculate the values for the numpy array, therefor the GeomVertexWriter isn’t a option.

In addition to this i am really interested in a way to add data to GeomTriangles(Geom.UHStatic) in a similar way. Is this only a array containing the indices to a triangle in the following form: [[int,int,int],[int,int,int],…]?

Thanks in advance

You can always try creating your own GeomVertexFormat with the types and order that you use.

For GeomTriangles, you’ll need an array of either 16-bits or 32-bits (depending on the value passed to setIndexType) integers, every set of three describing a single triangle.

Thank you very mutch rdb, i really appreciate the good advices you give on this forum.
I just noticed that i had a problem in my tri-creation code. But now that the tri index creation also happens in opencl this isn’t a problem anymore :slight_smile: (around 40 times faster).
I guess i will have to create a new GeomVertexFormat at some point but at this moment it works well enough with the standard type.
The setIndexType tip was really helpful. I didn’t even know that the index type could be changed.

For anyone who is interested:

		geomFaceNumpyData = np.empty((faceListLength,3),dtype=np.uint32)
		#add some data to face-array
		faceDataString = geomFaceNumpyData.tostring()
		geomFacesDataArray = tri.modifyVertices()