Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt3D - how to not draw the meshes?

Tags:

c++

qt

qml

qt3d

I want to not draw some objects on the scene. In normal OpenGL we have just to not call function related to drawing the mesh.

Unfortunately I didn't found this "functionality" in the QML. The Entity doesn't contain the "visibility" attribute etc. Of course we can try to send the uniform to the shader and just discard the rendering when needed - it will work but this approach doesn't look good.

Is possible do to that by using QML or full rendering functionality should be created in cpp file?

like image 796
user1020905 Avatar asked Dec 06 '17 14:12

user1020905


2 Answers

Yes it is possible.

The easiest solution is to remove the material from your entity. You would have something like this:

Entity {
    property bool visible: true // or ideally, dynamically read from a c++ property or whatever suits you

    Material {
        id: myMaterial
        // stuff
    } 

    GeometryRenderer {
        id: myRenderer
        // stuff
    }

    components: visible ? [myMaterial, myRenderer] : []
}

Another solution (maybe a bit more difficult) is to use filters in the Effect you use in your material. The Effect component will have one or several RenderPasses. Each of these render passes can have filter keys:

RenderPass {
    id: myPass

    filterKeys: [ FilterKey { name: "PassType"; value: "customFilterIdString" } ] // <-- This line here

    renderStates: [
        BlendEquationArguments {
            ...
        }, 
     ...
    ]
}

Each render pass can be filtered in your RenderTree Using the RenderPassFilter component. This allow you to skip whole set of object and order the way passes are done. This is a bit more advanced and I don't think you need it if you just want to hide specific objects, but don't hesitate to read the doc and look for examples using these components

like image 88
Basile Perrenoud Avatar answered Sep 20 '22 21:09

Basile Perrenoud


The easiest way is actually to set the enabled property of the entity to false.

For finer and more versatile control, you could look at using QLayer components.

like image 27
mkrus Avatar answered Sep 19 '22 21:09

mkrus