CapsuleMeshThe CapsuleMesh item represents a simple capsule in 3D space. More... Inherits Mesh CapsuleMesh instantiates the C++ class CapsuleMesh This type was introduced in Qt 4.8. Detailed DescriptionThe CapsuleMesh element in QML provides a simple way to create a capsule object, usually for testing material effects. Capsule's center is its barycenter. For example, the following QML code displays a green capsule with a uniform diameter of 0.5, and a length of 3.0: Item3D { mesh: CapsuleMesh { radius: 0.5 length: 3.0 } effect: Effect { color: "#aaca00" } } The CapsuleMesh element is part of the Qt3D.Shapes namespace, so the following must appear at the top of any QML file that references it: import Qt3D.Shapes 1.0 The capsule shape can have differing levels of detail, allowing for additional slices and layers to be drawn if more detailed meshes are required. Note that the length of the capsule should always exceed its diameter to be considered valid. To display the capsule mesh you can create your own Item3D as shown above, or use the convenience Capsule QML Component. Capsule { radius: 0.5 length: 3.0 effect: Effect { color: "#aaca00" } } Performance Hints for Larger ScenesThe convenience Capsule QML component will create a new mesh each time is instantiated. If you have a scene with a number of similar capsules use your own Item3D elements to all refer to the same mesh. See the Performance Hints section of the SphereMesh documentation for more details on this important technique. Performance Hints for AnimationBecause of the need to maintain the relative proportions of the cylinders components, the length and radius are implemented directly in the construction of the mesh. This differs from the approach used in the SphereMesh where a scale is used. For this reason avoid animating the length and radius properties of a CapsuleMesh, as it will give poor results due to the mesh being recreated every frame. Since the capules components are created with named sections in the mesh, one approach would be to individually apply scales to these sections using the meshNode property. This is an advanced topic, and future tutorials may cover it in more depth. See also Item3D and SphereMesh. |