Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® Maya® / Python / MD5 Mesh Reader Troubles
  RSS 2.0 ATOM  

MD5 Mesh Reader Troubles
Rate this thread
 
50812
 
Permlink of this thread  
avatar
  • Bob_Gneu
  • Posted: 28 December 2010 03:32 PM
  • Total Posts: 5
  • Joined: 27 December 2010 01:36 AM

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.progressWindowedit Trueprogress amountstatus=('Calculating Final Vertex Positions...' ) )
 
 final = 
Vector3()

 for 
weightOffset in range(0v.WeightElements):

 
vWeight mesh.Weights[v.WeightIndex weightOffset]
 vJoint 
self.Joints[vWeight.JointIndex]

 wsq 
vJoint.Orientation.** 2

 
var = wsq vJoint.Orientation.** vJoint.Orientation.** vJoint.Orientation.** 2
 var2 
* (vJoint.Orientation.vWeight.Position.vJoint.Orientation.vWeight.Position.vJoint.Orientation.vWeight.Position.z)
 
 
var3 Vector3(var * vWeight.Position.var2 vJoint.Orientation.x, var * vWeight.Position.var2 vJoint.Orientation.y, var * vWeight.Position.var2 vJoint.Orientation.z)

 
var3 += Vector3(
 
wsq * (vJoint.Orientation.vWeight.Position.vJoint.Orientation.vWeight.Position.y),
 
wsq * (vJoint.Orientation.vWeight.Position.vJoint.Orientation.vWeight.Position.z),
 
wsq * (vJoint.Orientation.vWeight.Position.vJoint.Orientation.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
Attachment Attachment
Replies: 0
avatar
  • Bob_Gneu
  • Posted: 28 December 2010 07:22 PM

The Weight class has an Index (int), JointIndex (int), WeightScale (float) and Position (vector3)
The Joint class has a Bone Name (string), ParentIndex (int), Position (vector3) and an Orientation (quaternion)

The file stores the X, Y, Z components of the Quaternion and you need to calculate the W component from something like the following:

1.0 - (q.** 2) - (q.** 2) - (q.** 2)
q.0.0 if 0.0 else -1.0 math.sqrt(t)


So all is well up to this point.

Executing my script i get everything loaded, and then it tries to render it. Below you will see two reference meshes that i rendered for example. The first two are pre import, the second are post.



Attachment Attachment
Attachment Attachment
Attachment Attachment
Attachment Attachment
Replies: 0
avatar
  • Bob_Gneu
  • Posted: 28 December 2010 07:46 PM

So here is my process for the files up to this point:

1. Create a cube/simple mesh.
2. Add a single joint at its center and apply full weight to all vertices in the mesh.
3. Export from Maya into UDK.
4. Export from UDK into MD5Mesh format (UModel assisted).
5. Load the exported file into MD5Mesh Viewer and confirm file is not corrupted.
6. Pass file path into my Maya MD5Mesh importer script and wait for completion.

This works fine.

The trick is that this file format has the positions impacted by multiple weights/joints and you have to calculate the position afterwards. So it makes sense that a single joint would be fine. I then repeated these steps, this time with two and then ten bones, figuring if it worked for two and it worked for ten i could be happy with a process and move it over to a full blown plugin for maya and not need to pass around the Python script.

Attached are two meshes, one a test cube with two linked joints which works and the second a bird which does not with 10 linked bones. (Apparently i cant attach the files, here are links to them)

http://projects.gneu.org/md5mesh/CubeTest.md5mesh
http://projects.gneu.org/md5mesh/Reference_MultipleBones.md5mesh

Also attached is the current draft of the script for loading the mesh into Maya. Tested on Maya 2010 and Maya 2011
http://projects.gneu.org/md5mesh/draft.php



Replies: 0
avatar

Hello

Could you give me some tips for a simple import of “.md5mesh” files.

Windows 7, 64bit, Maya or 3DSmax 2011.

Cheers, Claude



Replies: 0
avatar
  • Bob_Gneu
  • Posted: 23 February 2011 04:05 PM

Sure, but my mesh reader is still broken.

Do you have a certain area you need tips in?



Replies: 0