Skip to content

Commit

Permalink
new maya camera controller module (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrondaud committed Sep 1, 2016
1 parent ad82764 commit 45c8b62
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 6 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ add_subdirectory(plugins/qml/controls/NodeEditor)
add_subdirectory(plugins/qml/debug/InstantCoding)
add_subdirectory(plugins/qml/debug/Logger)
add_subdirectory(plugins/qml/qt3d/AlembicEntity)
add_subdirectory(plugins/qml/qt3d/MayaCameraController)
add_subdirectory(plugins/qml/stylesheets/DarkStyle)

subdirlist(SUBDIRS ${PROJECT_SOURCE_DIR}/plugins/cpp)
Expand Down
8 changes: 8 additions & 0 deletions plugins/qml/qt3d/MayaCameraController/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 2.6.2)
project(mayaCameraControllerQmlPlugin)

# Install settings
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins/qml
FILES_MATCHING PATTERN "*.qml"
PATTERN "qmldir")
104 changes: 104 additions & 0 deletions plugins/qml/qt3d/MayaCameraController/MayaCameraController.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Input 2.0
import Qt3D.Extras 2.0
import Qt3D.Logic 2.0
import QtQml 2.2

Entity {

id: root
property Camera camera
property real translateSpeed: 100.0
property real tiltSpeed: -500.0
property real panSpeed: 500.0

KeyboardDevice { id: keyboardSourceDevice }
MouseDevice { id: mouseSourceDevice; sensitivity: 0.1 }

LogicalDevice {
id: cameraControlDevice
actions: [
Action {
id: actionLMB
inputs: [
ActionInput {
sourceDevice: mouseSourceDevice
buttons: [MouseEvent.LeftButton]
}
]
},
Action {
id: actionRMB
inputs: [
ActionInput {
sourceDevice: mouseSourceDevice
buttons: [MouseEvent.RightButton]
}
]
},
Action {
id: actionMMB
inputs: [
ActionInput {
sourceDevice: mouseSourceDevice
buttons: [MouseEvent.MiddleButton]
}
]
},
Action {
id: actionAlt
inputs: [
ActionInput {
sourceDevice: keyboardSourceDevice
buttons: [Qt.Key_Alt]
}
]
}
]
axes: [
Axis {
id: axisMX
inputs: [
AnalogAxisInput {
sourceDevice: mouseSourceDevice
axis: MouseDevice.X
}
]
},
Axis {
id: axisMY
inputs: [
AnalogAxisInput {
sourceDevice: mouseSourceDevice
axis: MouseDevice.Y
}
]
}
]
}

components: [
FrameAction {
onTriggered: {
if(!actionAlt.active)
return;
if(actionLMB.active) { // rotate
var rx = -axisMX.value;
var ry = axisMY.value;
root.camera.panAboutViewCenter(root.panSpeed * rx * dt)
root.camera.tiltAboutViewCenter(root.tiltSpeed * ry * dt)
}
if(actionMMB.active) { // translate
var tx = axisMX.value * root.translateSpeed;
var ty = axisMY.value * root.translateSpeed;
root.camera.translate(Qt.vector3d(-tx, -ty, 0).times(dt))
}
if(actionRMB.active) { // zoom
var tz = axisMX.value * root.translateSpeed;
root.camera.translate(Qt.vector3d(0, 0, tz).times(dt))
}
}
}
]
}
3 changes: 3 additions & 0 deletions plugins/qml/qt3d/MayaCameraController/qmldir
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module MayaCameraController

MayaCameraController 1.0 MayaCameraController.qml
7 changes: 4 additions & 3 deletions src/qml/View3D.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Qt3D.Input 2.0
import Qt3D.Extras 2.0
import Qt3D.Logic 2.0
import AlembicEntity 1.0
import MayaCameraController 1.0

Item {

Expand All @@ -24,11 +25,9 @@ Item {
Scene3D {
anchors.fill: parent
focus: true
cameraAspectRatioMode: Scene3D.AutomaticAspectRatio // vs.UserAspectRatio
cameraAspectRatioMode: Scene3D.AutomaticAspectRatio // vs. UserAspectRatio
aspects: ["logic", "input"]

Entity {
id: sceneRoot
Camera {
id: mainCamera
projectionType: CameraLens.PerspectiveProjection
Expand All @@ -40,6 +39,7 @@ Item {
viewCenter: Qt.vector3d(0.0, 0.0, 0.0)
aspectRatio: width/height
}
MayaCameraController { camera: mainCamera }
components: [
RenderSettings {
activeFrameGraph: Viewport {
Expand Down Expand Up @@ -71,6 +71,7 @@ Item {
}

Slider {
focusPolicy: Qt.NoFocus
from: 0.1
to: 2
stepSize: 0.01
Expand Down
11 changes: 8 additions & 3 deletions src/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ ApplicationWindow {
StackLayout {
currentIndex: bar.currentIndex
onCurrentIndexChanged: children[currentIndex].focus = true
View2D { anchors.fill: parent }
View3D { anchors.fill: parent }
FocusScope {
anchors.fill: parent
View2D { anchors.fill: parent }
}
FocusScope {
anchors.fill: parent
View3D { anchors.fill: parent }
}
}
}
Graph {
Expand All @@ -81,7 +87,6 @@ ApplicationWindow {
}
}


// footer
footer: LogBar {}
}

0 comments on commit 45c8b62

Please sign in to comment.