I’m currently using some code drawn from this post, and indeed, it works quite well.
However, that code only extracts vertex-position data from the source-mesh, and I find myself wanting more. So, to that end, I’m trying to adapt the code to work with a vertex-format that includes such data. Specifically, where the code given there uses a “V3” format, I’m attempting to use a “tV3n3c4” format. (These acquired via their associated “get”-calls in GeomVertexFormat.)
And this is where I’m getting stuck: I don’t seem to be figuring out quite what to change in order for the data in the memory-view line up properly with the vertices in this new format.
To quote a bit of code from the post linked-to above, with credit to Epihaius for it, here is more-or-less the original form of what I have:
for geom in model_node.modify_geoms(): geom.decompose_in_place() vertex_data = geom.modify_vertex_data() vertex_data.format = GeomVertexFormat.get_v3() view = memoryview(vertex_data.arrays).cast("B").cast("f") index_list = geom.primitives.get_vertex_list() index_count = len(index_list) for indices in (index_list[i:i+3] for i in range(0, index_count, 3)): points = [Point3(*view[index*3:index*3+3]) for index in indices] coll_poly = CollisionPolygon(*points) collision_node.add_solid(coll_poly)
I’m then modifying the “getV3” count to look more or less like this:
vertex_data.format = GeomVertexFormat.get_v3n3c4()
Now, naturally this results in the vertex-data in the memory-view no longer lining up as shown in the code above.
So, my thought is to change the line that creates the “points” list to look like this:
points = [Point3(*view[index*3:index*3+3]) for index in indices]
Since there are no longer three floats per vertex-entry, but ten (three position, three normal, and four colour), I would expect to have to multiply my indices by ten instead of three, producing something like this:
points = [Point3(*view[index*10:index*10+3]) for index in indices]
However, this doesn’t seem to work–I end up with malformed geometry.
(And I’ve tried a few other alternatives to that line, also to little avail.)
I’m not seeing where I’m going wrong right now, so I appeal to the forum for help: does anyone see how to modify the code to work with this altered vertex-format?