Search code examples
qtqmlqt3d

Import STL files by Qt3D module: how to do configuration of light and material


I have used somebody's code uploaded here on Bitbucket to open and view STL files with Qt3D. The code has an entity which corresponds to imported STL model:

        Entity
        {
            id: monkeyEntity
            components: [
                SceneLoader
                {
                    id: sceneLoader
                }
            ]
        }

The above sceneLoader is loading the imported STL model by a QML dialog:

FileDialog
{
    id: fileDialog
    onAccepted:
    {
        sceneLoader.source = fileDialog.fileUrl
    }
}

But when I import the STL files, the lighting is not working. No matter how I change the light or material the imported 3D STL model is all white without showing the 3D shape:

STL model is all white, not showing the 3D shape

However when I use Blender software to convert STL file to Wavefront OBJ file, then the imported OBJ file into the Qt3D app shows up properly:

Wavefront OBJ model is viewed properly


I tried many light and material features of Qt3D but I couldn't make the STL model be viewed properly. Can anyone provide an example of Qt3D light/material configuration which would work for STL files?


Solution

  • When I build/run the app with Qt 5.9.0, it works fine, i.e. it can import STL files with all the colors:

    enter image description here

    However with Qt 5.11, it doesn't work fine:

    enter image description here

    I think the problem is SceneLoader which works differently in Qt 5.9.0 and Qt 5.11.


    Please take a look at this report on Qt and this report on assimp