[edit 2]
I’ve made some changes to this process, as described in the edits below. For the sake of clarity, then, I’ve edited the below description of my approach to better match what I have at time of this edit.
[/edit 2]
So, as per the conclusion of this thread, I’m attempting to use a memoryview in order to alter geometry on a per-frame basis. (Having switched from the use of stored GeomVertexWriters, which I’m told is unwise.)
After some trial and error I’ve managed to get to the point at which the code runs–but for some reason I’m not seeing any geometry. (Where, please note, the geometry was visible when using GeomVertexWriters.)
I would seem to be doing something wrong–but I don’t know quite what. (Especially as I’m rather new to the use of memoryviews.)
In short, my approach is as follows:
During initialisation:
- Create a GeomVertexFormat and a GeomVertexData
- My choice of format is “v3n3t2”
- Set the number of rows in the latter to reflect the number of vertices
- In this case, that amounts to (12) * (number of data-points used), for a naive definition of four triangles per data-point.
- Create a memoryview for the GeomVertexData, casting it to “B” and then to “f”
- Create my primitive (a GeomTriangles)
- Set the appropriate indices in the primitive
- Set up a GeomNode and NodePath using that primitive
Then, during updates:
- Create an array, with format “f”, initialised with an empty list
- i.e. Like so:
array.array("f", [])
- i.e. Like so:
- Iterate over the data that defines the vertices
- For each data-point:
- Perform various calculations
- (Noting that these should be unchanged since the version that worked when using GeomVertexWriter)
- Add to the array via “fromlist”
- Specifically, adding the following four triangles:
dataList.fromlist( [ # Tri 1 vert1.x, vert1.y, vert1.z, normal1.x, normal1.y, normal1.z, uv1.x, uv2.y, # Tri 2 # As with Tri 1, but with its own data # And so on for Tris 3 and 4... ] )
- Specifically, adding the following four triangles:
- Perform various calculations
- For each data-point:
- At the end, update the memoryview like so:
self.memoryviewObject[:len(dataList)] = dataList
And that’s basically it.
Does anyone see where I might be going wrong…? Is there a format issue with the array? Or the order in which I’m adding data? Or something else…?
Note that I’m not seeing junk vertices–I’m just seeing… nothing.
[edit]
Okay, I’ve realised one mistake, at least:
I had the number of rows being set to “(number of elements in the format) * (number of vertices) * (total number of numeric values across the format)”.
However, I now think that a row already incorporates the number of numeric values and the number of elements in the format–the former of which includes the latter, for that matter. This then just leaves the number of vertices.
Further, I was miscalculating the number of vertices.
The result is now, essentially: (number of data-points) * (number of vertices per data-point)
(The latter being 12 in my case; I could reduce this by re-using vertices, but for now at least separate vertices makes for simpler logic.)
However, having corrected this, I believe, I’m still seeing no geometry… :/
[edit 2]
Oh, and I’ve removed the use of the GeomVertexWriters; I’m just leaving the data as default until it’s modified in the update code.