diff options
author | Sven Erdem <sven.erdem@kdab.com> | 2016-12-21 17:55:21 +0100 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2017-01-13 09:41:17 +0000 |
commit | 0f32b7dc62b214e369a902067c467ec7ae6481b5 (patch) | |
tree | 6c017d189819cdfcfebd8bb8399b252057cdad85 /examples | |
parent | f627926f48f29739a3f765cea46f5c82ccc93e04 (diff) |
3D Text: created 3d text geometry and mesh
- Allows to extrude a 3D mesh from a text string
- Added 3d-text example
Triangulation fixes provided by Remi Faitout
Task-number: QTBUG-19234
Change-Id: I767ffa11092d30945e3fc19f90f72a5965f5a776
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/qt3d/3d-text/3d-text.pro | 8 | ||||
-rw-r--r-- | examples/qt3d/3d-text/main.cpp | 124 | ||||
-rw-r--r-- | examples/qt3d/qt3d.pro | 3 |
3 files changed, 134 insertions, 1 deletions
diff --git a/examples/qt3d/3d-text/3d-text.pro b/examples/qt3d/3d-text/3d-text.pro new file mode 100644 index 000000000..7fa771df4 --- /dev/null +++ b/examples/qt3d/3d-text/3d-text.pro @@ -0,0 +1,8 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +QT += core gui 3dcore 3drender 3dinput 3dextras 3drender-private + +SOURCES += main.cpp + diff --git a/examples/qt3d/3d-text/main.cpp b/examples/qt3d/3d-text/main.cpp new file mode 100644 index 000000000..40ae8b80a --- /dev/null +++ b/examples/qt3d/3d-text/main.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** 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 <QCoreApplication> +#include <Qt3DCore/Qt3DCore> +#include <Qt3DExtras/Qt3DExtras> +#include <qtext3dmesh.h> +#include <qtext3dgeometry.h> + +int main(int argc, char *argv[]) +{ + QGuiApplication a(argc, argv); + Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow(); + view->setTitle(QStringLiteral("3D Text CPP")); + view->defaultFrameGraph()->setClearColor(QColor(210, 210, 220)); + + auto *root = new Qt3DCore::QEntity(); + + { // plane + auto *plane = new Qt3DCore::QEntity(root); + auto *planeMesh = new Qt3DExtras::QPlaneMesh(); + auto *planeTransform = new Qt3DCore::QTransform(); + auto *planeMaterial = new Qt3DExtras::QPhongMaterial(root); + planeMesh->setWidth(10); planeMesh->setHeight(10); + planeTransform->setTranslation(QVector3D(0, 0, 0)); + planeMaterial->setDiffuse(QColor(150, 150, 150)); + + plane->addComponent(planeMaterial); + plane->addComponent(planeMesh); + plane->addComponent(planeTransform); + } + + auto *textMaterial = new Qt3DExtras::QPhongMaterial(root); + { // text + int i = 0; + QStringList fonts = QFontDatabase().families(); + + for (QString family : fonts) + { + auto *text = new Qt3DCore::QEntity(root); + auto *textMesh = new Qt3DExtras::QText3DMesh(); + Qt3DExtras::QText3DGeometry *textGeometry = static_cast<Qt3DExtras::QText3DGeometry*>(textMesh->geometry()); + + auto *textTransform = new Qt3DCore::QTransform(); + QFont font(family, 32, -1, false); + textTransform->setTranslation(QVector3D(-2.45f, i * .5f, 0)); + textTransform->setScale(.2f); + textGeometry->setDepth(.45f); + textGeometry->setFont(font); + textGeometry->setEdgeSplitAngle(90.f * .15f); + textGeometry->setText(QString(family)); + textMaterial->setDiffuse(QColor(111, 150, 255)); + + text->addComponent(textMaterial); + text->addComponent(textMesh); + text->addComponent(textTransform); + + i++; + } + } + + { // camera + float aspect = static_cast<float>(view->screen()->size().width()) / view->screen()->size().height(); + Qt3DRender::QCamera *camera = view->camera(); + camera->lens()->setPerspectiveProjection(65.f, aspect, 0.1f, 100.f); + camera->setPosition(QVector3D(0, 5, 3)); + camera->setViewCenter(QVector3D(0, 5, 0)); + + auto *cameraController = new Qt3DExtras::QOrbitCameraController(root); + cameraController->setCamera(camera); + } + + view->setRootEntity(root); + view->show(); + + return a.exec(); +} diff --git a/examples/qt3d/qt3d.pro b/examples/qt3d/qt3d.pro index d6d7437d1..7d0545404 100644 --- a/examples/qt3d/qt3d.pro +++ b/examples/qt3d/qt3d.pro @@ -15,7 +15,8 @@ SUBDIRS += \ planets-qml \ instanced-arrays-qml \ lights \ - compute-particles + compute-particles \ + 3d-text qtHaveModule(multimedia): SUBDIRS += audio-visualizer-qml |