[Interest] [Qt3D] Node's parent-child relationship clarification, please?

Émeric MASCHINO emeric.maschino at gmail.com
Tue Sep 29 11:28:27 CEST 2015


Hi,

In classical scenegraph approach, the path to a node gives the
relationships between the nodes. For example, the following path root
-> transform -> mesh means that the mesh node will be applied the
transform given by the transform node. The scenegraph's root is the
parent of the transform node, that in turn is the parent of the mesh
node.

By contrast, there's no such parent-child relationship in ECS approach [1].

Although Qt3D 2.x is an ECS, Qt3D::QNode constructor can be passed a
parent. I initially thought the parent plays the same role as in
classical scenegraph approach. Then I saw Qt3D's simple C++ example
[2], where mesh transform and material are added "the ECS way", by
adding a transform component. Still, the material and torus entities
are passed the root entity as parent:

// Root entity
Qt3D::QEntity *rootEntity = new Qt3D::QEntity();

<snip>

// Material
Qt3D::QMaterial *material = new Qt3D::QPhongMaterial(rootEntity);

// Torus
Qt3D::QEntity *torusEntity = new Qt3D::QEntity(rootEntity);
Qt3D::QTorusMesh *torusMesh = new Qt3D::QTorusMesh;
torusMesh->setRadius(5);
torusMesh->setMinorRadius(1);
torusMesh->setRings(100);
torusMesh->setSlices(20);

Qt3D::QTransform *torusTransform = new Qt3D::QTransform;
Qt3D::QScaleTransform *torusScaleTransform = new Qt3D::QScaleTransform;
torusScaleTransform->setScale3D(QVector3D(1.5, 1, 0.5));

Qt3D::QRotateTransform *torusRotateTransform = new Qt3D::QRotateTransform;
torusRotateTransform->setAxis(QVector3D(1, 0, 0));
torusRotateTransform->setAngleDeg(45);

torusTransform->addTransform(torusScaleTransform);
torusTransform->addTransform(torusRotateTransform);

torusEntity->addComponent(torusMesh);
torusEntity->addComponent(torusTransform);
torusEntity->addComponent(material);

So, can anybody explain why passing the root entity to the material
and torus entities is required? What's the difference with _not_
passing it?

How to deal with "parent transform"? Is this the role of the parent
passed to Qt3D::QNode constructor? I mean, in the above example, if
the root entity was added a transform component, would this behave as
a parent transform also applied to the torus entity (and also the
material entity?), meaning that the complete transform applied to the
torus entity would be the one from the root entity and then the one
from the transform component added to the torus entity?

Or is Qt3D::QNode's parent only for automatic memory management, i.e.
releasing an entity will also release its children entities?

Thanks,

     Émeric


[1] http://www.gamedev.net/topic/654122-entity-component-system-and-parent-relations/
(for example, but there are many resources on this topic on the web)
[2] http://doc.qt.io/qt-5/qt3drenderer-simple-cpp-main-cpp.html



More information about the Interest mailing list