论坛

由用户创建的信息 Ivan Lyubovnikov
28 July 2017 14:25
Actually, lamps cannot be loaded dynamically. The only solution is to have them all in the initial scene and turn on/off at a proper time by using the set_light_energy or hide_object/show_object methods.
27 July 2017 12:48
Но скорость оставляет желать лучшего…
А насколько сильно тормозит? Взятие скриншота вообщем-то не для реалтайма, как разовое действие может сойти, но, если нужна хорошая отзывчивость, например, перелистать несколько страниц подряд, то не очень подходит.
Вот, кстати, есть демка, где пишется видео в канвас текстуру: canvas_texture, если она у вас не тормозит, то проблемы - действительно именно со взятием скриншота.

А какими еще способами можно сделать скриншот канваса? Я знаю, что есть целый метод SCREENSHOTER Он вроде работает быстро. Можно ли как то его переделать под себя? Как я понял кроме функции shot он больше ничего не умеет?
Ну, по сути, мой пример - это и есть переписанный метод, который в итоге вызывается функцией shot , вот исходники: ссылка, только там просто формируется ссылка для скачивания через тот же параметр url. Других методов в API движка для взятия скриншота нет, если только самому что-то пробовать переписать.

Вообще ещё есть способ рендерить в текстуру - там вообще без скриншотов - возможно, вам подойдет.
26 July 2017 12:37
Добрый день, в canvas_data_url можно передать callback, в который придет url blob-объекта, содержащего данные скриншота. Потом его можно отрисовать в canvas-текстуру, которую заранее подготовить на объекте в Блендере.

Вот как-то так, например:
function click_cb() {
    var cube = m_scenes.get_object_by_name("Cube");
    var img = new Image();

    var cb = function(url) {
        img.onload = function() {
            var ctx = m_tex.get_canvas_ctx(cube, "Texture");
            ctx.drawImage(img, 0, 0);
            m_tex.update_canvas_ctx(cube, "Texture");
        }
        img.src = url;
    }

    m_main.canvas_data_url(cb, "image/png", 1.0, true);
}
26 July 2017 12:12
wow, I get it. Thanks, Ivan. And another question, can the fps be set?
you can try to limit the maximum fps like that:
m_config.set("max_fps", 10)

but this can be inaccurate, because it's mostly a debugging feature
26 July 2017 12:09
Hi, looks like an engine bug. Can you provide us an example to reproduce?
26 July 2017 11:46
Or is it possible somehow to control the position of a texture, like "10% from top, 3 % from left, do not stretch"?
This can be done via the special node material setup, when you have several "Value" nodes for changing the UV map for a texture. These nodes can be controlled via the set_nodemat_value method.

Have a look this file: nodemat_value.blend - here you'll have a Value node for controlling the Y coordinate of the UV map. You can try the following code to play with it:
var cube = m_scenes.get_object_by_name("Cube"); 
m_material.set_nodemat_value(cube, ["Material", "Value"], 2.5);
26 July 2017 11:21
Hi, you can also look at the source code of the "shot" method. It utilizes the canvas_data_url function for getting the URL of the corresponding Blob object, which represents a screenshot data. This function accepts a callback, in which you can send the data to the server in two requests: one for getting the blob object from the URL parameter and another for sending it to the server.

function screenshot_to_server(format, quality) {
    format = format || "image/png";
    quality = quality || 1.0;

    var cb = function(url) {
        // getting the blob object from URL
        var xhr = new XMLHttpRequest();
        xhr.open("GET", url, true);
        xhr.responseType = "blob";
        xhr.onload = function(e) {
            if (this.status == 200) {
                var blob = this.response;

                // sending the data to the server
                var xhr = new XMLHttpRequest();
                xhr.open("POST", "URL_TO_MY_SERVER", true);
                xhr.send(blob);
                xhr.onload = function(e) {
                    if (this.status == 200) {
                        console.log("Uploaded successfully!");
                    }
                }
            }
        };
        xhr.send();
    }

    m_main.canvas_data_url(cb, format, quality, true);
}

- just replace "URL_TO_MY_SERVER" with a valid url address.
26 July 2017 10:36
Hi berdon,

there's the method set_fps_callback. The callback executes every frame and gives you the actual fps value:
var m_main = require("main");

m_main.set_fps_callback(function(fps_avg, phy_fps_avg) {
    console.log("current fps is", fps_avg);
});
26 July 2017 10:11
We have tested it now on several devices and the bug has been fixed. Thanks.
Nice! Glad it helped!
25 July 2017 18:57
I've implemented the code change (re-compiled the viewer as well) and it didn't help.
We have also tested now on version 17.06 and everything is fine there.
Hmm, I guess some changes that may fix this bug were applied since 16.12.1, cannot say exactly though.
Another fix you can try is to disable webgl2 in the src/config.js module:
webgl2                     : false,

at this line: source.