|
Greetings Ladies, Gents, Holograms and turtles
New to the forum, but none the less need some help.
I am writing an MD5Mesh importer in Python for a personal learning project and ive run into a problem with calculating the final vertex positions and its become quite an irritation. All of the example plugins seem to be doing different things and I have come to you all for some assistance. With a single bone influencing any vertex all is well, but as soon as a second bone comes into the situation the waters get turbulent and the vertices jump all over the place.
Attached are two examples, illustrating that the problem is clearly in local rotations, but once i get there all seems to lay out. The character is actually from Maya 2010, the second (What used to be a bird) is from Maya 2011
def calculateVertexPositions(self):
for mesh in self.Meshes:
counter = 0
for v in mesh.Vertices:
counter += 1
amount = int(100 * (counter/len(mesh.Vertices)))
cmds.progressWindow( edit = True, progress = amount, status=('Calculating Final Vertex Positions...' ) )
final = Vector3()
for weightOffset in range(0, v.WeightElements):
vWeight = mesh.Weights[v.WeightIndex + weightOffset]
vJoint = self.Joints[vWeight.JointIndex]
wsq = vJoint.Orientation.w ** 2
var = wsq - vJoint.Orientation.x ** 2 - vJoint.Orientation.y ** 2 - vJoint.Orientation.z ** 2
var2 = 2 * (vJoint.Orientation.x * vWeight.Position.x + vJoint.Orientation.y * vWeight.Position.y + vJoint.Orientation.z * vWeight.Position.z)
var3 = Vector3(var * vWeight.Position.x + var2 * vJoint.Orientation.x, var * vWeight.Position.y + var2 * vJoint.Orientation.y, var * vWeight.Position.z + var2 * vJoint.Orientation.z)
var3 += Vector3(
wsq * (vJoint.Orientation.y * vWeight.Position.z - vJoint.Orientation.z * vWeight.Position.y),
wsq * (vJoint.Orientation.z * vWeight.Position.x - vJoint.Orientation.x * vWeight.Position.z),
wsq * (vJoint.Orientation.x * vWeight.Position.y - vJoint.Orientation.y * vWeight.Position.x))
final += var3
v.setFinalPosition(final)
As soon as i get home ill upload a couple more screenshots of a cube i used for reference and you can see its distortion, as well as a stream of the Vertex positions before and after the Quaternion is applied.
Thanks ahead of time for your help!
| Attachment
|
|
| Attachment
|
|
|