mirror of https://github.com/qt/qt3d.git
Add support for loading specific animations from glTF 2 files
Can now specify source urls to QAnimationClipLoader with query parameters for animationIndex or animationName. Add a new manual test to demonstrate/test this by loading the 2nd animation from the Rigged-Simple.gltf file. Will followup with the same support for Qt 3D native json animation files. Change-Id: Icb66073f29b8471fe06e2e2e9c43720567dc9ee5 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
This commit is contained in:
parent
8b9f4b0936
commit
80a51b60c2
|
|
@ -50,9 +50,13 @@
|
|||
#include <QtCore/qjsonarray.h>
|
||||
#include <QtCore/qjsondocument.h>
|
||||
#include <QtCore/qjsonobject.h>
|
||||
#include <QtCore/qurlquery.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#define ANIMATION_INDEX_KEY QLatin1String("animationIndex")
|
||||
#define ANIMATION_NAME_KEY QLatin1String("animationName")
|
||||
|
||||
namespace Qt3DAnimation {
|
||||
namespace Animation {
|
||||
|
||||
|
|
@ -210,15 +214,36 @@ void AnimationClip::loadAnimationFromUrl()
|
|||
return;
|
||||
}
|
||||
|
||||
// Extract the animationName or animationIndex from the url query parameters.
|
||||
// If both present, animationIndex wins.
|
||||
int animationIndex = -1;
|
||||
QString animationName;
|
||||
if (m_source.hasQuery()) {
|
||||
QUrlQuery query(m_source);
|
||||
if (query.hasQueryItem(ANIMATION_INDEX_KEY)) {
|
||||
bool ok = false;
|
||||
int i = query.queryItemValue(ANIMATION_INDEX_KEY).toInt(&ok);
|
||||
if (ok)
|
||||
animationIndex = i;
|
||||
}
|
||||
|
||||
if (animationIndex == -1 && query.hasQueryItem(ANIMATION_NAME_KEY)) {
|
||||
animationName = query.queryItemValue(ANIMATION_NAME_KEY);
|
||||
}
|
||||
|
||||
qCDebug(Jobs) << "animationIndex =" << animationIndex;
|
||||
qCDebug(Jobs) << "animationName =" << animationName;
|
||||
}
|
||||
|
||||
// TODO: Convert to plugins
|
||||
// Load glTF or "native"
|
||||
if (filePath.endsWith(QLatin1String("gltf"))) {
|
||||
qCDebug(Jobs) << "Loading glTF animation from" << filePath;
|
||||
GLTFImporter gltf;
|
||||
gltf.load(&file);
|
||||
// TODO: Allow loading of a named animation from a file containing many
|
||||
m_name = gltf.animations().first().name;
|
||||
m_channels = gltf.createAnimationData();
|
||||
auto nameAndChannels = gltf.createAnimationData(animationIndex, animationName);
|
||||
m_name = nameAndChannels.name;
|
||||
m_channels = nameAndChannels.channels;
|
||||
} else if (filePath.endsWith(QLatin1String("json"))) {
|
||||
// Native format
|
||||
QByteArray animationData = file.readAll();
|
||||
|
|
|
|||
|
|
@ -466,16 +466,15 @@ QHash<int, int> GLTFImporter::createNodeIndexToJointIndexMap(const Skin &skin) c
|
|||
return nodeIndexToJointIndexMap;
|
||||
}
|
||||
|
||||
QVector<Qt3DAnimation::Animation::Channel> GLTFImporter::createAnimationData(const QString &animationName) const
|
||||
GLTFImporter::AnimationNameAndChannels GLTFImporter::createAnimationData(int animationIndex, const QString &animationName) const
|
||||
{
|
||||
QVector<Qt3DAnimation::Animation::Channel> channels;
|
||||
AnimationNameAndChannels nameAndChannels;
|
||||
if (m_animations.isEmpty()) {
|
||||
qCWarning(Jobs) << "File does not contain any animation data";
|
||||
return channels;
|
||||
return nameAndChannels;
|
||||
}
|
||||
|
||||
int animationIndex = 0;
|
||||
if (!animationName.isEmpty()) {
|
||||
if (animationIndex == -1 && !animationName.isEmpty()) {
|
||||
for (int i = 0; i < m_animations.size(); ++i) {
|
||||
if (m_animations[i].name == animationName) {
|
||||
animationIndex = i;
|
||||
|
|
@ -483,7 +482,13 @@ QVector<Qt3DAnimation::Animation::Channel> GLTFImporter::createAnimationData(con
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (animationIndex >= m_animations.size()) {
|
||||
qCWarning(Jobs) << "Invalid animation index. Skipping.";
|
||||
return nameAndChannels;
|
||||
}
|
||||
const Animation &animation = m_animations[animationIndex];
|
||||
nameAndChannels.name = animation.name;
|
||||
|
||||
// Create node index to joint index lookup tables for each skin
|
||||
QVector<QHash<int, int>> nodeIndexToJointIndexMaps;
|
||||
|
|
@ -621,11 +626,11 @@ QVector<Qt3DAnimation::Animation::Channel> GLTFImporter::createAnimationData(con
|
|||
} // case 4
|
||||
}
|
||||
|
||||
channels.push_back(outputChannel);
|
||||
nameAndChannels.channels.push_back(outputChannel);
|
||||
++channelIndex;
|
||||
}
|
||||
|
||||
return channels;
|
||||
return nameAndChannels;
|
||||
}
|
||||
|
||||
GLTFImporter::RawData GLTFImporter::accessorData(int accessorIndex, int index) const
|
||||
|
|
|
|||
|
|
@ -182,7 +182,12 @@ public:
|
|||
bool load(QIODevice *ioDev);
|
||||
const QVector<Animation> animations() const { return m_animations; }
|
||||
|
||||
QVector<Qt3DAnimation::Animation::Channel> createAnimationData(const QString &animationName = QString()) const;
|
||||
struct AnimationNameAndChannels
|
||||
{
|
||||
QString name;
|
||||
QVector<Qt3DAnimation::Animation::Channel> channels;
|
||||
};
|
||||
AnimationNameAndChannels createAnimationData(int animationIndex, const QString &animationName = QString()) const;
|
||||
|
||||
private:
|
||||
static Qt3DRender::QAttribute::VertexBaseType accessorTypeFromJSON(int componentType);
|
||||
|
|
|
|||
|
|
@ -77,7 +77,13 @@ void QAnimationClipLoaderPrivate::setStatus(QAnimationClipLoader::Status status)
|
|||
/*!
|
||||
\property Qt3DAnimation::QAnimationClipLoader::source
|
||||
|
||||
Holds the source URL from which to load the animation clip.
|
||||
Holds the source URL from which to load the animation clip. Currently
|
||||
glTF2 and the native Qt 3D json animation file formats are supported.
|
||||
|
||||
In the case where a file contains multiple animations, it is possible
|
||||
to select which animation should be loaded by way of query parameters
|
||||
on the source url. The accepted query parameters are animationIndex and
|
||||
animationName. If both are specified, animationName is ignored.
|
||||
*/
|
||||
/*!
|
||||
\class Qt3DAnimation::QAnimationClipLoader
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ SUBDIRS += \
|
|||
animation-keyframe-programmatic \
|
||||
layerfilter-qml \
|
||||
skinned-mesh \
|
||||
rigged-simple \
|
||||
proximityfilter \
|
||||
rendercapture-qml-fbo \
|
||||
blitframebuffer-qml \
|
||||
|
|
|
|||
|
|
@ -0,0 +1,116 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB).
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the Qt3D module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, you may use this file under the terms of the BSD license
|
||||
** as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import Qt3D.Core 2.10
|
||||
import Qt3D.Render 2.10
|
||||
import Qt3D.Input 2.0
|
||||
import Qt3D.Extras 2.10
|
||||
|
||||
Entity {
|
||||
id: root
|
||||
|
||||
components: [
|
||||
RenderSettings {
|
||||
activeFrameGraph: ForwardRenderer {
|
||||
camera: mainCamera
|
||||
}
|
||||
},
|
||||
// Event Source will be set by the Qt3DQuickWindow
|
||||
InputSettings { }
|
||||
]
|
||||
|
||||
Camera {
|
||||
id: mainCamera
|
||||
position: Qt.vector3d(1, 0.15, 0)
|
||||
viewCenter: Qt.vector3d(0, 0.15, 0)
|
||||
fieldOfView: 60
|
||||
}
|
||||
|
||||
OrbitCameraController {
|
||||
camera: mainCamera
|
||||
linearSpeed: 10
|
||||
lookSpeed: 180
|
||||
}
|
||||
|
||||
Entity {
|
||||
components: [
|
||||
PointLight {
|
||||
enabled: parent.enabled
|
||||
color: "black"
|
||||
intensity: 0
|
||||
},
|
||||
EnvironmentLight {
|
||||
enabled: parent.enabled
|
||||
|
||||
irradiance: TextureLoader {
|
||||
source: "qrc:/assets/envmaps/cedar-bridge/cedar_bridge_irradiance.dds"
|
||||
wrapMode {
|
||||
x: WrapMode.ClampToEdge
|
||||
y: WrapMode.ClampToEdge
|
||||
}
|
||||
generateMipMaps: false
|
||||
}
|
||||
specular: TextureLoader {
|
||||
source: "qrc:/assets/envmaps/cedar-bridge/cedar_bridge_specular.dds"
|
||||
wrapMode {
|
||||
x: WrapMode.ClampToEdge
|
||||
y: WrapMode.ClampToEdge
|
||||
}
|
||||
generateMipMaps: false
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
SkyboxEntity {
|
||||
baseName: "qrc:/assets/envmaps/cedar-bridge/cedar_bridge_irradiance"
|
||||
extension: ".dds"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB).
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the Qt3D module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, you may use this file under the terms of the BSD license
|
||||
** as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import Qt3D.Core 2.10
|
||||
import Qt3D.Render 2.10
|
||||
import Qt3D.Input 2.0
|
||||
import Qt3D.Extras 2.10
|
||||
|
||||
Entity {
|
||||
id: root
|
||||
|
||||
property Effect effect: skinnedPbrEffect
|
||||
property url source: ""
|
||||
property alias createJointsEnabled: skeleton.createJointsEnabled
|
||||
property alias transform: transform
|
||||
property color baseColor: "red"
|
||||
property alias rootJoint: skeleton.rootJoint
|
||||
property alias skeleton: skeleton
|
||||
|
||||
components: [
|
||||
Transform {
|
||||
id: transform
|
||||
rotationX: -90
|
||||
},
|
||||
Mesh {
|
||||
source: root.source
|
||||
},
|
||||
Armature {
|
||||
skeleton: SkeletonLoader {
|
||||
id: skeleton
|
||||
source: root.source
|
||||
onStatusChanged: console.log("skeleton loader status: " + status)
|
||||
onJointCountChanged: console.log("skeleton has " + jointCount + " joints")
|
||||
}
|
||||
},
|
||||
Material {
|
||||
effect: root.effect
|
||||
|
||||
parameters: [
|
||||
Parameter { name: "baseColor"; value: root.baseColor }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB).
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the Qt3D module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, you may use this file under the terms of the BSD license
|
||||
** as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import Qt3D.Core 2.10
|
||||
import Qt3D.Render 2.10
|
||||
import Qt3D.Input 2.0
|
||||
import Qt3D.Extras 2.10
|
||||
|
||||
Effect {
|
||||
id: skinnedPbrEffect
|
||||
parameters: [
|
||||
Parameter { name: "baseColor"; value: "red" },
|
||||
Parameter { name: "metalness"; value: 0.1 },
|
||||
Parameter { name: "roughness"; value: 0.2 }
|
||||
]
|
||||
|
||||
techniques: [
|
||||
Technique {
|
||||
filterKeys: FilterKey { name: "renderingStyle"; value: "forward" }
|
||||
|
||||
graphicsApiFilter {
|
||||
api: GraphicsApiFilter.OpenGL
|
||||
majorVersion: 3
|
||||
minorVersion: 1
|
||||
profile: GraphicsApiFilter.CoreProfile
|
||||
}
|
||||
|
||||
renderPasses: RenderPass {
|
||||
shaderProgram: ShaderProgram {
|
||||
id: prog
|
||||
vertexShaderCode: loadSource("qrc:/skinnedPbr.vert")
|
||||
}
|
||||
|
||||
ShaderProgramBuilder {
|
||||
shaderProgram: prog
|
||||
fragmentShaderGraph: "qrc:/shaders/graphs/metalrough.frag.json"
|
||||
enabledLayers: ["baseColor", "metalness", "roughness", "ambientOcclusion", "normal"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the Qt3D module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, you may use this file under the terms of the BSD license
|
||||
** as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <Qt3DQuickExtras/qt3dquickwindow.h>
|
||||
#include <Qt3DAnimation/QAnimationAspect>
|
||||
#include <QGuiApplication>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QGuiApplication app(argc, argv);
|
||||
Qt3DExtras::Quick::Qt3DQuickWindow view;
|
||||
view.registerAspect(new Qt3DAnimation::QAnimationAspect());
|
||||
|
||||
view.setSource(QUrl("qrc:/main.qml"));
|
||||
view.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB).
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the Qt3D module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, you may use this file under the terms of the BSD license
|
||||
** as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import Qt3D.Core 2.10
|
||||
import Qt3D.Render 2.10
|
||||
import Qt3D.Input 2.0
|
||||
import Qt3D.Animation 2.10
|
||||
import Qt3D.Extras 2.10
|
||||
import QtQuick 2.9
|
||||
|
||||
DefaultSceneEntity {
|
||||
id: scene
|
||||
|
||||
SkinnedPbrEffect {
|
||||
id: skinnedPbrEffect
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: 2000
|
||||
running: true
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
animator.running = true
|
||||
}
|
||||
}
|
||||
|
||||
SkinnedEntity {
|
||||
id: riggedSimple
|
||||
effect: skinnedPbrEffect
|
||||
source: "qrc:/assets/gltf/2.0/RiggedSimple/RiggedSimple.gltf"
|
||||
baseColor: "blue"
|
||||
transform.scale: 0.05
|
||||
|
||||
components: [
|
||||
ClipAnimator {
|
||||
id: animator
|
||||
running: true
|
||||
loops: Animation.Infinite
|
||||
clip: AnimationClipLoader {
|
||||
source: "qrc:/assets/gltf/2.0/RiggedSimple/RiggedSimple.gltf?animationIndex=1"
|
||||
}
|
||||
channelMapper: ChannelMapper {
|
||||
mappings: [
|
||||
SkeletonMapping{ skeleton: riggedSimple.skeleton }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
!include( ../manual.pri ) {
|
||||
error( "Couldn't find the manual.pri file!" )
|
||||
}
|
||||
|
||||
QT += 3dcore 3drender 3dinput 3dquick qml quick 3dquickextras 3danimation
|
||||
|
||||
SOURCES += \
|
||||
main.cpp
|
||||
|
||||
OTHER_FILES += \
|
||||
main.qml \
|
||||
DefaultSceneEntity.qml \
|
||||
SkinnedEntity.qml \
|
||||
SkinnedPbrEffect.qml
|
||||
|
||||
RESOURCES += \
|
||||
rigged-simple.qrc \
|
||||
../../../examples/qt3d/exampleresources/cubemaps.qrc \
|
||||
../../../examples/qt3d/exampleresources/envmaps.qrc \
|
||||
../../../examples/qt3d/exampleresources/gltf.qrc
|
||||
|
||||
DISTFILES += \
|
||||
skinnedPbr.vert
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>main.qml</file>
|
||||
<file>DefaultSceneEntity.qml</file>
|
||||
<file>skinnedPbr.vert</file>
|
||||
<file>SkinnedEntity.qml</file>
|
||||
<file>SkinnedPbrEffect.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the Qt3D module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, you may use this file under the terms of the BSD license
|
||||
** as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#version 150
|
||||
|
||||
in vec3 vertexPosition;
|
||||
in vec3 vertexNormal;
|
||||
in vec4 vertexTangent;
|
||||
in vec2 vertexTexCoord;
|
||||
in ivec4 vertexJointIndices;
|
||||
in vec4 vertexJointWeights;
|
||||
|
||||
out vec3 worldPosition;
|
||||
out vec3 worldNormal;
|
||||
out vec4 worldTangent;
|
||||
out vec2 texCoord;
|
||||
|
||||
uniform mat4 modelMatrix;
|
||||
uniform mat3 modelNormalMatrix;
|
||||
uniform mat4 mvp;
|
||||
|
||||
const int maxJoints = 100;
|
||||
uniform mat4 skinningPalette[maxJoints];
|
||||
|
||||
void main()
|
||||
{
|
||||
// Pass the texture coordinates through
|
||||
texCoord = vertexTexCoord;
|
||||
|
||||
// Perform the skinning
|
||||
mat4 skinningMatrix = skinningPalette[vertexJointIndices[0]] * vertexJointWeights[0];
|
||||
skinningMatrix += skinningPalette[vertexJointIndices[1]] * vertexJointWeights[1];
|
||||
skinningMatrix += skinningPalette[vertexJointIndices[2]] * vertexJointWeights[2];
|
||||
skinningMatrix += skinningPalette[vertexJointIndices[3]] * vertexJointWeights[3];
|
||||
|
||||
vec4 skinnedPosition = skinningMatrix * vec4(vertexPosition, 1.0);
|
||||
vec3 skinnedNormal = vec3(skinningMatrix * vec4(vertexNormal, 0.0));
|
||||
vec3 skinnedTangent = vec3(skinningMatrix * vec4(vertexTangent.xyz, 0.0));
|
||||
|
||||
// Transform position, normal, and tangent to world space
|
||||
worldPosition = vec3(modelMatrix * skinnedPosition);
|
||||
worldNormal = normalize(modelNormalMatrix * skinnedNormal);
|
||||
worldTangent.xyz = normalize(vec3(modelMatrix * vec4(skinnedTangent, 0.0)));
|
||||
worldTangent.w = vertexTangent.w;
|
||||
|
||||
gl_Position = mvp * skinnedPosition;
|
||||
}
|
||||
Loading…
Reference in New Issue