Is it possible to change image texture after Render?

As the title suggest, I have just discovered the wonderful blend4web, the current project I'm working on requires me to be able to change the image on my render outside of blender.

I've been able to achieve this somewhat with babylon.js, but being the complete novice I am at javascript it's difficult to fully impliment what I want.

So basically, I have a plane for example, with a image mapped onto it, export out to blend4web, and I would now like a way to change that image via the code inside the html document, without needing to go back into Blender and change it?

Is this possible?

1 Answer

First, check version of blend4web:

Before 17.08:

//load modules:
var m_tex       = require("textures");
var m_scenes    = require("scenes");

//get object
var obj = m_scenes.get_object_by_name("_object_name_");

//change texture in object
m_tex.change_image(obj, "_texture_name_", "_image_URL_" );


After 17.08:

var m_scenes  = require("scenes");
var m_tex = require("textures");

var obj = m_scenes.get_object_by_name("_object_name_");
var image = new Image();
image.onload = function() {
m_tex.replace_image(obj, "_texture_name_", image);
}
image.src = "_image_URL_";


Where:

_object_name_ is the name of your plane in Blender:

_texture_name_ is the name of texture data block in Blender:

_image_URL_ url of your image in web.

More information:

https://www.blend4web.com/api_doc/module-textures.html#.replace_image

Live example:

https://www.blend4web.com/apps/code_snippets/code_snippets.html?scene=change_image

• Thanks for the quick reply! Nice to know it can be done, just need to decipher your answer and figure out how haha. – Facity Dec 12 '17 at 10:41