As an extension to my previous 2D spring physics worm generator here I have translated the form generation code into Unity and csharp and also made it function properly in 3D. Initially I tried to implement the spring/bone physics in Unitys built in PhysX engine, but it wasn’t very satisfactory. The PhysX engine seems to become very unstable after only a few links in a chain of joints, causing the structures to flinch and whip around. I opted to write my own system instead where I can control angle limits etc more accurately. I also moved to using quaternion storage and manipulation for the joint alignment. This avoids the nasty gimbal lock problems I was having with standard euler angles, it also makes it much easier to see the actual orientation of each bone, by observing the quaternions vectors (see image).
Initially I wanted to create a single skeletal form generation routine, but ended up having to produce a few individual ones as the underlying structural arrangements are different enough to warrant seperate construction routines. So far the basic layouts include, bilateral, rotational (radial), quartered(mirror/rotation), tube (circles along a spine) and fan (tree branch). Within each layout the following parameters apply to generate the final form: limb length, fork number, bone size, bone spacing and xyz rotations. Each of these values is a stochastic range which can be as limited or varying as the user/program requires. There are other arguments that could be exposed, but to use the parameters in any sort of organised gene structure they needed to be limited where possible and fairly interchangeable. I’ve uploaded a selection of form screenshots to my flickr stream here. There is a short video at the base of the page, showing form construction in realtime.