Need help with function...
Blitz3D Forums/Blitz3D Programming/Need help with function...
| ||
Ok, I need a function that checks through each bone in a model, and checks for an identical (named) bone in another mesh. Then if it finds a match, parents the two together. I know it's possible, but I'm just not seeing how this will work out...Anyone know a good, efficient way to do this? |
| ||
First - "parent together" is something that doesn't exist. You may parent one to the other, but not in both directions, this would produce a hierarchy loop and probably crash the stack (that's why tools don't allow 2-way parenting). But maybe the simple parenting is working for your purpose too. I'd suggest you use a recursive hierarchy parser as seen in the codearchives ("how to make entityalpha work with animated meshes"). Additionally read in the versions.txt (blitz3d install folder) what the exact class string of a "bone" is. Blitz has no bones by definition, possible EntityClass$() return strings are Pivot Light Camera Mirror Listener Sprite Terrain Plane Mesh MD2 BSP I think your bones would be Pivots then. I am not sure if you can parent them and make them animate simultanously - probably you better determine the animation time of animesh 1 and apply it to animesh 2. |
| ||
Well, I mis-stated what I was trying to type...it doesn't parent them "together," it parents the bones of one mesh to identically named bones in another mesh, but not vice versa. Yes, they are pivots, used as bones in the animated models I'm working with. This system is for attaching unanimated, but rigged objects like clothing and armor to an animated, base character mesh. I finally got it working right, using manual attachment code, but now I need to write a function to do it automatically for me. I think I figured out how to do it now...if I need any help while I try it out I'll post a more specific problem. Thanks for replying, I hope I cleared up what I'm trying to accomplish... |
| ||
One problem that may pop up is: when you rotate a bone-pivot, the weighted vertices will be ignored and they will follow one pivot 100%ish (regardless of their connection to multiple pivots). At least that's what happened when I tried it last time. |
| ||
Odd, it seemed to work well in our tests... Anyway, this is what I came up with out of nowhere: Function AttachMesh(MeshToAttach,Mesh) For Children = 1 To CountChildren(MeshToAttach) Child = GetChild(MeshToAttach,Children) For OtherChildren = 1 To CountChildren(Mesh) OtherChild = GetChild(Mesh,OtherChildren) If EntityName(Child) = EntityName(OtherChild) Then EntityParent(Child,OtherChild) Exit EndIf Next Next End Function But, it fails at the first line, saying entity does not exist...when in fact I have passed the two entities to the function. Both are loaded as animated meshes to preserve the bones. Seems simple enough, but I get the feeling I'm missing something... |
| ||
Assume you have checked that MeshToAttach has a value > 0? Also, make sure you compare child to otherchildren to ensure that you're not parenting a child to itself .. I think will cause issues. Function AttachMesh(MeshToAttach,Mesh) For Children = 1 To CountChildren(MeshToAttach) Child = GetChild(MeshToAttach,Children) For OtherChildren = 1 To CountChildren(Mesh) OtherChild = GetChild(Mesh,OtherChildren) If Child <> OtherChild If EntityName(Child) = EntityName(OtherChild) EntityParent(Child,OtherChild) Exit EndIf EndIf Next Next End Function |
| ||
I don't think I should actually need to compare child to otherchild, since they are called from seperate meshes. I just tried checking to see if they actually had children first...keeps it from crashing but also results in nothing happening...like it's not recognizing the models bones as children entities. |