From e09b474e2e9fb9ae87536bdce5c8df3c5f8006ee Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 17 Oct 2023 22:02:25 +0800 Subject: import(teapot): Startup! --- works/teapot/.dockerignore | 1 + works/teapot/.github/workflows/ci.yaml | 30 ++++ works/teapot/.gitignore | 1 + works/teapot/CMakeLists.txt | 35 +++++ works/teapot/README.md | 1 + works/teapot/debian/control | 8 + works/teapot/main.cpp | 20 +++ works/teapot/main.qml | 270 +++++++++++++++++++++++++++++++++ works/teapot/qml.qrc | 6 + works/teapot/script/build-deb.bash | 12 ++ works/teapot/script/install-deps.bash | 3 + works/teapot/teapot.mesh | Bin 0 -> 42656 bytes works/teapot/view3d.pro | 14 ++ 13 files changed, 401 insertions(+) create mode 100644 works/teapot/.dockerignore create mode 100644 works/teapot/.github/workflows/ci.yaml create mode 100644 works/teapot/.gitignore create mode 100644 works/teapot/CMakeLists.txt create mode 100644 works/teapot/README.md create mode 100644 works/teapot/debian/control create mode 100644 works/teapot/main.cpp create mode 100644 works/teapot/main.qml create mode 100644 works/teapot/qml.qrc create mode 100755 works/teapot/script/build-deb.bash create mode 100644 works/teapot/script/install-deps.bash create mode 100644 works/teapot/teapot.mesh create mode 100644 works/teapot/view3d.pro (limited to 'works') diff --git a/works/teapot/.dockerignore b/works/teapot/.dockerignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/works/teapot/.dockerignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/works/teapot/.github/workflows/ci.yaml b/works/teapot/.github/workflows/ci.yaml new file mode 100644 index 0000000..426fdb9 --- /dev/null +++ b/works/teapot/.github/workflows/ci.yaml @@ -0,0 +1,30 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + defaults: + run: + shell: bash + + steps: + - uses: actions/checkout@v3 + + - name: Install Build Dependencies + run: ./script/install-deps.bash + + - name: Build Deb Package + run: ./script/build-deb.bash + + - name: Upload Artifact + uses: actions/upload-artifact@v3 + with: + name: deb-package + path: build/package.deb diff --git a/works/teapot/.gitignore b/works/teapot/.gitignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/works/teapot/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/works/teapot/CMakeLists.txt b/works/teapot/CMakeLists.txt new file mode 100644 index 0000000..0bbff29 --- /dev/null +++ b/works/teapot/CMakeLists.txt @@ -0,0 +1,35 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(crupest-teapot LANGUAGES CXX) + +set(CMAKE_AUTOMOC ON) + +find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Quick3D) + +qt_add_executable(crupest-teapot + main.cpp +) + +set_target_properties(crupest-teapot PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE +) + +target_link_libraries(crupest-teapot PUBLIC + Qt::Core + Qt::Gui + Qt::Quick + Qt::Quick3D +) + +qt_add_qml_module(crupest-teapot + URI Example + VERSION 1.0 + QML_FILES main.qml + RESOURCES teapot.mesh + NO_RESOURCE_TARGET_PATH +) + +install(TARGETS crupest-teapot) diff --git a/works/teapot/README.md b/works/teapot/README.md new file mode 100644 index 0000000..c684667 --- /dev/null +++ b/works/teapot/README.md @@ -0,0 +1 @@ +From https://github.com/qt/qtquick3d/tree/dev/examples/quick3d/view3d \ No newline at end of file diff --git a/works/teapot/debian/control b/works/teapot/debian/control new file mode 100644 index 0000000..20aad59 --- /dev/null +++ b/works/teapot/debian/control @@ -0,0 +1,8 @@ +Package: crupest-teapot +Version: 1.0-1 +Section: utils +Priority: optional +Architecture: all +Maintainer: crupest +Description: This is a test application for packaging +Depends: libqt63dquick6,qml6-module-qtqml,qml6-module-qtqml-workerscript,qml6-module-qtquick,qml6-module-qtquick-templates,qml6-module-qtquick-controls,qml6-module-quick3d diff --git a/works/teapot/main.cpp b/works/teapot/main.cpp new file mode 100644 index 0000000..804f8ff --- /dev/null +++ b/works/teapot/main.cpp @@ -0,0 +1,20 @@ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + QSurfaceFormat::setDefaultFormat(QQuick3D::idealSurfaceFormat()); + qputenv("QT_QUICK_CONTROLS_STYLE", "Basic"); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + if (engine.rootObjects().isEmpty()) + return -1; + + return app.exec(); +} diff --git a/works/teapot/main.qml b/works/teapot/main.qml new file mode 100644 index 0000000..8f61137 --- /dev/null +++ b/works/teapot/main.qml @@ -0,0 +1,270 @@ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick +import QtQuick3D +import QtQuick.Controls + +Window { + id: window + width: 1280 + height: 720 + visible: true + title: "View3Ds with Different Cameras" + color: "#848895" + + // The root scene + //! [rootnode] + Node { + id: standAloneScene + //! [rootnode] + + DirectionalLight { + ambientColor: Qt.rgba(0.5, 0.5, 0.5, 1.0) + brightness: 1.0 + eulerRotation.x: -25 + } + + Model { + source: "#Cube" + y: -104 + scale: Qt.vector3d(3, 3, 0.1) + eulerRotation.x: -90 + materials: [ + DefaultMaterial { + diffuseColor: Qt.rgba(0.8, 0.8, 0.8, 1.0) + } + ] + } + + Model { + source: "teapot.mesh" + y: -100 + scale: Qt.vector3d(50, 50, 50) + materials: [ + PrincipledMaterial { + baseColor: "#41cd52" + metalness: 0.0 + roughness: 0.1 + opacity: 1.0 + } + ] + + PropertyAnimation on eulerRotation.y { + loops: Animation.Infinite + duration: 5000 + to: 0 + from: -360 + } + } + + //! [cameras start] + // The predefined cameras. They have to be part of the scene, i.e. inside the root node. + // Animated perspective camera + Node { + PerspectiveCamera { + id: cameraPerspectiveOne + z: 600 + } + + PropertyAnimation on eulerRotation.x { + loops: Animation.Infinite + duration: 5000 + to: -360 + from: 0 + } + } + + // Stationary perspective camera + PerspectiveCamera { + id: cameraPerspectiveTwo + z: 600 + } + //! [cameras start] + + // Second animated perspective camera + Node { + PerspectiveCamera { + id: cameraPerspectiveThree + x: 500 + eulerRotation.y: 90 + } + PropertyAnimation on eulerRotation.y { + loops: Animation.Infinite + duration: 5000 + to: 0 + from: -360 + } + } + + // Stationary orthographic camera viewing from the top + OrthographicCamera { + id: cameraOrthographicTop + y: 600 + eulerRotation.x: -90 + } + + // Stationary orthographic camera viewing from the front + OrthographicCamera { + id: cameraOrthographicFront + z: 600 + } + + //! [cameras end] + // Stationary orthographic camera viewing from left + OrthographicCamera { + id: cameraOrthographicLeft + x: -600 + eulerRotation.y: -90 + } + } + //! [cameras end] + + //! [views] + // The views + Rectangle { + id: topLeft + anchors.top: parent.top + anchors.left: parent.left + width: parent.width * 0.5 + height: parent.height * 0.5 + color: "#848895" + border.color: "black" + + View3D { + id: topLeftView + anchors.fill: parent + importScene: standAloneScene + camera: cameraOrthographicFront + } + + Label { + text: "Front" + anchors.top: parent.top + anchors.left: parent.left + anchors.margins: 10 + color: "#222840" + font.pointSize: 14 + } + } + //! [views] + + Rectangle { + id: topRight + anchors.top: parent.top + anchors.right: parent.right + width: parent.width * 0.5 + height: parent.height * 0.5 + color: "transparent" + border.color: "black" + + Label { + text: "Perspective" + anchors.top: parent.top + anchors.right: parent.right + anchors.margins: 10 + color: "#222840" + font.pointSize: 14 + } + + View3D { + id: topRightView + anchors.top: parent.top + anchors.right: parent.right + anchors.left: parent.left + anchors.bottom: parent.bottom; + camera: cameraPerspectiveOne + importScene: standAloneScene + renderMode: View3D.Underlay + + environment: SceneEnvironment { + clearColor: window.color + backgroundMode: SceneEnvironment.Color + } + } + + Row { + id: controlsContainer + anchors.bottom: parent.bottom + anchors.horizontalCenter: parent.horizontalCenter + spacing: 10 + padding: 10 + + //! [buttons] + RoundButton { + text: "Camera 1" + highlighted: topRightView.camera == cameraPerspectiveOne + onClicked: { + topRightView.camera = cameraPerspectiveOne + } + } + //! [buttons] + RoundButton { + text: "Camera 2" + highlighted: topRightView.camera == cameraPerspectiveTwo + onClicked: { + topRightView.camera = cameraPerspectiveTwo + } + } + RoundButton { + text: "Camera 3" + highlighted: topRightView.camera == cameraPerspectiveThree + onClicked: { + topRightView.camera = cameraPerspectiveThree + } + } + } + } + + Rectangle { + id: bottomLeft + anchors.bottom: parent.bottom + anchors.left: parent.left + width: parent.width * 0.5 + height: parent.height * 0.5 + color: "#848895" + border.color: "black" + + View3D { + id: bottomLeftView + anchors.fill: parent + importScene: standAloneScene + camera: cameraOrthographicTop + } + + Label { + text: "Top" + anchors.top: parent.top + anchors.left: parent.left + anchors.margins: 10 + color: "#222840" + font.pointSize: 14 + } + } + + Rectangle { + id: bottomRight + anchors.bottom: parent.bottom + anchors.right: parent.right + width: parent.width * 0.5 + height: parent.height * 0.5 + color: "#848895" + border.color: "black" + + View3D { + id: bottomRightView + anchors.fill: parent + importScene: standAloneScene + camera: cameraOrthographicLeft + } + + Label { + text: "Left" + anchors.top: parent.top + anchors.right: parent.right + anchors.margins: 10 + color: "#222840" + font.pointSize: 14 + } + } +} diff --git a/works/teapot/qml.qrc b/works/teapot/qml.qrc new file mode 100644 index 0000000..b1f4acf --- /dev/null +++ b/works/teapot/qml.qrc @@ -0,0 +1,6 @@ + + + main.qml + teapot.mesh + + diff --git a/works/teapot/script/build-deb.bash b/works/teapot/script/build-deb.bash new file mode 100755 index 0000000..954d026 --- /dev/null +++ b/works/teapot/script/build-deb.bash @@ -0,0 +1,12 @@ +set -e + +mkdir -p build +pushd build +cmake .. "-DCMAKE_BUILD_TYPE=RelWithDebInfo" +make +mkdir -p package +cmake --install . --prefix ./package/ +mkdir -p package/DEBIAN +cp ../debian/control ./package/DEBIAN/control +dpkg-deb --root-owner-group --build package +popd diff --git a/works/teapot/script/install-deps.bash b/works/teapot/script/install-deps.bash new file mode 100644 index 0000000..813b884 --- /dev/null +++ b/works/teapot/script/install-deps.bash @@ -0,0 +1,3 @@ +set -e +sudo apt-get update +sudo apt-get install -y build-essential cmake g++ libgl1-mesa-dev qt6-base-dev qt6-declarative-dev qt6-quick3d-dev qt6-quick3d-dev-tools libqt6shadertools6-dev diff --git a/works/teapot/teapot.mesh b/works/teapot/teapot.mesh new file mode 100644 index 0000000..75ff317 Binary files /dev/null and b/works/teapot/teapot.mesh differ diff --git a/works/teapot/view3d.pro b/works/teapot/view3d.pro new file mode 100644 index 0000000..61455a1 --- /dev/null +++ b/works/teapot/view3d.pro @@ -0,0 +1,14 @@ +QT += quick quick3d + +target.path = $$[QT_INSTALL_EXAMPLES]/quick3d/view3d + +INSTALLS += target + +SOURCES += \ + main.cpp + +RESOURCES += \ + qml.qrc + +OTHER_FILES += \ + doc/src/*.* -- cgit v1.2.3 From 8aa652f77ad921c64f9e6a7bfc4a51f3e6f2727d Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 17 Oct 2023 22:07:10 +0800 Subject: import(teapot): Use bash to run scripts in CI. Although it is easy for me to set +x for scripts on macos. But it might not be that easy for Windows users. --- works/teapot/.github/workflows/ci.yaml | 7 ++----- works/teapot/script/install-deps.bash | 0 2 files changed, 2 insertions(+), 5 deletions(-) mode change 100644 => 100755 works/teapot/script/install-deps.bash (limited to 'works') diff --git a/works/teapot/.github/workflows/ci.yaml b/works/teapot/.github/workflows/ci.yaml index 426fdb9..9420964 100644 --- a/works/teapot/.github/workflows/ci.yaml +++ b/works/teapot/.github/workflows/ci.yaml @@ -10,18 +10,15 @@ jobs: build: name: Build runs-on: ubuntu-latest - defaults: - run: - shell: bash steps: - uses: actions/checkout@v3 - name: Install Build Dependencies - run: ./script/install-deps.bash + run: bash ./script/install-deps.bash - name: Build Deb Package - run: ./script/build-deb.bash + run: bash ./script/build-deb.bash - name: Upload Artifact uses: actions/upload-artifact@v3 diff --git a/works/teapot/script/install-deps.bash b/works/teapot/script/install-deps.bash old mode 100644 new mode 100755 -- cgit v1.2.3 From cb0e3a0fb536284bdf366b0bdca2f8f0bfdcf6d1 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 17 Oct 2023 22:27:14 +0800 Subject: import(teapot): Fix deps of deb: add qt qpa. And update README. I really can't understand why qt dependencies on Ubuntu is such a mess. --- works/teapot/README.md | 11 ++++++++++- works/teapot/debian/control | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'works') diff --git a/works/teapot/README.md b/works/teapot/README.md index c684667..caf2eaf 100644 --- a/works/teapot/README.md +++ b/works/teapot/README.md @@ -1 +1,10 @@ -From https://github.com/qt/qtquick3d/tree/dev/examples/quick3d/view3d \ No newline at end of file +From https://github.com/qt/qtquick3d/tree/dev/examples/quick3d/view3d + +This package only works on Ubuntu 22.04 because it relies on the system qt6 libs. At least I only test this platform. Other platforms might also work if the lib linkage is right. However, another way is to bundle all dependencies into the deb, which looks like most apps would do. But I'm new to deb package system and I'm in a hurry with no time to do more research. + +In a word, + +1. Make sure you are on Ubuntu 22.04. +2. Download `package.deb` from ci. +3. Run `sudo apt-get install package.deb` (NOT `dpkg`), and apt will take care of dependencies for you. +4. Run `crupest-teapot` and enjoy yourself! diff --git a/works/teapot/debian/control b/works/teapot/debian/control index 20aad59..74aab7c 100644 --- a/works/teapot/debian/control +++ b/works/teapot/debian/control @@ -5,4 +5,4 @@ Priority: optional Architecture: all Maintainer: crupest Description: This is a test application for packaging -Depends: libqt63dquick6,qml6-module-qtqml,qml6-module-qtqml-workerscript,qml6-module-qtquick,qml6-module-qtquick-templates,qml6-module-qtquick-controls,qml6-module-quick3d +Depends: qt6-qpa-plugins,libqt63dquick6,qml6-module-qtqml,qml6-module-qtqml-workerscript,qml6-module-qtquick,qml6-module-qtquick-templates,qml6-module-qtquick-controls,qml6-module-quick3d -- cgit v1.2.3