2023-06-19 13:29:46 +00:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
|
|
import QtQuick
|
|
|
|
import QtQuick3D
|
|
|
|
import QtQuick3D.Physics
|
|
|
|
import QtQuick3D.Helpers
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: item
|
|
|
|
property real settingGravity: 980.7
|
2025-02-28 09:30:42 +00:00
|
|
|
property alias settingsStaticFriction: physicsMaterial.staticFriction
|
|
|
|
property alias settingsDynamicFriction: physicsMaterial.dynamicFriction
|
|
|
|
property alias settingsRestitution: physicsMaterial.restitution
|
|
|
|
property alias settingsDiceWidth: diceSpawner.diceWidth
|
|
|
|
property alias settingsDiceCount: diceSpawner.count
|
|
|
|
property alias rollForce: diceSpawner.rollForce
|
2025-02-28 09:56:29 +00:00
|
|
|
property alias cameraControllerEnabled : orbitCameraController.enabled
|
2025-02-28 09:30:42 +00:00
|
|
|
|
|
|
|
function spawnDice() {
|
|
|
|
diceSpawner.respawn()
|
2023-06-19 13:29:46 +00:00
|
|
|
}
|
|
|
|
|
2024-09-24 16:46:21 +00:00
|
|
|
Screen.onPrimaryOrientationChanged: {
|
|
|
|
var orientation = Screen.primaryOrientation
|
|
|
|
var isPortrait = orientation === Qt.PortraitOrientation
|
|
|
|
|| orientation === Qt.InvertedPortraitOrientation
|
|
|
|
viewport.camera.position = Qt.vector3d(0, -20, isPortrait ? 100 : 60)
|
|
|
|
}
|
|
|
|
|
2023-06-19 13:29:46 +00:00
|
|
|
PhysicsWorld {
|
|
|
|
id: physicsWorld
|
|
|
|
running: true
|
|
|
|
enableCCD: true
|
|
|
|
scene: viewport.scene
|
2024-07-05 07:59:31 +00:00
|
|
|
gravity: Qt.vector3d(0, -item.settingGravity, 0)
|
2023-06-19 13:29:46 +00:00
|
|
|
typicalLength: 1
|
|
|
|
typicalSpeed: 1000
|
|
|
|
minimumTimestep: 15
|
|
|
|
maximumTimestep: 20
|
|
|
|
}
|
|
|
|
|
|
|
|
PhysicsMaterial {
|
|
|
|
id: physicsMaterial
|
2025-02-28 09:30:42 +00:00
|
|
|
staticFriction: 0.5
|
|
|
|
dynamicFriction: 0.5
|
|
|
|
restitution: 0.5
|
2023-06-19 13:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OrbitCameraController {
|
2025-02-28 09:56:29 +00:00
|
|
|
id: orbitCameraController
|
2023-06-19 13:29:46 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
origin: originNode
|
|
|
|
camera: camera
|
2024-10-31 10:15:53 +00:00
|
|
|
panEnabled: false
|
2023-06-19 13:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
View3D {
|
|
|
|
id: viewport
|
|
|
|
anchors.fill: parent
|
|
|
|
camera: camera
|
|
|
|
|
|
|
|
Node {
|
|
|
|
id: originNode
|
|
|
|
eulerRotation: Qt.vector3d(-14.2885, 410.287, 0)
|
|
|
|
PerspectiveCamera {
|
|
|
|
id: camera
|
2024-09-24 16:46:21 +00:00
|
|
|
position: Qt.vector3d(0, -20, 100)
|
2023-06-19 13:29:46 +00:00
|
|
|
clipFar: 1000
|
|
|
|
clipNear: 0.1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
environment: SceneEnvironment {
|
|
|
|
clearColor: "white"
|
|
|
|
backgroundMode: SceneEnvironment.SkyBox
|
|
|
|
antialiasingMode: SceneEnvironment.MSAA
|
|
|
|
antialiasingQuality: SceneEnvironment.High
|
|
|
|
lightProbe: proceduralSky
|
|
|
|
}
|
|
|
|
|
|
|
|
Texture {
|
|
|
|
id: proceduralSky
|
|
|
|
textureData: ProceduralSkyTextureData {
|
|
|
|
sunLongitude: -115
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Node {
|
|
|
|
id: scene
|
|
|
|
|
2025-02-28 08:02:43 +00:00
|
|
|
PointLight {
|
|
|
|
y: 80
|
|
|
|
x: 80
|
|
|
|
z: 80
|
2023-06-19 13:29:46 +00:00
|
|
|
castsShadow: true
|
|
|
|
brightness: 1
|
2024-08-06 11:27:53 +00:00
|
|
|
shadowFactor: 100
|
2023-06-19 13:29:46 +00:00
|
|
|
shadowMapQuality: Light.ShadowMapQualityVeryHigh
|
2025-02-28 08:02:43 +00:00
|
|
|
softShadowQuality: Light.PCF64
|
2024-10-01 10:23:21 +00:00
|
|
|
shadowBias: 0.4
|
2025-02-28 08:02:43 +00:00
|
|
|
pcfFactor: 0.01
|
|
|
|
quadraticFade: 0.001
|
2023-06-19 13:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PhysicalTable {
|
|
|
|
id: table
|
|
|
|
}
|
|
|
|
|
|
|
|
DiceSpawner {
|
|
|
|
id: diceSpawner
|
2025-02-28 09:30:42 +00:00
|
|
|
physicsMaterial: physicsMaterial
|
|
|
|
diceWidth: 3.5
|
|
|
|
rollForce: Qt.vector3d(0, 0, 0)
|
2023-06-19 13:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Carpet {
|
|
|
|
position: Qt.vector3d(0, -50, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
// floor
|
|
|
|
StaticRigidBody {
|
|
|
|
position: Qt.vector3d(0, -50, 0)
|
|
|
|
eulerRotation: Qt.vector3d(-90, 0, 0)
|
2023-08-17 03:49:16 +00:00
|
|
|
collisionShapes: PlaneShape {}
|
2023-06-19 13:29:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|