Forum

Mixing APP_ASSETS_PATH with INHERIT_MATERIAL

13 July 2017 22:58
Hi Everyone,

Having a much better day today with B4W. Starting to get the hang of it.

Hopefully this should be a simple answer for someone, as I'm getting a bit smarter and know how to ask the questions more efficiently.

I'm trying to inherit a material from one blend file to my primary app blend file.

Steps I've taken so far:

Made 2 projects (the primary ((tex 1)) with a JS callback node) and the secondary ((tex2)) with nothing more than a cube and material.

I've saved the blend file and JSON file from 'tex2' along with moving the material texture in the 'tex1' project directory.

I've included 'obj', 'mat', 'scenes' and 'logic nodes' into my require list.

…Appended my function to a custom call back and written the following code (I'm taking baby steps remember)

m_data.load(APP_ASSETS_PATH + "my_project_Tex2.json");


This doesn't do anything unpredictable, it simply imports the cube from the my secondary blend file to my primary. Which is a good start… NO CONSOLE ERRORS YEEHAR!

But obviously I'm wanting to only import the material from the cube in 'tex2'.

So how do I amalgamate my 'secondary APP_ASSETS_PATH' with:

var cube1 = m_scenes.get_object_by_name("Cube1");
var cube2 = m_scenes.get_object_by_name("Cube2");
m_mat.inherit_material(cube1, "MyMaterial_1", cube2, "MyMaterial_2");


Thanks in advance
14 July 2017 04:45
Your second object and its materials are going to be wrapped up in one JSON file. You won't be able to import part of it. Take a look at load() in the data module.
Example:
var m_data = require("data");
//load an object in hidden mode
m_data.load(ASSETS_PATH + "your_object.json", loaded_cb, null, null, true);
14 July 2017 10:41
Hi Charlie,
you can also find useful info about material inheritance here: documentation.
Blend4Web Team
14 July 2017 22:07
Thanks Will, thanks Ivan.

So, Will, what you're saying is, technically I have to import the secondary object before I can inherit a material from it. I can't just reference the object and inherit/import it's texture to my target mesh?

This isn't a big deal, as I'm building a room configurator and there's only so many core materials I'm ever likely to use; 'Surface Glossy', 'Surface Matte', 'Semi Reflective', 'Fully Reflective', 'Metallic' and 'fabric'. I don't even think I'll need complex materials with normal maps, as I'm shooting for performance over photo-realism.

I could just have 5 or 10 spheres behind the camera.

So, Ivan, 'Replacing Textures' is probably the only external reference I'll need.

Here's how my UI structure is going to work.

I'm using a multi level menu (one menu heading for each core material) for a two step selection process.

You click an object on screen, and using an 'object_is_selected' method, the corresponding menu appears in an Iframe.

So let's say the object is 'the floor' and is selected. - A pertinent menu appears in the iFrame, with top level selections; 'Carpet', 'Wood', 'Ceramic' and 'Vinyl'. When one is selected the selected object inherits the correct material.

The second level of the menu (a drop-down or similar) shows the different 'woods', 'carpet patterns' etc. These are only textures and I intend to use the 'change texture method' with an external file structure (I hope to eventually plug this into a CMS).

So, providing that all of my textures are seamless and the target objects are UV un-wrapped and their scale is believable (and they're based on the same 'standard' as the ones contained within the 'donor material'), I should be able to simply flip from texture-to-texture within the 'selected object' without affecting the material that it was inherited from right?

C
15 July 2017 02:22
I could just have 5 or 10 spheres behind the camera.
I was just reading the documentation Ivan linked. You can have just one simple plane object with all of your materials on it to use as a library in your scene.

You can then use the Inherit Material node to pull materials from it.
17 July 2017 11:04
So, providing that all of my textures are seamless and the target objects are UV un-wrapped and their scale is believable (and they're based on the same 'standard' as the ones contained within the 'donor material'), I should be able to simply flip from texture-to-texture within the 'selected object' without affecting the material that it was inherited from right?
When you inherit a material you get a copy of it on an object. So, texture replacing will affect the copied material only, but not the material on the donor object.
Blend4Web Team
18 July 2017 19:59
Thanks Ivan. That's not an issue though, as I'm assigning the material to 'the target' first, in the selection process.

Thanks guys
 
Please register or log in to leave a reply.