Qt Quick 3D Physics - 材料示例
演示如何使用物理材料。
材质示例演示了如何控制物理体的材质属性。场景包含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 } }
文件:
© 2025 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.