Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MeshingBoundingBox.qml « Viewer3D « qml « ui « meshroom - github.com/alicevision/meshroom.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cee83594e4c1478d4caa90862ea4d1f2a65e48a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import Qt3D.Core 2.0
import Qt3D.Render 2.9
import Qt3D.Input 2.0
import Qt3D.Extras 2.10
import QtQuick 2.9

/**
 * BoundingBox entity for Meshing node. Used to define the area to reconstruct.
 * Simple box controlled by a gizmo to give easy and visual representation.
 */
Entity {
    id: root
    property DefaultCameraController sceneCameraController
    property Layer frontLayerComponent
    property var window
    property var currentMeshingNode: null
    enabled: true

    EntityWithGizmo {
        id: boundingBoxEntity
        sceneCameraController: root.sceneCameraController
        frontLayerComponent: root.frontLayerComponent
        window: root.window

        // Update node meshing slider values when the gizmo has changed: translation, rotation, scale, type
        transformGizmo.onGizmoChanged: {

            var previous_euler = Qt.vector3d(rotation.x, rotation.y, rotation.z)
            var updated_rotation = Transformations3DHelper.transformRotationGL(previous_euler)

            switch(type) {
                case TransformGizmo.Type.TRANSLATION: {
                    _reconstruction.setAttribute(
                        root.currentMeshingNode.attribute("boundingBox.bboxTranslation"),
                        JSON.stringify([translation.x, -translation.y, -translation.z])
                    )
                    break
                }
                case TransformGizmo.Type.ROTATION: {
                    _reconstruction.setAttribute(
                        root.currentMeshingNode.attribute("boundingBox.bboxRotation"),
                        JSON.stringify([updated_rotation.x, updated_rotation.y, updated_rotation.z])
                    )
                    break
                }
                case TransformGizmo.Type.SCALE: {
                    _reconstruction.setAttribute(
                        root.currentMeshingNode.attribute("boundingBox.bboxScale"),
                        JSON.stringify([scale.x, scale.y, scale.z])
                    )
                    break
                }
                case TransformGizmo.Type.ALL: {
                    _reconstruction.setAttribute(
                        root.currentMeshingNode.attribute("boundingBox"),
                        JSON.stringify([
                            [translation.x, -translation.y, -translation.z],
                            [updated_rotation.x, updated_rotation.y, updated_rotation.z],
                            [scale.x, scale.y, scale.z]
                        ])
                    )
                    break
                }
            }
        }

        // Translation values from node (vector3d because this is the type of QTransform.translation)
        property var nodeTranslation : Qt.vector3d(
            root.currentMeshingNode ? root.currentMeshingNode.attribute("boundingBox.bboxTranslation.x").value : 0,
            root.currentMeshingNode ? -root.currentMeshingNode.attribute("boundingBox.bboxTranslation.y").value : 0,
            root.currentMeshingNode ? -root.currentMeshingNode.attribute("boundingBox.bboxTranslation.z").value : 0
        )

        // Rotation values from node (3 separated values because QTransform stores Euler angles like this)
        property var nodeRotationX: {
            var rx = root.currentMeshingNode ? root.currentMeshingNode.attribute("boundingBox.bboxRotation.x").value : 0
            var ry = root.currentMeshingNode ? root.currentMeshingNode.attribute("boundingBox.bboxRotation.y").value : 0
            var rz = root.currentMeshingNode ? root.currentMeshingNode.attribute("boundingBox.bboxRotation.z").value : 0

            var previous_euler = Qt.vector3d(rx, ry, rz)
            var updated_rotation = Transformations3DHelper.transformRotationGL(previous_euler)
            return updated_rotation.x
        }

        property var nodeRotationY: {
            var rx = root.currentMeshingNode ? root.currentMeshingNode.attribute("boundingBox.bboxRotation.x").value : 0
            var ry = root.currentMeshingNode ? root.currentMeshingNode.attribute("boundingBox.bboxRotation.y").value : 0
            var rz = root.currentMeshingNode ? root.currentMeshingNode.attribute("boundingBox.bboxRotation.z").value : 0

            var previous_euler = Qt.vector3d(rx, ry, rz)
            var updated_rotation = Transformations3DHelper.transformRotationGL(previous_euler)
            return updated_rotation.y
        }

        property var nodeRotationZ: {
            var rx = root.currentMeshingNode ? root.currentMeshingNode.attribute("boundingBox.bboxRotation.x").value : 0
            var ry = root.currentMeshingNode ? root.currentMeshingNode.attribute("boundingBox.bboxRotation.y").value : 0
            var rz = root.currentMeshingNode ? root.currentMeshingNode.attribute("boundingBox.bboxRotation.z").value : 0

            var previous_euler = Qt.vector3d(rx, ry, rz)
            var updated_rotation = Transformations3DHelper.transformRotationGL(previous_euler)
            return updated_rotation.z
        }

        // Scale values from node (vector3d because this is the type of QTransform.scale3D)
        property var nodeScale: Qt.vector3d(
            root.currentMeshingNode ? root.currentMeshingNode.attribute("boundingBox.bboxScale.x").value : 1,
            root.currentMeshingNode ? root.currentMeshingNode.attribute("boundingBox.bboxScale.y").value : 1,
            root.currentMeshingNode ? root.currentMeshingNode.attribute("boundingBox.bboxScale.z").value : 1
        )

        // Automatically evaluate the Transform: value is taken from the node OR from the actual modification if the gizmo is moved by mouse.
        // When the gizmo has changed (with mouse), the new values are set to the node, the priority is given back to the node and the Transform is re-evaluated once with those values.
        transformGizmo.gizmoDisplayTransform.translation: transformGizmo.focusGizmoPriority ? transformGizmo.gizmoDisplayTransform.translation : nodeTranslation
        transformGizmo.gizmoDisplayTransform.rotationX: transformGizmo.focusGizmoPriority ? transformGizmo.gizmoDisplayTransform.rotationX : nodeRotationX
        transformGizmo.gizmoDisplayTransform.rotationY: transformGizmo.focusGizmoPriority ? transformGizmo.gizmoDisplayTransform.rotationY : nodeRotationY
        transformGizmo.gizmoDisplayTransform.rotationZ: transformGizmo.focusGizmoPriority ? transformGizmo.gizmoDisplayTransform.rotationZ : nodeRotationZ
        transformGizmo.objectTransform.scale3D: transformGizmo.focusGizmoPriority ? transformGizmo.objectTransform.scale3D : nodeScale

        // The entity
        BoundingBox { transform: boundingBoxEntity.objectTransform }
    }
}