- INTRODUCTION -
First I want to point out that I'm talking about LW and not 3DS, it's possible that this would work with 3DS bones too but I haven't tried it. The second thing I want to point out is that I don't know if this is the best/fastest way, since I just got the idea about how it works. OK what is bones? Well have you ever seen the dancing baby? I'm sure you have. Have you ever wanted to make something so realistic in realtime? I'm sure you have that too. Well then the keyword is BONES! Sound like there is going to be some heavy math now? NO, the hardest part is to find out the distance between a point and a line, and that isn't too hard for you, right?
- THE BASIC IDEA -
A bone is presented as a vertex with a direction and a length (a line). I first thought that a bone was just a point but after I discussed my therory with Zyrax/Obscure he proved to me that it wasn't a point, thanks. All bones affect every vertex in the object with a "power" which depends on the distance between the vertex and the bone. When we have the power calculated for every bone->vertex (how to calculate it comes in the next section) the only thing we have to do is to rotate the object with the bone as the pivot point one time for every bone and then add the rotated points together depending on the power. Pretty simple hey!
- FIRST ENCOUNTER... PRECALC -
Okay, first of all we need the power from the bones and that is calculated by taking (1/Distance^x)*strength where x is a constant (1-16 in LW55) and strength is a variable you set for each bone in LW. Since the bone is a line we are going to get a "force field" around the bone that would look something like two half spheres with a cylinder between.
The cylinder would be the line and the half spheres would be the end points. Since distance=squareroot & squareroot=precalc we precalc the power when we load the scene. Okay now that we know how to get the power with which the bone affects a vertex we allocate some memory, enough to store one floating point number per vertex and bone that is NrBones*NrVerts*4 (yep, precalcs aren't supposed to be memory friendly), then we store the power at a vertex from each bone in this buffer. Now it's time to convert the power to percents. Just get the total power on a vertex by adding the power from every bone, then divide the power by the total power and we get a number between 0 and 1.0, store that number in the buffer instead of the power. Do that for every vertex and the precalc is done! Note that the bones rest position and rest direction should be merged into this precalc. Rest direction... Think about the object as rotated exactly as the bone, rest position as a piviot point.
- SECOND ENCOUNTER... USE IT -
Well now we have the precalc done and as that is always the hard part the only question left is, "What to do with the precalced values?" Remember that I said that we should rotate the object one time for every bone? That is exactly what we are going to do now, we take the first bone and set it to the piviot point, then rotate/scale/move the object in the same way that the bone is rotated/scaled/moved in the current frame, and save the new values. Note that you will have to multiply a rest direction matrix for the rest direction. Repeat this for every bone in the object. Okay, now we have 25 copies of the object rotated/scaled/moved in 25 different ways, what's next? Well, it's time to use the precalc! It's time to create the final object, do this by multiplying the precalced value for each vertex/bone with the new rotated/scaled/moved values and add together to the final object. Note that the polygon normals will be destroyed but you were already planning to use gouraud shading, weren't you? DONE! Sounds messy? Well use pen & paper and try to understand the theory before you try to code it, if you just understand the theory you won't have any problems implementing it.
- THIRD ENCOUNTER... FUNNY OPTIONS -
There are a lot of funny options in LW, such as limited range and muscle bending. What to do with them? Hmm, limited range is self explaning but muscle flexing and joint compensation... well, I haven't had the time to figure them out, but I think you just have to add some funny formula to the precalc. Mail me if you figure them out!
- FAQ -
* Where the f*ck is the source code? - Right where you saved it after you wrote it. * Who wrote this? - Bizze/TMB * How do I contact this guy Bizze? - ircnet #tmb or email@example.com * Aren't 3DS and LW copyrighted trademarks? - Yes, LW by Newtek and 3DS by Kinetix