Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dmorphtarget.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
7
8#include <QtQuick3DRuntimeRender/private/qssgrendermorphtarget_p.h>
9#include <QtQml/QQmlFile>
10
12
13/*!
14 \qmltype MorphTarget
15 \inherits Object3D
16 \inqmlmodule QtQuick3D
17 \brief Defines the properties of a morph target.
18
19 Each \e MorphTarget is a morph target for a \l{Morphing Animation}{vertex animation}. The degree
20 of morphing is controlled by changing the \l {weight} property.
21
22 \qml
23 MorphTarget {
24 id: morphtarget0
25 attributes: MorphTarget.Position | MorphTarget.Normal
26 weight: 0.5
27 }
28 \endqml
29
30 The \l {Qt Quick 3D - Morphing Example}{morphing example} shows how to use a morph target.
31*/
32
33QQuick3DMorphTarget::QQuick3DMorphTarget(QQuick3DObject *parent)
34 : QQuick3DObject(*(new QQuick3DObjectPrivate(QQuick3DObjectPrivate::Type::MorphTarget)), parent) {}
35
36QQuick3DMorphTarget::~QQuick3DMorphTarget()
37{
38}
39
40/*!
41 \qmlproperty real MorphTarget::weight
42
43 Specifies the weight of the current morph target. The weight is the multiplication factor used
44 by the linear interpolation. A weight of 1 means that this target is fully applied. A weight of
45 0 means that it has no influence.
46*/
47
48float QQuick3DMorphTarget::weight() const
49{
50 return m_weight;
51}
52
53/*!
54 \qmlproperty enumeration MorphTarget::attributes
55
56 Specifies the set of attributes of the current morph target.
57 In order to animate vertex attributes in morphing, the mesh must
58 contain those target attributes and the morph target must have the
59 attributes enabled.
60
61 The attributes for a morph target are specified by OR-ing together the following values:
62 \value MorphTarget.Position animates the vertex positions
63 \value MorphTarget.Normal animates the normal vectors
64 \value MorphTarget.Tangent animates the tangent vectors
65 \value MorphTarget.Binormal animates the binormal vectors
66 \value MorphTarget.TexCoord0 animates the texture coordinate 0 vectors
67 \value MorphTarget.TexCoord1 animates the texture coordinate 1 vectors
68 \value MorphTarget.Color animates the vertex color vectors
69*/
70
71QQuick3DMorphTarget::MorphTargetAttributes QQuick3DMorphTarget::attributes() const
72{
73 return m_attributes;
74}
75
76void QQuick3DMorphTarget::markAllDirty()
77{
78 m_dirtyAttributes = 0xffffffff;
79 QQuick3DObject::markAllDirty();
80}
81
82void QQuick3DMorphTarget::setWeight(float weight)
83{
84 if (m_weight == weight)
85 return;
86
87 m_weight = weight;
88 emit weightChanged();
89 markDirty(WeightDirty);
90}
91
92void QQuick3DMorphTarget::setAttributes(MorphTargetAttributes attributes)
93{
94 if (m_attributes == attributes)
95 return;
96
97 m_attributes = attributes;
98 m_numAttribs = 0;
99 int flags = attributes;
100 while (flags) {
101 m_numAttribs += flags & 0x1;
102 flags >>= 1;
103 }
104 emit attributesChanged();
105 markDirty(MorphTargetAttributesDirty);
106}
107
108QSSGRenderGraphObject *QQuick3DMorphTarget::updateSpatialNode(QSSGRenderGraphObject *node)
109{
110 if (!node) {
111 markAllDirty();
112 node = new QSSGRenderMorphTarget();
113 }
114 QQuick3DObject::updateSpatialNode(node);
115 auto modelNode = static_cast<QSSGRenderMorphTarget *>(node);
116 if (m_dirtyAttributes & WeightDirty)
117 modelNode->weight = m_weight;
118 if (m_dirtyAttributes & MorphTargetAttributesDirty)
119 modelNode->attributes = QSSGRenderMorphTarget::InputAttributes(int(m_attributes));
120
121 m_dirtyAttributes = 0;
122
123 return modelNode;
124}
125
126void QQuick3DMorphTarget::markDirty(QQuick3DMorphTarget::QSSGMorphTargetDirtyType type)
127{
128 if (!(m_dirtyAttributes & quint32(type))) {
129 m_dirtyAttributes |= quint32(type);
130 update();
131 }
132}
133
134size_t QQuick3DMorphTarget::numAttribs()
135{
136 return m_numAttribs;
137}
138
139QT_END_NAMESPACE
Combined button and popup list for selecting options.