qquick3dnode.cpp 18.2 KB
Newer Older
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
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Quick 3D.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

Andy Nichols's avatar
Andy Nichols committed
30
#include "qquick3dnode_p.h"
Andy Nichols's avatar
Andy Nichols committed
31

Andy Nichols's avatar
Andy Nichols committed
32
33
#include <QtQuick3DRuntimeRender/private/qssgrendernode_p.h>
#include <QtQuick3DUtils/private/qssgutils_p.h>
34
#include <QtQuick3DUtils/private/qssgrendereulerangles_p.h>
35
36
#include <QtQuick3D/private/qquick3dobject_p_p.h>
#include <QtQuick3D/private/qquick3dscenemanager_p.h>
Andy Nichols's avatar
Andy Nichols committed
37

38
39
#include <QtMath>

40
41
QT_BEGIN_NAMESPACE

42
/*!
Andy Nichols's avatar
Andy Nichols committed
43
    \qmltype Node
44
45
    \inherits Object3D
    \instantiates QQuick3DNode
Andy Nichols's avatar
Andy Nichols committed
46
    \inqmlmodule QtQuick3D
47
    \brief The base component for an object that exists in a 3D Scene.
48
49


50
*/
51

Andy Nichols's avatar
Andy Nichols committed
52
QQuick3DNode::QQuick3DNode()
53
54
{
}
Andy Nichols's avatar
Andy Nichols committed
55

Andy Nichols's avatar
Andy Nichols committed
56
QQuick3DNode::~QQuick3DNode() {}
Andy Nichols's avatar
Andy Nichols committed
57

58
59
60
61
62
63
64
65
/*!
    \qmlproperty float QtQuick3D::Node::x

    This property contains the x value of the position translation in
    local coordinate space.

    \sa QtQuick3D::Node::position
*/
Andy Nichols's avatar
Andy Nichols committed
66
float QQuick3DNode::x() const
67
68
69
70
{
    return m_position.x();
}

71
72
73
74
75
76
77
78
/*!
    \qmlproperty float QtQuick3D::Node::y

    This property contains the y value of the position translation in
    local coordinate space.

    \sa QtQuick3D::Node::position
*/
Andy Nichols's avatar
Andy Nichols committed
79
float QQuick3DNode::y() const
80
81
82
83
{
    return m_position.y();
}

84
85
86
87
88
89
90
91
/*!
    \qmlproperty float QtQuick3D::Node::z

    This property contains the z value of the position translation in
    local coordinate space.

    \sa QtQuick3D::Node::position
*/
Andy Nichols's avatar
Andy Nichols committed
92
float QQuick3DNode::z() const
93
94
95
96
{
    return m_position.z();
}

97
98
99
100
101
102
/*!
    \qmlproperty vector3d QtQuick3D::Node::rotation

    This property contains the rotation values for the x, y, and z axis.
    These values are stored as euler angles.
*/
Andy Nichols's avatar
Andy Nichols committed
103
QVector3D QQuick3DNode::rotation() const
Andy Nichols's avatar
Andy Nichols committed
104
105
106
107
{
    return m_rotation;
}

108
109
110
111
112
113
114
/*!
    \qmlproperty vector3d QtQuick3D::Node::position

    This property contains the position translation in local coordinate space.

    \sa QtQuick3D::Node::x, QtQuick3D::Node::y, QtQuick3D::Node::z
*/
Andy Nichols's avatar
Andy Nichols committed
115
QVector3D QQuick3DNode::position() const
Andy Nichols's avatar
Andy Nichols committed
116
117
118
119
{
    return m_position;
}

120
121
122
123
124
125

/*!
    \qmlproperty vector3d QtQuick3D::Node::scale

    This property contains the scale values for the x, y, and z axis.
*/
Andy Nichols's avatar
Andy Nichols committed
126
QVector3D QQuick3DNode::scale() const
Andy Nichols's avatar
Andy Nichols committed
127
128
129
130
{
    return m_scale;
}

131
132
133
134
135
136
137
/*!
    \qmlproperty vector3d QtQuick3D::Node::pivot

    This property contains the pivot values for the x, y, and z axis.  These
    values are used as the pivot points when applying rotations to the node.

*/
Andy Nichols's avatar
Andy Nichols committed
138
QVector3D QQuick3DNode::pivot() const
Andy Nichols's avatar
Andy Nichols committed
139
140
141
142
{
    return m_pivot;
}

143
144
145
146
147
148
149
150
/*!
    \qmlproperty float QtQuick3D::Node::opacity

    This property contains the local opacity value of the Node.  Since Node
    objects are not necessarialy visible, this value might not have any affect,
    but this value is inherited by all children of the Node, which might be visible.

*/
Andy Nichols's avatar
Andy Nichols committed
151
float QQuick3DNode::localOpacity() const
Andy Nichols's avatar
Andy Nichols committed
152
153
154
155
{
    return m_opacity;
}

156
157
158
159
160
161
162
163
164
/*!
    \qmlproperty int QtQuick3D::Node::boneId

    This property contains the skeletonID used for skeletal animations

    \note This property currently has no effect, since skeletal animations are
    not implimented.

*/
Andy Nichols's avatar
Andy Nichols committed
165
qint32 QQuick3DNode::skeletonId() const
Andy Nichols's avatar
Andy Nichols committed
166
167
168
169
{
    return m_boneid;
}

170
171
172
173
174
175
176
/*!
    \qmlproperty enumeration QtQuick3D::Node::rotationOrder

    This property defines in what order the Node::rotation properties components
    are applied in.

*/
Andy Nichols's avatar
Andy Nichols committed
177
QQuick3DNode::RotationOrder QQuick3DNode::rotationOrder() const
Andy Nichols's avatar
Andy Nichols committed
178
179
180
181
{
    return m_rotationorder;
}

182
183
184
185
186
187
188
189
/*!
    \qmlproperty enumeration QtQuick3D::Node::orientation

    This property defines whether the Node is using a RightHanded or Lefthanded
    coordinate system.


*/
Andy Nichols's avatar
Andy Nichols committed
190
QQuick3DNode::Orientation QQuick3DNode::orientation() const
Andy Nichols's avatar
Andy Nichols committed
191
192
193
194
{
    return m_orientation;
}

195
196
197
198
199
200
/*!
    \qmlproperty bool QtQuick3D::Node::visible

    When this property is true, the Node (and its children) can be visible.

*/
Andy Nichols's avatar
Andy Nichols committed
201
bool QQuick3DNode::visible() const
Andy Nichols's avatar
Andy Nichols committed
202
203
204
205
{
    return m_visible;
}

Richard Gustavsen's avatar
Richard Gustavsen committed
206
207
208
209
210
211
212
QQuick3DNode *QQuick3DNode::parentNode() const
{
    // The parent of a QQuick3DNode should never be anything else than a (subclass
    // of) QQuick3DNode (but the children/leaf nodes can be something else).
    return static_cast<QQuick3DNode *>(parentItem());
}

213
214
215
216
217
218
219
/*!
    \qmlproperty vector3d QtQuick3D::Node::forward

    This property returns a normalized vector of its forward direction.


*/
Andy Nichols's avatar
Andy Nichols committed
220
QVector3D QQuick3DNode::forward() const
221
{
222
    QMatrix3x3 theDirMatrix = mat44::getUpper3x3(globalTransform());
223
224
225
226
    theDirMatrix = mat33::getInverse(theDirMatrix).transposed();

    const QVector3D frontVector(0, 0, 1);
    return mat33::transform(theDirMatrix, frontVector).normalized();
227
228
}

229
230
231
232
233
234
/*!
    \qmlproperty vector3d QtQuick3D::Node::up

    This property returns a normalized vector of its up direction.

*/
Andy Nichols's avatar
Andy Nichols committed
235
QVector3D QQuick3DNode::up() const
236
{
237
    QMatrix3x3 theDirMatrix = mat44::getUpper3x3(globalTransform());
238
239
240
241
    theDirMatrix = mat33::getInverse(theDirMatrix).transposed();

    const QVector3D upVector(0, 1, 0);
    return mat33::transform(theDirMatrix, upVector).normalized();
242
243
}

244
245
246
247
248
249
/*!
    \qmlproperty vector3d QtQuick3D::Node::right

    This property returns a normalized vector of its up direction.

*/
Andy Nichols's avatar
Andy Nichols committed
250
QVector3D QQuick3DNode::right() const
251
{
252
    QMatrix3x3 theDirMatrix = mat44::getUpper3x3(globalTransform());
253
254
255
256
    theDirMatrix = mat33::getInverse(theDirMatrix).transposed();

    const QVector3D rightVector(1, 0, 0);
    return mat33::transform(theDirMatrix, rightVector).normalized();
257
}
258
259
260
261
/*!
    \qmlproperty vector3d QtQuick3D::Node::globalPosition

    This property returns the position of the node in global coordinate space.
262
    \note the position will be reported in the same orientation as the node.
263
*/
Andy Nichols's avatar
Andy Nichols committed
264
QVector3D QQuick3DNode::globalPosition() const
265
{
266
    return mat44::getPosition(globalTransform());
267
268
}

269
270
271
272
273
274
275
/*!
    \qmlproperty vector3d QtQuick3D::Node::globalRotation

    This property returns the rotation of the node in global coordinate space.
*/
QVector3D QQuick3DNode::globalRotation() const
{
276
    return mat44::getRotation(globalTransform(), m_rotationorder);
277
278
}

279
280
281
282
283
284
285
/*!
    \qmlproperty vector3d QtQuick3D::Node::globalScale

    This property returns the scale of the node in global coordinate space.
*/
QVector3D QQuick3DNode::globalScale() const
{
286
    return mat44::getScale(globalTransform());
287
288
}

289
290
291
292
/*!
    \qmlproperty matrix4x4 QtQuick3D::Node::globalTransform

    This property returns the global transform matrix for this node.
293
294
295
296
    \note the return value will be \l LeftHanded or \l RightHanded
    depending on \l orientation().

    \sa globalTransformRightHanded()
297
*/
Andy Nichols's avatar
Andy Nichols committed
298
QMatrix4x4 QQuick3DNode::globalTransform() const
299
{
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
    return m_orientation == LeftHanded ? globalTransformLeftHanded() : globalTransformRightHanded();
}

/*!
    This function returns the global transform matrix for this node
    as a left-handed coordinate system, regardless of \l orientation().

    \sa globalTransform() globalTransformRightHanded()
*/
QMatrix4x4 QQuick3DNode::globalTransformLeftHanded() const
{
    QMatrix4x4 transform = globalTransformRightHanded();
    mat44::flip(transform);
    return transform;
}

/*!
    This function returns the global transform matrix for this node
    as a right-handed coordinate system, regardless of \l orientation().

    \sa globalTransform() globalTransformLeftHanded()
*/
QMatrix4x4 QQuick3DNode::globalTransformRightHanded() const
{
    // TODO: don't call this if not dirty
    const_cast<QQuick3DNode *>(this)->calculateGlobalVariables();
    return m_globalTransformRightHanded;
}

void QQuick3DNode::calculateGlobalVariables()
{
    QMatrix4x4 localTransformRightHanded = calculateLocalTransformRightHanded();
    QQuick3DNode *parent = parentNode();
    if (!parent) {
        m_globalTransformRightHanded = localTransformRightHanded;
        return;
    }

    parent->calculateGlobalVariables();
    m_globalTransformRightHanded = parent->m_globalTransformRightHanded * localTransformRightHanded;
}

QMatrix4x4 QQuick3DNode::calculateLocalTransformRightHanded()
{
    // Create a right-handed rotation transform from the radians.
    const float radX = qDegreesToRadians(m_rotation.x());
    const float radY = qDegreesToRadians(m_rotation.y());
    const float radZ = qDegreesToRadians(m_rotation.z());
    const QVector3D radians(radX, radY, radZ);
    const QMatrix4x4 rotationTransform = QSSGEulerAngleConverter::createRotationMatrix(radians, quint32(m_rotationorder));

    const QVector3D pivot = -m_pivot * m_scale;
    QMatrix4x4 localTransform;

    localTransform(0, 0) = m_scale[0];
    localTransform(1, 1) = m_scale[1];
    localTransform(2, 2) = m_scale[2];

    localTransform(0, 3) = pivot[0];
    localTransform(1, 3) = pivot[1];
    localTransform(2, 3) = pivot[2];

    localTransform = rotationTransform * localTransform;

    localTransform(0, 3) += m_position[0];
    localTransform(1, 3) += m_position[1];
    localTransform(2, 3) += m_position[2];

    if (Q_LIKELY(m_orientation == LeftHanded))
        mat44::flip(localTransform);

    return localTransform;
372
373
}

374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
void QQuick3DNode::calculateAndNotifyGlobalTransformChanges()
{
    const QMatrix4x4 oldGlobalTransform = m_globalTransformRightHanded;
    const QMatrix4x4 newGlobalTransform = globalTransformRightHanded();
    if (oldGlobalTransform == newGlobalTransform)
        return;

    const QVector3D oldGlobalPosition = mat44::getPosition(oldGlobalTransform);
    const QVector3D newGlobalPosition = mat44::getPosition(newGlobalTransform);
    const QVector3D oldGlobalRotation = mat44::getRotation(oldGlobalTransform, m_rotationorder);
    const QVector3D newGlobalRotation = mat44::getRotation(newGlobalTransform, m_rotationorder);
    const QVector3D oldGlobalScale = mat44::getScale(oldGlobalTransform);
    const QVector3D newGlobalScale = mat44::getScale(newGlobalTransform);

    emit globalTransformChanged();
    if (oldGlobalPosition != newGlobalPosition)
        emit globalPositionChanged();
    if (oldGlobalRotation != newGlobalRotation)
        emit globalRotationChanged();
    if (oldGlobalScale != newGlobalScale)
        emit globalScaleChanged();
}

bool QQuick3DNode::isGlobalTransformRelatedSignal(const QMetaMethod &signal)
{
    static const QMetaMethod globalTransformSignal = QMetaMethod::fromSignal(&QQuick3DNode::globalTransformChanged);
    static const QMetaMethod globalPositionSignal = QMetaMethod::fromSignal(&QQuick3DNode::globalPositionChanged);
    static const QMetaMethod globalRotationSignal = QMetaMethod::fromSignal(&QQuick3DNode::globalRotationChanged);
    static const QMetaMethod globalScaleSignal = QMetaMethod::fromSignal(&QQuick3DNode::globalScaleChanged);

    return (signal == globalTransformSignal
            || signal == globalPositionSignal
            || signal == globalRotationSignal
            || signal == globalScaleSignal);
}

void QQuick3DNode::updateGlobalTransformRegistration()
{
    // Whenever someone creates a connection to any of the global transform releated
    // properties, we inform the scene manager about it. What it means is that we need
    // to calulate the global transform and emit changes to it whenever it changes. But
    // knowing when it changes is costly, since it will change whenever the transform of
    // an ancestor change (and we don't want to listen for that all the way to the root).
    // So the scene manager will instead delay all global transform calculations to a be
    // done in a single pass before we update instead.
    if (!QQuick3DObjectPrivate::get(this)->componentComplete) {
        // We need to wait until completed so that we have a scene manager assigned
        // todo: We might need to listen for e.g parent changes, to catch if the scene manager changes.
        return;
    }
    auto sceneManager = QQuick3DObjectPrivate::get(this)->sceneManager;
    if (!sceneManager)
        return;

   if (m_globalTransformConnectionCount != 0)
       sceneManager->globalTransformNodes.append(this);
   else
       sceneManager->globalTransformNodes.removeOne(this);
}

void QQuick3DNode::connectNotify(const QMetaMethod &signal)
{
436
    if (isGlobalTransformRelatedSignal(signal)) {
437
        m_globalTransformConnectionCount++;
438
439
440
        if (m_globalTransformConnectionCount == 1)
            updateGlobalTransformRegistration();
    }
441
442
443
444
}

void QQuick3DNode::disconnectNotify(const QMetaMethod &signal)
{
445
    if (isGlobalTransformRelatedSignal(signal)) {
446
        m_globalTransformConnectionCount--;
447
448
449
        if (m_globalTransformConnectionCount == 0)
            updateGlobalTransformRegistration();
    }
450
451
452
453
454
455
456
457
458
}

void QQuick3DNode::componentComplete()
{
    QQuick3DObject::componentComplete();
    if (m_globalTransformConnectionCount != 0)
        updateGlobalTransformRegistration();
}

Andy Nichols's avatar
Andy Nichols committed
459
QQuick3DObject::Type QQuick3DNode::type() const
Andy Nichols's avatar
Andy Nichols committed
460
{
Andy Nichols's avatar
Andy Nichols committed
461
    return QQuick3DObject::Node;
Andy Nichols's avatar
Andy Nichols committed
462
463
}

Andy Nichols's avatar
Andy Nichols committed
464
void QQuick3DNode::setX(float x)
465
466
467
468
469
470
471
472
473
474
{
    if (qFuzzyCompare(m_position.x(), x))
        return;

    m_position.setX(x);
    emit positionChanged(m_position);
    emit xChanged(x);
    update();
}

Andy Nichols's avatar
Andy Nichols committed
475
void QQuick3DNode::setY(float y)
476
477
478
479
480
481
482
483
484
485
{
    if (qFuzzyCompare(m_position.y(), y))
        return;

    m_position.setY(y);
    emit positionChanged(m_position);
    emit yChanged(y);
    update();
}

Andy Nichols's avatar
Andy Nichols committed
486
void QQuick3DNode::setZ(float z)
487
488
489
490
491
492
493
494
495
496
{
    if (qFuzzyCompare(m_position.z(), z))
        return;

    m_position.setZ(z);
    emit positionChanged(m_position);
    emit zChanged(z);
    update();
}

Andy Nichols's avatar
Andy Nichols committed
497
void QQuick3DNode::setRotation(QVector3D rotation)
Andy Nichols's avatar
Andy Nichols committed
498
499
500
501
502
503
{
    if (m_rotation == rotation)
        return;

    m_rotation = rotation;
    emit rotationChanged(m_rotation);
504

Andy Nichols's avatar
Andy Nichols committed
505
506
507
    update();
}

Andy Nichols's avatar
Andy Nichols committed
508
void QQuick3DNode::setPosition(QVector3D position)
Andy Nichols's avatar
Andy Nichols committed
509
510
511
512
{
    if (m_position == position)
        return;

513
514
515
516
    const bool xUnchanged = qFuzzyCompare(position.x(), m_position.x());
    const bool yUnchanged = qFuzzyCompare(position.y(), m_position.y());
    const bool zUnchanged = qFuzzyCompare(position.z(), m_position.z());

Andy Nichols's avatar
Andy Nichols committed
517
518
    m_position = position;
    emit positionChanged(m_position);
519
520
521
522
523
524
525
526

    if (!xUnchanged)
        emit xChanged(m_position.x());
    if (!yUnchanged)
        emit yChanged(m_position.y());
    if (!zUnchanged)
        emit zChanged(m_position.z());

Andy Nichols's avatar
Andy Nichols committed
527
528
529
    update();
}

Andy Nichols's avatar
Andy Nichols committed
530
void QQuick3DNode::setScale(QVector3D scale)
Andy Nichols's avatar
Andy Nichols committed
531
532
533
534
535
536
537
538
539
{
    if (m_scale == scale)
        return;

    m_scale = scale;
    emit scaleChanged(m_scale);
    update();
}

Andy Nichols's avatar
Andy Nichols committed
540
void QQuick3DNode::setPivot(QVector3D pivot)
Andy Nichols's avatar
Andy Nichols committed
541
542
543
544
545
546
547
548
549
{
    if (m_pivot == pivot)
        return;

    m_pivot = pivot;
    emit pivotChanged(m_pivot);
    update();
}

Andy Nichols's avatar
Andy Nichols committed
550
void QQuick3DNode::setLocalOpacity(float opacity)
Andy Nichols's avatar
Andy Nichols committed
551
552
553
554
555
556
557
558
559
{
    if (qFuzzyCompare(m_opacity, opacity))
        return;

    m_opacity = opacity;
    emit localOpacityChanged(m_opacity);
    update();
}

Andy Nichols's avatar
Andy Nichols committed
560
void QQuick3DNode::setSkeletonId(qint32 boneid)
Andy Nichols's avatar
Andy Nichols committed
561
562
563
564
565
566
567
568
569
{
    if (m_boneid == boneid)
        return;

    m_boneid = boneid;
    emit skeletonIdChanged(m_boneid);
    update();
}

Andy Nichols's avatar
Andy Nichols committed
570
void QQuick3DNode::setRotationOrder(QQuick3DNode::RotationOrder rotationorder)
Andy Nichols's avatar
Andy Nichols committed
571
572
573
574
575
576
577
578
579
{
    if (m_rotationorder == rotationorder)
        return;

    m_rotationorder = rotationorder;
    emit rotationOrderChanged(m_rotationorder);
    update();
}

Andy Nichols's avatar
Andy Nichols committed
580
void QQuick3DNode::setOrientation(QQuick3DNode::Orientation orientation)
Andy Nichols's avatar
Andy Nichols committed
581
582
583
584
585
586
587
588
589
{
    if (m_orientation == orientation)
        return;

    m_orientation = orientation;
    emit orientationChanged(m_orientation);
    update();
}

Andy Nichols's avatar
Andy Nichols committed
590
void QQuick3DNode::setVisible(bool visible)
Andy Nichols's avatar
Andy Nichols committed
591
592
593
594
595
596
597
598
599
{
    if (m_visible == visible)
        return;

    m_visible = visible;
    emit visibleChanged(m_visible);
    update();
}

Andy Nichols's avatar
Andy Nichols committed
600
QSSGRenderGraphObject *QQuick3DNode::updateSpatialNode(QSSGRenderGraphObject *node)
Andy Nichols's avatar
Andy Nichols committed
601
{
Christian Strømme's avatar
WIP:    
Christian Strømme committed
602
    if (!node)
Andy Nichols's avatar
Andy Nichols committed
603
        node = new QSSGRenderNode();
Andy Nichols's avatar
Andy Nichols committed
604

Andy Nichols's avatar
Andy Nichols committed
605
    auto spacialNode = static_cast<QSSGRenderNode *>(node);
606
607
608
609
610
611
612
    bool transformIsDirty = false;
    if (spacialNode->position != m_position) {
        transformIsDirty = true;
        spacialNode->position = m_position;
    }
    if (spacialNode->rotation != m_rotation) {
        transformIsDirty = true;
613
614
615
        spacialNode->rotation = QVector3D(qDegreesToRadians(m_rotation.x()),
                                          qDegreesToRadians(m_rotation.y()),
                                          qDegreesToRadians(m_rotation.z()));
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
    }
    if (spacialNode->scale != m_scale) {
        transformIsDirty = true;
        spacialNode->scale = m_scale;
    }
    if (spacialNode->pivot != m_pivot) {
        transformIsDirty = true;
        spacialNode->pivot = m_pivot;
    }

    if (spacialNode->rotationOrder != quint32(m_rotationorder)) {
        transformIsDirty = true;
        spacialNode->rotationOrder = quint32(m_rotationorder);
    }

Andy Nichols's avatar
Andy Nichols committed
631
632
    spacialNode->localOpacity = m_opacity;
    spacialNode->skeletonId = m_boneid;
Andy Nichols's avatar
Andy Nichols committed
633

634
    if (m_orientation == LeftHanded)
Andy Nichols's avatar
Andy Nichols committed
635
        spacialNode->flags.setFlag(QSSGRenderNode::Flag::LeftHanded, true);
636
    else
Andy Nichols's avatar
Andy Nichols committed
637
        spacialNode->flags.setFlag(QSSGRenderNode::Flag::LeftHanded, false);
638

Andy Nichols's avatar
Andy Nichols committed
639
    spacialNode->flags.setFlag(QSSGRenderNode::Flag::Active, m_visible);
640
641

    if (transformIsDirty) {
Andy Nichols's avatar
Andy Nichols committed
642
        spacialNode->markDirty(QSSGRenderNode::TransformDirtyFlag::TransformIsDirty);
643
        spacialNode->calculateGlobalVariables();
644
        // Still needs to be marked dirty if it will show up correctly in the backend
645
646
        // Note: no longer sure if this is still needed after we now do our own
        // calculation of the global matrix from the front-end.
Andy Nichols's avatar
Andy Nichols committed
647
        spacialNode->flags.setFlag(QSSGRenderNode::Flag::Dirty, true);
648
    } else {
Andy Nichols's avatar
Andy Nichols committed
649
        spacialNode->markDirty(QSSGRenderNode::TransformDirtyFlag::TransformNotDirty);
650
    }
651

Andy Nichols's avatar
Andy Nichols committed
652
653
    return spacialNode;
}
654
655

QT_END_NAMESPACE