- Home /
Runtime mesh and bones stitching - is it possible and what is the right approach?
Hello there,
I'm new to Unity and after banging my head for a couple of days over what seemed like an easy task in the beginning I've decided to query the community wisdom as I'm running out of ideas, and perhaps I'm approaching this in a wrong way.
The goal is seemingly simple - I need to create a pipe which I can then extend in length and bend at will at runtime, in an animated fashion. The pipe is constructed out of three parts - female joint (FJ), the pipe itself (PIPE) and the male joint (MJ). So I've constructed a simple mesh which looks like:
====+========+====
\ | | \
/ | | /
====+========+====
FJ PIPE MJ
I've added a set of bones and weighted the PIPE part so I can easily bend it in the middle, and those bones are connected to the leading bones of the FJ and trailing bones of the MJ. This allows me to move the MJ and FJ parts easily while stretching (and bending if needed) the PIPE right in the middle.
But this causes two sets of problems. First, the mesh quality alongside the texture and the bend itself will severely degrade if FJ and MJ are moved too far apart; and second - I need to control where the pipe bends and with this setup it will always bend in the middle. Further, for my purposes I need the pipe to be able to bend more than once between the joints, which cannot be done this way (but I guess I can just omit the FJ part and 'connect' two pipe segments) So I thought I could add multiple pipe segments between the FJ and MJ segments and connect them together to control the length of the pipe as well as the point (or points) where it will bend, like:
====+========+========+====
\ | | | \
/ | | | /
====+========+========+====
FJ PIPE0 PIPE1... MJ
However, since in that case it is no longer the same mesh, the bones within each segment are not connected and I quickly end up having 100s of objects on the scene, having 100s of scripts executing to keep everything together which brings my quite powerful workstation to a halt and given that this has to be able to work on mobile devices as well it is apparent that I'm doing it wrong.
To more easily visualize the 'effect' I am trying to achieve you can think of the old 3D pipes screensaver, but where the pipe would gradually grow in a straight line to an undetermined size and then start bending at various points (moving and rotating all the parts in front of the bend while bending), while still growing.
So, any ideas or pointers on how to approach this in a viable manner?
Thanks a bunch in advance.