2020-09-10 16:02:31 +03:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2020 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2021-06-28 14:04:43 +03:00
|
|
|
import QtQuick 6.0
|
|
|
|
|
import QtQuick3D 6.0
|
2020-09-10 16:02:31 +03:00
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: root
|
|
|
|
|
width: 150
|
|
|
|
|
height: 150
|
|
|
|
|
visible: true
|
|
|
|
|
|
|
|
|
|
property View3D view: null
|
|
|
|
|
property alias contentItem: contentItem
|
|
|
|
|
|
2020-09-18 12:56:24 +03:00
|
|
|
property var previewObject
|
|
|
|
|
|
2020-09-10 16:02:31 +03:00
|
|
|
property var materialViewComponent
|
2020-09-18 12:56:24 +03:00
|
|
|
property var modelViewComponent
|
2020-09-22 11:30:05 +03:00
|
|
|
property var nodeViewComponent
|
2020-09-18 12:56:24 +03:00
|
|
|
|
2022-05-27 14:14:22 +03:00
|
|
|
property bool closeUp: false
|
|
|
|
|
|
2020-09-10 16:02:31 +03:00
|
|
|
function destroyView()
|
|
|
|
|
{
|
2020-09-18 12:56:24 +03:00
|
|
|
previewObject = null;
|
2020-11-02 10:57:25 +02:00
|
|
|
if (view)
|
2020-09-10 16:02:31 +03:00
|
|
|
view.destroy();
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-05 17:14:05 +03:00
|
|
|
function createViewForObject(obj, env, envValue, model)
|
2020-09-10 16:02:31 +03:00
|
|
|
{
|
2022-08-05 17:14:05 +03:00
|
|
|
backgroundView3d.visible = true;
|
2020-09-10 16:02:31 +03:00
|
|
|
if (obj instanceof Material)
|
2022-08-05 17:14:05 +03:00
|
|
|
createViewForMaterial(obj, env, envValue, model);
|
2020-09-18 12:56:24 +03:00
|
|
|
else if (obj instanceof Model)
|
|
|
|
|
createViewForModel(obj);
|
2020-09-22 11:30:05 +03:00
|
|
|
else if (obj instanceof Node)
|
|
|
|
|
createViewForNode(obj);
|
2020-09-10 16:02:31 +03:00
|
|
|
}
|
|
|
|
|
|
2022-08-05 17:14:05 +03:00
|
|
|
function createViewForMaterial(material, env, envValue, model)
|
2020-09-10 16:02:31 +03:00
|
|
|
{
|
|
|
|
|
if (!materialViewComponent)
|
|
|
|
|
materialViewComponent = Qt.createComponent("MaterialNodeView.qml");
|
|
|
|
|
|
|
|
|
|
// Always recreate the view to ensure material is up to date
|
2022-08-05 17:14:05 +03:00
|
|
|
if (materialViewComponent.status === Component.Ready) {
|
|
|
|
|
view = materialViewComponent.createObject(viewRect, {"previewMaterial": material,
|
|
|
|
|
"envMode": env,
|
|
|
|
|
"envValue": envValue,
|
|
|
|
|
"modelSrc": model});
|
|
|
|
|
}
|
|
|
|
|
// Floor must be in same view as material so material can reflect it, so hide it in this one
|
|
|
|
|
backgroundView3d.visible = false;
|
2022-02-02 17:56:16 +02:00
|
|
|
previewObject = material;
|
2020-09-10 16:02:31 +03:00
|
|
|
}
|
|
|
|
|
|
2020-09-18 12:56:24 +03:00
|
|
|
function createViewForModel(model)
|
|
|
|
|
{
|
|
|
|
|
if (!modelViewComponent)
|
|
|
|
|
modelViewComponent = Qt.createComponent("ModelNodeView.qml");
|
|
|
|
|
|
|
|
|
|
// Always recreate the view to ensure model is up to date
|
|
|
|
|
if (modelViewComponent.status === Component.Ready)
|
|
|
|
|
view = modelViewComponent.createObject(viewRect, {"sourceModel": model});
|
2022-02-02 17:56:16 +02:00
|
|
|
|
|
|
|
|
previewObject = model;
|
2020-09-18 12:56:24 +03:00
|
|
|
}
|
|
|
|
|
|
2020-09-22 11:30:05 +03:00
|
|
|
function createViewForNode(node)
|
|
|
|
|
{
|
|
|
|
|
if (!nodeViewComponent)
|
|
|
|
|
nodeViewComponent = Qt.createComponent("NodeNodeView.qml");
|
|
|
|
|
|
|
|
|
|
// Always recreate the view to ensure node is up to date
|
|
|
|
|
if (nodeViewComponent.status === Component.Ready)
|
|
|
|
|
view = nodeViewComponent.createObject(viewRect, {"importScene": node});
|
2022-02-02 17:56:16 +02:00
|
|
|
|
|
|
|
|
previewObject = node;
|
2020-09-22 11:30:05 +03:00
|
|
|
}
|
|
|
|
|
|
2022-02-02 17:56:16 +02:00
|
|
|
function fitToViewPort()
|
2020-09-18 12:56:24 +03:00
|
|
|
{
|
2022-05-27 14:14:22 +03:00
|
|
|
view.fitToViewPort(closeUp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Enables/disables icon mode. When in icon mode, camera is zoomed bit closer to reduce margins
|
|
|
|
|
// and the background is removed, in order to generate a preview suitable for library icons.
|
|
|
|
|
function setIconMode(enable)
|
|
|
|
|
{
|
|
|
|
|
closeUp = enable;
|
|
|
|
|
backgroundRect.visible = !enable;
|
2020-09-18 12:56:24 +03:00
|
|
|
}
|
|
|
|
|
|
2020-09-10 16:02:31 +03:00
|
|
|
Item {
|
|
|
|
|
id: contentItem
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
2022-05-27 14:14:22 +03:00
|
|
|
Item {
|
2020-09-10 16:02:31 +03:00
|
|
|
id: viewRect
|
|
|
|
|
anchors.fill: parent
|
2022-05-27 14:14:22 +03:00
|
|
|
}
|
2020-09-10 16:02:31 +03:00
|
|
|
|
2022-05-27 14:14:22 +03:00
|
|
|
Rectangle {
|
|
|
|
|
id: backgroundRect
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
z: -1
|
2020-09-10 16:02:31 +03:00
|
|
|
gradient: Gradient {
|
|
|
|
|
GradientStop { position: 1.0; color: "#222222" }
|
|
|
|
|
GradientStop { position: 0.0; color: "#999999" }
|
|
|
|
|
}
|
2022-06-23 14:20:56 +03:00
|
|
|
|
|
|
|
|
// Use View3D instead of static image to make background look good on all resolutions
|
|
|
|
|
View3D {
|
2022-08-05 17:14:05 +03:00
|
|
|
id: backgroundView3d
|
2022-06-23 14:20:56 +03:00
|
|
|
anchors.fill: parent
|
|
|
|
|
environment: sceneEnv
|
|
|
|
|
|
|
|
|
|
SceneEnvironment {
|
|
|
|
|
id: sceneEnv
|
|
|
|
|
antialiasingMode: SceneEnvironment.MSAA
|
|
|
|
|
antialiasingQuality: SceneEnvironment.High
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DirectionalLight {
|
|
|
|
|
eulerRotation.x: -26
|
|
|
|
|
eulerRotation.y: -57
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PerspectiveCamera {
|
|
|
|
|
y: 125
|
|
|
|
|
z: 120
|
|
|
|
|
eulerRotation.x: -31
|
|
|
|
|
clipNear: 1
|
|
|
|
|
clipFar: 1000
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Model {
|
|
|
|
|
id: floorModel
|
|
|
|
|
source: "#Rectangle"
|
|
|
|
|
scale.y: 8
|
|
|
|
|
scale.x: 8
|
|
|
|
|
eulerRotation.x: -90
|
|
|
|
|
materials: floorMaterial
|
|
|
|
|
DefaultMaterial {
|
|
|
|
|
id: floorMaterial
|
|
|
|
|
diffuseMap: floorTex
|
|
|
|
|
Texture {
|
|
|
|
|
id: floorTex
|
|
|
|
|
source: "../images/floor_tex.png"
|
|
|
|
|
scaleU: floorModel.scale.x
|
|
|
|
|
scaleV: floorModel.scale.y
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-10 16:02:31 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|