Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs

MeshSkinner (for Unity 3D)

Make SkinnedMeshRenderer components in Unity games during runtime. · By Winterdust

MeshSkinner Support Sticky

A topic by Winterdust created Sep 27, 2016 Views: 491 Replies: 14
Viewing posts 1 to 8
Developer
If you're having any trouble please feel free to post about it here and I'll help out.

Would you consider offering a pro version at some point that included source, or an engine augnasic version?

Developer

Sorry for the late reply, at the moment no such thing is on the horizon.

(1 edit)

I am trying to get my Humanoid character to use Mesh Skinner, There seems to be an issue in my heirarchy as the bones array is out of range..  I am not sure what I have done Incorrectly. The Skeleton layout is there my skin model is inside  LP_Female/ZbrushModelMesh3D and then I added all my clothing to Mesh Objects.. Note prior to the screen shot everything was separated. -Levon

Figured it out now I just need to see how to relax some of the weights

Hello, i get the same error : indexoutofrangeexception: array index is out of range. can you share please how to solve it?

Any help on error : indexoutofrangeexception: array index is out of range?

Developer

It's a little vague, I don't know where that error could have appeared.

I'm trying this tool for the first time, and getting a NullReferenceException in MeshSkinner.preWork.  I have definitely given it valid model and skeleton references; and in fact it moves the skeleton inside the model before dying with this error.

Any ideas?  And, do you have any faster means of support (such as email)?

Developer

Hi! It's possible that Unity has changed something again, what version of Unity do you have and is there a larger error message / stack trace? My e-mail is contact@winterdust.com

(1 edit)

Hi there! I'm trying to use the demo versions of mesh skinner and bhv importer to import animations from here. I'm using this model. Here is the script I used to do the job:

(I tried both debug and regular skeleton)

Also, I tried to rearrange the hierarchy of the dummy model to match the hierarchy of the BHV skeleton:



Results between debug skeleton and regular one were slightly different but both very wrong. Here is the result with the debug skeleton:


You can imagine that the motion of the mesh won't match the skeleton. Is there something I'm missing? We want to use both of this plugins in our project but can't run the demo versions. Thanks for the help :)

PS: I also tried a couple of other models from turbosquid and got similar results.

Developer

You need to use BVH to create a skeleton in the rest position, then you move the skeleton GameObject to align with the rest position of the model, then you use MeshSkinner to apply the skeleton to the model. The problem here is that the BVH rest position has the arms straight down but the model rest position is in T-pose.

In the example below I rearranged the arms of the model you linked to so they became a child of the shoulder GameObject and then I rotated and repositioned the shoulders so the model was no longer in T-pose. This was done in Unity with "dummy_obj.obj" (didn't use Blender or something else). Now the rest pose of the BVH was roughly the same as the rest pose of the model and I could align the skeleton with the model.

The arrangements was made in Unity's play mode with a debug BVH skeleton (xray turned on). After everything looked good I copied the root "dummy_obj" and stopped play mode. The model was reset, I deleted it and then pasted the arranged version. Now when I enter play mode the model is aligned with the skeleton created by BVH.

Finally I call BVH's static animateSkeleton() helper method to animate the thing. I used "Full-body Walking" from the page you linked to (notch-format.bvh), it was tiny so I scaled it up by 100 to fit the model. I imported the BVH at 10 fps and looping between frame -36 and -10 with an extra loop keyframe added produced a seamless walking animation. However, due to the rest pose of the BVH the MeshSkinner incorrectly thinks part of the model's hip is part of the hand bone. It might be possible to tweak this issue away in MeshSkinner before the work call, but best would be to find .bvh files that have the skeleton rest positions in T-pose or A-pose.

BVH bvh = new BVH("C:/temp/notch-format.bvh", -10);
bvh.scale(100);
GameObject skeleton = bvh.makeDebugSkeleton(animate:false, xray:true);

MeshSkinner ms = new MeshSkinner(GameObject.Find("dummy_obj"), skeleton);
ms.workAndFinish();

Animation a = BVH.animateSkeleton(skeleton, bvh.makeAnimationClip(-36, -10, true));


Developer

Depending on how well you fit the skeleton inside the model you might want to instruct MeshSkinner to not "ignoreJointsUntilInsideMesh". Below is a version of my example code with makeSkeleton() instead of makeDebugSkeleton(). I had to set ignoreJointsUntilInsideMesh=false because when makeDebugSkeleton() is called with a jointSize!=0 meshes are created to visualize the joints, causing makeSkeleton() to look different. I've made a note to try to fix this if I update MeshSkinner (will make the work routine not take meshes on the skeleton GameObjects into account).

BVH bvh = new BVH("C:/temp/notch-format.bvh", -10);
bvh.scale(100);
GameObject skeleton = bvh.makeSkeleton();  //changed line
MeshSkinner.DESTROY_ORIGINAL_MESH_RENDERER = 1;  //new line
MeshSkinner ms = new MeshSkinner(GameObject.Find("dummy_obj"), skeleton);
ms.workAndFinish(ignoreJointsUntilInsideMesh:false);  //changed line
Animation a = BVH.animateSkeleton(skeleton, bvh.makeAnimationClip(-36, -10, true));

While testing with Unity 2019.1 it seems like an old quirk have been fixed in Unity now, creating "SkinnedVersion" GameObjects is no longer needed. That's why I'm setting DESTROY_ORIGINAL_MESH_RENDERER to 1 above, it's not needed but should free up some resources while the game's running.

Another issue I noticed with Unity 2019.1 is that system locale matters now (coutry number formats, "comma instead of period"). Thanks to this BVH could throw FormatException when parsing numbers. Hopefully this is just something Unity has overlooked and will revert, I don't see it as a good thing when code don't run the same on different computers simply because comma is expected instead of a period. I'll take the possibility into account if I update BVH but in the meantime this can be fixed by defining the desired culture in your code (only needs to be done once, before the BVH class is used):

System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");

Thank you for the quick and detailed answer :)

It worked nicely, thank you very much!