Godot Version
4.7.1.stable.official
Question
I have been working on C++ code that gets the skinned positions of mesh vertices that have been posed by a Skeleton3D. I found a project that includes a way to do it in GDScript, and using that as reference for my project works fine when I adapt it to my project. However, after porting the code to C++, I suddenly can’t get it to work.
The offending code seems to be this line: skinned_vertex_array[vertex_index] = Transform3D(x_basis, y_basis, z_basis, origin) * vertex
This is meant to combine the new basis and origin values gathered from the bones and weights affecting the vertex, and put the vertex into the appropriate place based on that. This works fine in GDScript. But using the * operator in this way in C++ won’t compile, so I changed it to this seemingly equivalent code:
skinned_vertex_array[vertex_index] = Transform3D(x_basis, y_basis, z_basis, origin).xform(vertex);
This does not work at all. I’ve used a debugger to look at the basis and origin values through the rest of the code, and everything regarding creating the Transform3D is the same up to this point. Clearly the * operator in GDScript does something different to what .xform() does, but I don’t know enough about how this works to know what is different, or what I should be doing instead. I’ve guessed at a few other operations to see if I could get it to work by brute force, but they were all wrong in some other slightly different way.
What is GDScript doing here that’s making it work, and how do I replicate that in C++? If possible, perhaps someone could point me to where the GDScript interpreter does this operation in Godot’s source code, so I can try to figure out these discrepancies next time. I wasn’t able to find that myself after a quick look.
The image below shows the discrepancy between the two. The green dots are vertices output from the GDScript code using the * operator, and appear as expected. The red dots are the C++ code, using the .xform()function, and is very clearly not in the correct place.
