NeHe OpenGL Lesson25 – Morphing & Loading Objects From A File
This sample shows us how to do vertex morphing and load objects from text files.
For vertex morphing, you could apply such technology to transform smoothly object A to object B, like transform a human being to a vehicle and so on. Actually, this is an old animation technology. As you see, we need to keep a whole vertex posture for each key frame. This will take a lots of memory space. So currently, such animation technology already replaced by the skin animation which use only one copy of the vertex data and those key frames data saved into the bones. And we also apply skin calculation on the GPU, this will improve the speed a lots. But vertex morphing still has it’s space, like transform one object to another one, because such transform data is very hard to convert into skin animation.
Vertex Morph Implementation
To morph, the vertex number of those two objects should be the same. That means, we need to do one vertex to one vertex mapping. For each vertex, we could do the following calculation to transform source object to destination object:
D = S – (S – D) / steps;
After the ‘steps’ steps later, we could find the right part (immediate part, or morphing part) fully equal to the left part (Destination). Then we get a D from S. That is it. This is all done by this sample.
Something More
Another topic mentioned here is that loading objects from text file. For some assets, like model vertex, animation saved as text is not a good idea. String parsing will take a lots of time, make them binarized should be much better. But we could still use text file, such as .xml file during the process of game development. We could use .xml to organize the scene structure, contain the map or level content, make a simple description of a special material or shader graph and so on. We could use text files as an immediate content, but should use it as the final asset format. Of course, you could use text file as configure file.
For more details, you could find the source code from here.