Forum

Configurator and inherit material

02 September 2017 17:51
Hello Everyone,

we're evaluating blend4web to use as one of the tools to develop an e-commerce configurator. The products we'll be selling will be made of different materials and components, but they will mostly include wood and different types of fabrics.

I understand that I cannot control all the parameters in a given material via the javascript API, so to replace a component material we need to define those materials in blender first, assigning them to dummy objects, and then use the inherit_material method. However, I'm trying to understand what would be the best option performance-wise.

I can create all meshes in blender, and have invisible dummy objects in the same blender file, one per each possible material that could be used for that product, and just use the inherit_material to replace the material making the selected product component inherit the material from one of the dummies when the corresponding material thumbnail is clicked in the e-commerce software. Or I could have different blender files, one per each of the possible materials, and use the inherit_material method too, but load the dummy mesh blender file on the fly on top of the current scene first, based on the user material selection.

In the first option, I would have all the materials already available to be inherited, but the initial scene would probably take longer to load. In the second case, initial load would be much faster, but the material replacement would take longer to refresh, since we would have to load the additional dummy blender file on the fly.

I'm not clear on how textures are loaded. Are they loaded into the scene when none of the meshes in the scene is using them? If they are, since we will have lots of possible materials, the initial load may take an extremely long time, and users may leave the site before the scene loads, and in that case, the separate blender files per material approach makes more sense.

Can you please clarify how that works so we can define our approach to the problem?

I hope the question makes sense. Thank you very much!
03 September 2017 06:20
Hi Scalere, welcome to the forum.
If you haven't already, have a look at the Materials Module.

You can apply all of your materials to one simple mesh and load it as a hidden object. Then inherit from it as needed. If you want to load it on the fly, you could create a .blend for each material, export each one into JSON format, then load it as needed. Each texture will load attached to an object as part of a JSON file. So when you load the JSON file, you will get any materials that are on the included objects. Have a look at the materials module linked above, it may reduce the number of unique materials you need to load. You can change the image texture as well as a number of material properties.
04 September 2017 16:28
Hello Will, thank you very much for getting back to me.

I guess my question was not clear enough. I've been doing tests with the materials module already, changing values, but also using the inherit_material method. Because of the complexity of the materials we have to work with, I thought that creating them in blender with nodes, and using inherit_material would make more sense. Eventually, we may change the textures on the fly, but that will be an exception.

I understand that all the materials applied to objects in a scene will be loaded when you load the scene, but does that mean that all the textures used for a given material will also be loaded along, even though the objects that use those materials are not currently visible in the scene?

Let's say I create a dummy mesh and apply all my materials to it (they could be more than a 100 materials, many of them using different texture files). And that I have that mesh in the same JSON file as the actual mesh that will get those materials applied based on user interaction. Will the initial load have to wait for all the textures used in all those materials to get loaded, even though most of those materials are not going to be visible at the initial display?

In that case, the dynamic loading of additional JSON files may make more sense. Does this clarify my question?

Thanks again!
04 September 2017 23:21
I understand that all the materials applied to objects in a scene will be loaded when you load the scene, but does that mean that all the textures used for a given material will also be loaded along, even though the objects that use those materials are not currently visible in the scene?
Yes, they will load. You can use the "Hidden" option in the object menu.

You can load a materials library object with its materials at a later time, dynamically.

If you have a look at the Cartoon Interior example project in your SDK, it loads objects (JSON files) in with a button press. It has separate .blend files for each of the objects that can be loaded after the main scene gets loaded.
04 September 2017 23:33
You may be able to load a simple mesh object with a given material at the time the user selects the color.
Have a look at the load() function in the Data module.
It has a parameter for "hidden" as well as a "loaded" call back that you might be able to use to 'get' its material and apply it to your selected object. I have never tried this but a simple mesh with only one material might load fast enough that you would not need a "loading new material" message for the viewer.
05 September 2017 01:33
That is exactly what I was referring to. I wasn't sure because I could not find any specific reference in the documentation about when exactly the texture files load did take place.

Thanks a lot, Will.
29 September 2017 02:19
OK, here is another question related to this issue. Let's say that my scene has a mesh that needs a normal map in its initial material. But based on user interaction, I need it to inherit a material from a dummy mesh from another json file that I will load dynamically like it was explained above. I want those dummy files to be re-usable, so that for example, a red velvet dummy could be re-used and have different meshes inherit from it. But if one of those meshes needs normal maps, the normal map will be lost when it inherits the material, right? Would I have to create one dummy json file per material AND normal map to avoid this? This would generate tons of files. Since I'm going to develop a configurator, the possible combinations could be in the hundreds.

Am I thinking this correctly?

Thanks again.
29 September 2017 12:19
Hi, do you mean that a mesh should always have a normal map applied on it even if it inherits a different material? In this case you're right - normal map is a part of a material and if it isn't presented in the inherited one, then it will be lost, because the inherit_material method overrides a material completely and doesn't combine them partially.

One possible solution is to create a dummy material with a normal map and swap the corresponding texture with the required one for a particular object immediately after inheriting.
29 September 2017 18:53
Hi Ivan,

thank you for getting back to me. And how would I do that? I mean, to swap the texture for the normal map only?
30 September 2017 00:20
OK, so after doing some more research, it seems I have to use replace_image() method in texture module, right?
 
Please register or log in to leave a reply.