Forum

Change Texture for multiple Objects via Script

21 January 2019 09:58
Thank you very much, I wrote this code too fast ^^ Sry.
You helped me a lot Blend4life. From now on, i can work vey well with blend4web thanks to you.
Kind regards,

Bani
14 February 2019 16:22
Hello There,
thank you again for your very good help.
I have now another question. Can i use the Texture Change principal for Materials?
When yes, how?
Kind regards,

Bani
14 February 2019 16:23
And how can i reset everything
Kind regards,

Bani
14 February 2019 20:46
Well, as mentioned before, materials are switched with the m_material.inherit_material() method.

To reset to the original configuration, you simply add a function that puts the original texture/material on the object, and you call this function when the reset button is pressed.
15 February 2019 13:03
Hmm yea i read it. Hmm i just get errors. Must figure it out.

Here in the Link is the Upload Cube. The problem is, that the code you send me made the upload, but after the 2nd or 3th upload of images it stops. Also the Reset is not working anymore :/

Do you have an idea?
my_upload.zip
Kind regards,

Bani
15 February 2019 19:40
Oh, that project again.

Check the blend file. You have a messed up source path to the "logo" image in the texture node, still linked to a different project:

..\..\my_Upload_Project\my_upload_project\assets\logo.png

and that folder structure is bugged itself because you can't have a project folder "my_upload_project" inside a project folder "my_Upload_Project".

Whenever you get a zipped project from somebody, make sure that after unzipping you copy over to your projects folder the root folder of the project (where the little ".b4w" file is) so that it is directly under "projects", not with another folder in between. So your attempts to get this working should look like "projects/my_upload_project", "projects/my_upload_project2", "projects/my_upload_project_another_attempt" etc. etc. And avoid upper case characters and spaces if you can.

the Reset is not working anymore
Correcting the above-mentioned path fixes the reset. The path needs to be the project's own assets/logo.png


but after the 2nd or 3th upload of images it stops
Note how the uploads stop only if you re-try an image you already had, so there may be a caching/timing problem here in the filereader. Apparently it's not good enough to just say:

target.src = this.result;

So I added a "new Image" which waits for itself to get the filereader's result via another onload event. This seems to work now. I attched the new version ("uploadscript.js").
15 February 2019 19:46
I forgot to ask, why do you need inherit_material for an upload project? People cannot upload materials, only images, so why do you want to change whole materials?
18 February 2019 10:04
Thank you Blend4Life,
you helped me a lot. I am so grateful.

I would like to design a surface where i can change the material after uploading.
Changable should be high specular, medium specular and low specular.
Kind regards,

Bani
 
Please register or log in to leave a reply.