Forum

Blend4Web utility function

09 April 2015 22:33
I would recommend you to thoroughly examine webplayer app, especially parts connected with interface (html and css). Understanding will be the best answer for all your questions. I wish you luck!
24 April 2015 08:54
HI master
i found json file define mix color,

                        "name": "Mix",
                        "type": "MIX_RGB",
                        "inputs": [
                            {
                                "name": "Fac",
                                "identifier": "Fac",
                                "is_linked": true,
                                "default_value": 0.5
                            },
                            {
                                "name": "Color1",
                                "identifier": "Color1",
                                "is_linked": false,
                                "default_value": [
                                    1,
                                    0.859,
                                    0.55,
                                    1
                                ]
                            },
                            {
                                "name": "Color2",
                                "identifier": "Color2",
                                "is_linked": false,
                                "default_value": [
                                    0.638,
                                    0,
                                    0.04,
                                    1
                                ]
                            }
                        ],


i want use html& js get default_value and click some buttom change default_value color ,how do it ?
24 April 2015 10:35
Hi, Iaishi,

With API you can change only "Value" and "RGB" nodes. This is made as an optimization. If you construct material properly, this would be always enough. For example, put "RGB" node to the input of your "Mix" node.

You can do this with the recently introduced API from the object module.

Say, you have and object cube with some material named "Material". You can change the color of "My_rgb_node" node to red with the following code:
var m_scs = require("scenes");
var m_objs = require("objects");

var cube = m_scs.get_object_by_name("Cube");
m_objs.set_nodemat_rgb(cube, ["Material", "My_rgb_node"], 1, 0, 0);
24 April 2015 12:15
Thank you our developer Evgeny Rodygin:
Through my efforts, but failed, because I was too stupid!

I present my error code

I want to by clicking on the above color change the color of the cube
I didn't have know JS friends, I ask you my teacher, PLZ fix the error code.
Thanks+
24 April 2015 13:02
Ответ на сообщение пользователя laishi
Thank you our developer Evgeny Rodygin:
Through my efforts, but failed, because I was too stupid!

I present my error code

I want to by clicking on the above color change the color of the cube
I didn't have know JS friends, I ask you my teacher, PLZ fix the error code.
Thanks+

It is a bad practice to put JS code to your index.html. Better to move it to cube.js script. main_canvas_click should look like this:
function main_canvas_click(e) {
    if (e.preventDefault)
        e.preventDefault();

    var cube = m_scenes.get_object_by_name("Cube");
    m_objs.set_nodemat_rgb(cube, ["Cube-Mat", "My_rgb_node"], 1, 0, 0);
}


Getting proper color from html elements is a different story. And it is not directly related to Blend4Web. One of solutions is to register onclick event on your "<div>" elements and process cube in their callback instead of main_canvas_click function.

P.S. In order to change colors, object must have Force Dynamic Object flag on it.
24 April 2015 19:19
can you help me use this project as As an example?
25 April 2015 00:43
Just fix your project according to Evgeny's hints and the success will be yours . Also check our new Code Snippets app from the SDK, especially snippet called "Material API" (last cube is exactly the same thing that you are trying to implement here).
12 August 2015 07:51
Last post for tonight! I've been jumping around subjects in the "Discussion" section just to publicly praise and thank the B4W team for your hard work and cheerful, generous attitude! I appreciate it greatly! Thanks very much! I figure not everyone looks at every thread so I can cover my bases better this way.

Feel free to delete this!
 
Please register or log in to leave a reply.