(C++) Material based texture animator

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
dwmitch
Posts: 52
Joined: Thu Nov 09, 2006 9:29 pm

(C++) Material based texture animator

Post by dwmitch »

Admittedly, all I did was change a few lines in existing files, so I won't post the full code here.

Go into the Irrlicht source folder and open CSceneNodeAnimatorTexture.cpp and CSceneNodeAnimatorTexture.h.

Under the existing member variables in the header file add one called matIndex. Then add the parameter MatIndex to the argument list of the constructor, placing matIndex(MatIndex) in the initializer.

Under the function that swaps out the textures (can't remember exactly what it's called and I don't have access to the file here) there will be a line that says

Code: Select all

node->setMaterialTexture(0, textures[Idx]);
Change that to

Code: Select all

node->getMaterial(matIndex)->Texture1 = textures[idx];
(or possibly node->getMaterial(matIndex).Texture1 = textures[Idx]. Never can remember until I get a compile error)

Do a find and replace (ctrl+H in Visual Studio 6, don't know about other IDEs) in both files and replace "CSceneNodeAnimatorTexture" with "CMyAnimatorName" (I renamed it CSceneNodeAnimatorSkyBox because I originally had it in mind for animated skybox textures), and then save both of these files into your project's folder as <CClassName>.cpp and <CClassName>.h.

For actual useage consult the custom scene node tutorial, or you could build it into a custom library (consult with someone more experienced, as I either end up with a crapload of build errors or a dll that crashes everything when it does build).

This has only been tested with the skybox scene node, but it should be able to work with any multi-material node, and it could possibly be expanded to allow you to specify a texture layer.
Post Reply