Scene Graph - Transform Gizmo #1272
Replies: 1 comment 5 replies
-
|
Awesome work @OlivierLDff ! In a sense your work shows that we can now do almost anything with CXX-Qt, as long as you're willing to write the odd C++ function every now and then, which was our goal with CXX-Qt. Also thank you for your feedback about what could be improved. Generics (QVariant/QList/QMap)You can implement a trait for any type you want to store in the QVariant. The issue we have with this in general is that C++ templates are very difficult to represent in Rust with generics. You can maybe get around this with some newtype wrappers, but it would be somewhat cumbersome. Alternative solution: destructuring the propertyIf I understand the code correctly, the In that case a solution could be to deconstruct the property into multiple Rust method calls:
Which could then be called from QML/JS: function updateTargets() {
clearTargets();
for (model of view.pickedModels) {
addTarget(model.position, model.rotation.toVector4d(), model.scale);
}
finalizeTargets();
}This would move the data deconstruction from C++ into QML, which is not an ideal API, but should allow you to get rid of the C++ code. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Code is available at: https://github.com/OlivierLDff/cxx-qt-experiments
CleanShot.2025-05-18.at.1.48.30.mp4
I got time to have more play-around with
cxx-qt, so I keep up on implementingQQuickItembased item. My goal here was to port be able to use transform_gizmo as a qml object.transform-gizmois a framework-agnostic Rust crate that provides a feature-rich and customizable 3D transformation gizmo for manipulating the position, rotation and scale of 3D entities.I will split my feedback in 3 parts:
updatePaintNode)Rendering via
updatePaintNodeThe crate have a simple
drawfunction that return aGizmoDrawData:We need to render that using QSG API. Like in my previous test (bezier curve) I went with interacting from C++ as they are no bindings for that. As I found before I don't know if doing 1:1 mapping brings anything to the table.
And this call the following cpp code:
Then this is just regular Qt with C++. I've found myself a bit in uncharted water because they are not much online example/documentation on how to create something else than bezier curve and Efficient custom shapes in Qt Quick. But I guess this is mainly my lack of knowledge of graphic programming.
Interaction with the Mouse
The
transform_gizmocrate expect aGizmoInteractionto describe the interaction:So I wanted to have interaction with the mouse click/move/hover information. For that I needed to inherit 6 functions and manipulate
QMouseEvent*&QHoverEvent*. I didn't know what I needed before hand so trying to solve making new bindings and figuring out what needed to be done was too much at once.I went with the same trick as before: writing the stuff in C++ that doesn't bring much value, and call the logic written in rust.
So my base class:
This make life so much easier since I just need to "inherit" from rust
updateInteractionandpickPreview(that check if we are hovering a clickable part of the gizmo).I'm not sure what is the best way to provide bindings for
QMouseEventandQHoverEvent, but I'm sure the new upcast feature will help.Api for Targets Manipulation
That part is very opinionated. The role of the gizmo is to update translation/rotation/scale of 1 or N objects. At first I thought about doing some
QQmlListPropertyor something usingQObjectfor each targe that need to be manipulated. But that sounded like a hassle so I went with something way simpler to avoid any binding:QVariant, or more precisely aQList<QMap<QString, QVariant>>.So user could just pass a list of js object, and get back a list of update object.
But somehow I struggle with lots of cryptic error message, I would really like your feedback on how to write that using only rust because I think this is possible with what is in
cxx-qt.Since I had trouble with
QVariantusage from rust I went the C++ route again:And the code I would love to be able to write in rust:
Also I wanted to use
CxxVectororrust::Vectorbut somehow this gave me linking error about a missing cxx symbol. Is qt cxx bridge linking to cxx library?What Have I Been Missing from
cxx-qtQVariantexamplesQQuaternionfor rotation bindings, I went withQVector4DQVariantwithQtGuitypes (QVector3D,QVector4D)I don't know if there is a right way to bind all the QSG & QEvent object, so manipulating them from C++ is okish.
I've also seen there is a
qt-lib-extracrate so I will see if I can contribute some work forQQuickItem.Beta Was this translation helpful? Give feedback.
All reactions