WorkerScript for heavy canvas3d application



  • I have a qt quick application (buttons etc.) for user control and a canvas3d animation in the middle of the screen. However loading the javascript files with JSON.loader for the cad model takes a lot of time and my application freezes for some time. I was trying to run extra thread for the animation with WorkerScript in QML.

    The problem is that i cannot give the canvas3d object (QObject) ot the workerscript. Any idea how to solve that problem?

    Canvas3D  {
    id: canvas3d
    anchors.fill: parent
    anchors.verticalCenter: parent.verticalCenter
    anchors.horizontalCenter: parent.horizontalCenter
    focus: true
    
    WorkerScript {
        id: myWorker
        source: 'workerscript.js'
        onMessage: console.log(message.reply)
    }
    onInitializeGL: {
        //GLCode.init(canvas3d)
        myWorker.sendMessage(canvas3d)
    }
    WorkerScript.onMessage = function(message)
    {  
    initScene();
    initCamera(message.canvas)
    initMeshObjects();
    initRenderer(message.canvas);
    WorkerScript.sendMessage({'reply': 'WorkerScript done!'});
     }
    
    function initMeshObjects() {
        // ![1]
        var loader1 = new THREE.JSONLoader();
    
        loader1.load('/rightBack/chrome11.js', function(geometry, materials) {
        var material = new THREE.MeshBasicMaterial({color: 0xCBDAD5,
                                                       ambient: 0x00000000,
                                                       shading: THREE.SmoothShading});
        chrome11 = new THREE.Mesh(geometry, material);
        scene.add(chrome11);
    });
    }


Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.