Search Unity

Rigging INSIDE Unity?

Discussion in 'Scripting' started by theBundyXVO, Sep 22, 2014.

  1. theBundyXVO

    theBundyXVO

    Joined:
    Sep 15, 2014
    Posts:
    24
    I'm working on a free, open-source 3D modeling project using the UnityEngine and I was wondering if it would be possible to rig and skin a mesh all inside of Unity and have the ability to save and export the rigged model? If not, can pass on on some knowledge give on how to achieve this through something else (such as Javascript Engines of some sort)?
    Any help would be loved, thanks all.

    P.S sorry for not going into better detail & dp, let me know if you need it.

    EDIT : The rigging doesn't have to be interactive, I'd actually like to spawn the bones myself and allow them to be placed inside of the mesh by the user (like the Rigify plugin for Blender).
     
    Last edited: Sep 22, 2014
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Rigging and skinning is possible. Check out the Mesh class documentation and in particular the boneWeights property. (I've never done it, but it looks fairly straightforward.)

    Saving and exporting the model, you will probably have to write your own serializer.
     
  3. theBundyXVO

    theBundyXVO

    Joined:
    Sep 15, 2014
    Posts:
    24
    Thank you so much for your help! But can you give me a bit more detail on this, a little more direct to rigging/skinning? The Mesh Class is pretty broad to which makes it hard find both things. Also, this is gonna be a complied program so its not going to be running through the Editor itself.

    Thanks again, bvo.
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Again, I've never used that part of the script API myself. But the idea is that each vertex is influenced by one or more 'bones'. Each bone has an index (basically, its placed in a particular array in the SkinnedMeshRenderer), and a weight; a vertex may be 60% "the bone on the left" and 40% "the bone on the right".

    Start with something simple, and build your skills up. You ARE going to have to master the Mesh class to make this project work. So, start build a single quad in script. Then a more complex mesh. Then, create two transforms (your bones), one on each side, and assign every vertex those two bones, with bone weights that smoothly blend from one to the other - you should be able to (after the mesh is generated) grab and move those bones around freely, and the mesh will stretch between them. Around that point, how to accomplish your actual end goal should start to become apparent in your mind.
     
    theBundyXVO likes this.
  5. theBundyXVO

    theBundyXVO

    Joined:
    Sep 15, 2014
    Posts:
    24
    You said that beautifully, it was clear and right to the point. I appreciate your help, seriously. My main questions though,

    1. "create two transforms (your bones)", what exactly can I use as my bones/transforms? Cubes/spheres game-objects?

    2. "assign every vertex to those two bones, with bone weights that smoothly blend from one to the other" I hate to keep asking you to do research for me, so I'm sorry man, but are there any tutorials or solid information how exactly I can do this? This information is great, I completely follow you on it, but I haven't the slightest clue on how to do exactly that (applying vertexes to bones and then weighting the bones)?

    3. Also, I was hoping to have a system as to where the bones would be assigned to the vertexes all around the area the bones covered (which I don't believe you could do with something like a raycast?) Any way on doing that?
    Hopefully in the end I'd be able to also animate the newly rigged/skinned mesh.

    Also, thanks again, your helping me and alot of other people right now!
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    1. Just an empty GameObject. You can use cubes or spheres if you want to be able to see where they are (for debug purposes), but typically, bones have almost nothing on them.

    2. Like I said, I can't really help you much more on this one than the docs can, as I haven't done it myself. This is one of those things that should become clearer as you get to that point in the "learning the Mesh class" process. Once you get the basic manipulation of vertices under your belt, if you still can't figure this out, then it'll be time to come back with more questions :)

    3. Well, the bone doesn't "cover" an area - it's just a point in space and a rotation, essentially (well, and a scale, but you rarely use scale in skeletal animation). But you can loop through each vertex, and within that vertex, find the nearest bone and make that bone the vertex's bone. (Or, find the nearest two and use their relative differences as weights, or whatever other logic you want to apply to that)
     
    theBundyXVO likes this.
  7. theBundyXVO

    theBundyXVO

    Joined:
    Sep 15, 2014
    Posts:
    24
    I can't thank you enough, you're awesome. :)
    +1000000000000000000000000.
     
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    theBundyXVO likes this.
  9. theBundyXVO

    theBundyXVO

    Joined:
    Sep 15, 2014
    Posts:
    24
  10. theBundyXVO

    theBundyXVO

    Joined:
    Sep 15, 2014
    Posts:
    24
    Just to reply, the above was right, there is no current way to connect selective vertexes to a mesh at this moment, you can only loop ALL of the vertexes to a mesh sadly.
     
    Last edited: Sep 23, 2014