How to use Clone() on Animatedtexture
AnsweredI saw that there is a clone() function on Animated Texture Provider. https://lensstudio.snapchat.com/api/classes/AnimatedTextureFileProvider/
So I tried it, but got an error.
How to use this function properly?
function init(){
var myLength = script.objBird.length;
for(i=0;i<myLength;i++){
birdTex[i] = script.texBirdAnim.control.clone()
script.objBird[i].getComponent("Component.Image").mainPass.baseTex = birdTex[i]
script.objBird[i].getComponent("Component.Image").mainPass.baseTex.control.play(1,0)
}
}
init();
-
Can anyone can help me with this? Thanks!
Comment actions -
What error did you get?
Comment actions -
Hey,
Pls send the error what you get that we can help you!
Best,
justin.crxComment actions -
Hi, I tried it again today with simplified version of the script
// @input SceneObject imageA
// @input SceneObject imageB
var cloneTex = script.imageA.getComponent("Component.Image").mainPass.baseTex.control.clone()
script.imageB.getComponent("Component.Image").mainPass.baseTex = cloneTex
Please let me know how to use this properly!
PS. The imageA has animated texture on it
Thanks!Comment actions -
Comment actions
-
Yeah, I saw that. Before I post it in here, but as you can see it gives me error.. can you give me example of how to use this in script? Thank you!
Comment actions -
Hellooo??? its been 7 days but no one answer my simple question
Comment actions -
Hi, Jhonnel Pica
The clone method actually clones Texture Provider and not a texture itself.
You have to set cloned texture provider to be a control of another texture. This should work :
// @input SceneObject imageA
// @input SceneObject imageB
var control = script.imageA.getComponent("Component.Image").mainPass.baseTex.control.clone();
script.imageB.getComponent("Component.Image").mainPass.baseTex.control = control;
control.play(-1, 2);Note that I assume you are using default material on the Images.
Please let me know if this works for you! I can attach example project if needed
Best
Olha
Comment actions -
Thanks Olha , the code works but not what I expected because I thought that it will clone the texture itself so I can offset other animation without duplicating the same texture animation.
Comment actions -
I see! It's not that straightforward but still can be used for your case. You just need a texture reference to set provider to, that's why i was using default material.
You can also use proxy texture asset for this
Comment actions -
Olha how did you use proxy texture? theres no setting when I click on it
Comment actions -
Hi, Jhonnel Pica
It's just an empty texture before anything is assigned to it. You can use it to create your copy. For example:
// @input Asset.Texture fromTexture
// @input Asset.Texture toTexture
var control = script.fromTexture.control.clone();
script.toTexture.control = control;
control.play(-1, 2);And now you can use that proxy texture resource in Materials right away
My setup :
Best
Olha
Comment actions -
Wow!! Thank you so much @olha .. This is a nice trick!
Comment actions
Please sign in to leave a comment.
Have a comment?