Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Best way to "draw" dynamically a 3D house shape using QML.



  • I want to draw different types of structures and allow the user to change there's dimensions from the 3D view.

    For example giving the following image, clicking in the width dimension will update the shape:

    alt text

    This is possible to make with QML?



  • I think you should define a unique entity for your house, containing sub entities of the differents surfaces and properties binded to your surfaces dimmensions. To manage those properties you could then use some methods that you could call from other entities when they are clicked (like the arrow of your picture).

    This should look approximately like that (to me) :

    Entity
                {
                    id: house
    
                    property real height     // Total height of your house
                    property real length     // Total length of your house
                    property real width      // Total width of your house
    
                    Entity
                    {
                        id: surface1
    
                        ObjectPicker
                        {
                            id: surface1Picker
                            hoverEnabled: true
                            onEntered:
                            {
                                // Your code here
                            }
                            onExited:
                            {
                                // Your code here
                            }
                            onClicked:
                            {
                                // Your code here
                            }
                        }
    
                        PlaneMesh
                        {
                            id: surface1Mesh
                            width: // Dimmensions according to properties
                            height: // Dimmensions according to properties
                            meshResolution: Qt.size(2, 2)
                        }
    
                        Texture2D
                        {
                            id: surface1Texture
                            TextureImage
                            {
                                 id: texture1Image
                                 source : ""
                                 mirrored: false
                            }
                        }
    
                        DiffuseMapMaterial
                        {
                            id: surface1Material
                            diffuse: surface1Texture
                            shininess: 0
                        }
    
                        Transform
                        {
                            id: surface1Transform
                            scale3D: Qt.vector3d(1, 1, 1)
                            rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 90)
                            translation: Qt.vector3d(x, y, z)  // x, y and z are set according to your properties
                        }
    
                        components: [ surface1Mesh, surface1Material, surface1Transform, surface1Picker ]
                    }
    
                    Entity
                    { ...}
            }
    


  • Thanks! I'll try it.


Log in to reply