Jump to content

Need Help with Animated Textures


Dan22
 Share

Recommended Posts

For every frame, save it as a material (just like how water is done).

 

After that make an array with all the materials. From there you only need a few variables to loop through the array and assign it to the model.

 

Example of how I'd do it (C++ though, Lua should be similar):

Material aMaterials[10]; // For example 10 frames
float fCurrentFrame = 0.f; // Start at frame 0
int iMaxFrame = 10; // Amount of frames the array has
float fFrameSpeed = 1.0f; // Set desired speed here
void Start(){
  aMaterials[0] = Material::Load("./Materials/Animation/00.mat");
  aMaterials[1] = Material::Load("./Materials/Animation/01.mat");
  // etc
}
void Update(){
  // Animate
  fCurrentFrame += fFrameSpeed; // Note: Deltatime is not applied here
  // Did we reach our limit?
  if (fCurrentFrame >= iMaxFrame)
  fCurrentFrame = 0; // Reset
  // Assign material
  model->SetMaterial( aMaterials[ Math::Floor( fCurrentFrame ) ] );
}

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

Link to comment
Share on other sites

Or just cycle textures in one material, something like :

 

in start()

for i=1,numberfortextures,1
do
 tableoftextures[i]=Texture:Load("/path/to/texture"..i..".tex")
done

 

then in update()

i=i+Time:GetSpeed()
if i>numberfortextures then i=1 end
material:SetTexture(tableoftextures[math.floor(i)])

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

  • 5 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...