Qt Quick 3D 物理——材料示例
演示如何使用物理材质。

“材质”示例演示了如何控制物理体的材质属性。该场景包含View3D 、PhysicsWorld 、PerspectiveCamera 和DirectionalLight 等常规组件。此外,场景中还包含两个物理体,即一个略微倾斜的平面和一个盒子。 每个物理体都具有一个名为 `physicsMaterial ` 的属性,该属性包含一个 `PhysicsMaterial ` 节点。`PhysicsMaterial ` 包含以下三个材质属性:staticFriction 、dynamicFriction 和restitution ,这些属性用于定义物理体在与其他物体碰撞和滑动时的行为。系统提供了一个简单的用户界面,允许用户交互式地调整方块的材质,以便观察其根据不同材质属性的交互效果。
以下是该材质的 QML 代码:
PhysicsMaterial {
id: physicsMaterial
staticFriction: staticFrictionSlider.value
dynamicFriction: dynamicFrictionSlider.value
restitution: restitutionSlider.value
}该材质仅引用了用户界面中滑块的数值。随后,该材质被同时应用于方块和地板:
DynamicRigidBody {
id: box
physicsMaterial: physicsMaterial
massMode: DynamicRigidBody.CustomDensity
density: 10
property vector3d startPosition: Qt.vector3d(700, 300, 0)
position: startPosition
Model {
source: "#Cube"
materials: PrincipledMaterial {
baseColor: "red"
}
}
collisionShapes: BoxShape {}
}
StaticRigidBody {
eulerRotation: Qt.vector3d(-79, -90, 0)
scale: Qt.vector3d(20, 30, 100)
physicsMaterial: physicsMaterial
collisionShapes: PlaneShape {}
Model {
source: "#Rectangle"
materials: PrincipledMaterial {
baseColor: "green"
}
castsShadows: false
receivesShadows: true
}
}文件:
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.