Qt 6.4中的Qt Quick 3D物理

Qt Quick 3D Physics in Qt 6.4

Qt 6.4中的Qt Quick 3D物理

Friday July 15, 2022 by Jonas Karlsson | Comments

​2022年7月15日星期五Jonas Karlsson评论

Qt 6.4 includes the new module Qt Quick 3D Physics as tech preview. As the name implies, this is a module that adds physical simulation capabilities on top of Qt Quick 3D. In particular, it enables rigid body simulation using simple primitives (spheres, boxes, planes and capsules) as well as convex- and triangle meshes and heightmaps. Physical properties such as mass, density, gravity and friction are customizable. This makes it possible to create physically correct behavior in 3D scenes without having to handcraft animations.

Qt 6.4包括新模块Qt Quick 3D Physics作为技术预览。顾名思义,这是一个在Qt Quick 3D上添加物理模拟功能的模块。特别是,它支持使用简单的基本体(球体、长方体、平面和胶囊)以及凸面和三角形网格和高度图进行刚体模拟。物理特性(如质量、密度、重力和摩擦力)可自定义。这使得在3D场景中创建物理上正确的行为成为可能,而无需手工制作动画。

Adding physics to your scene is quite easy. The following snippet is all it takes to create and render a whole scene with a plane and a box interacting with each other:

将物理添加到场景中相当容易。以下片段是创建和渲染整个场景所需的全部内容,其中平面和长方体相互交互:


import QtQuick
import QtQuick3D
import QtQuick3D.Physics

Window {
    visible: true
    DynamicsWorld {}

    View3D {
        anchors.fill: parent

        PerspectiveCamera {
            position: Qt.vector3d(0, 100, 500)
            clipFar: 5000
            clipNear: 1
        }

        DirectionalLight {
            eulerRotation.x: -45
            eulerRotation.y: 45
            castsShadow: true
        }

        StaticRigidBody {
            position: Qt.vector3d(0, 0, 0)
            eulerRotation: Qt.vector3d(-90, 0, 0)
            collisionShapes: PlaneShape {}
            Model {
                source: "#Rectangle"
                scale: Qt.vector3d(10, 10, 10)
                materials: PrincipledMaterial {
                    baseColor: "green"
                }
                castsShadows: false
                receivesShadows: true
            }
        }

        DynamicRigidBody {
            position: Qt.vector3d(0, 200, 0)
            collisionShapes: BoxShape {}
            Model {
                source: "#Cube"
                materials: PrincipledMaterial {
                    baseColor: "yellow"
                }
            }
        }
    }
}

And this is how it looks:

这是它的外观:



Qt Quick 3D Physics is a pure QML API and is currently available as a tech preview in Qt 6.4. The documentation comes with a handful of explanatory examples showing off the different capabilities of the module. This is the best place to start if you want to try it out yourself.  There is a lot more that could be said about this module but since a picture says a thousand words I imagine this video of the examples will say even more.

​Qt Quick 3D Physics是一个纯QML API,目前在Qt 6.4中作为技术预览版提供。文档附带了几个解释性示例,展示了模块的不同功能。如果你想亲自尝试,这是最好的开始。关于这个模块还有很多要说的,但因为一张图片能说千言万语,我想这个例子的视频会说得更多。

https://play.hubspotvideo.com/dba0c1eb-69f5-4aae-af8f-f511db709390

I hope you found this blog post interesting and I look forward to seeing what you will create with this new module.

我希望你觉得这篇博文很有趣,我期待着看到你将用这个新模块创建什么。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值