SphereMeshThe SphereMesh item represents a simple UV-sphere in 3D space. More... Inherits Item3D SphereMesh instantiates the C++ class SphereMesh This type was introduced in Qt 4.8. Detailed DescriptionThe SphereMesh element in QML provides a simple way to create a sphere object, usually for testing material effects. For example, the following QML code displays a green sphere mesh of radius 1.5, centered on the origin: Item3D { mesh: SphereMesh { radius: 1.5 } effect: Effect { color: "#aaca00" } } As shown, the mesh is only displayed when it is set as the target of a mesh property on an Item3D. The SphereMesh 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 By default, the sphere is aligned to lie along the Z axis. The axis property can change this to either the X or the Y axis, as shown in the following example: SphereMesh { radius: 1.5 axis: Qt.YAxis } To display the sphere mesh you can create your own Item3D as shown above, or use the convenience Sphere QML component: Sphere { radius: 1.5 levelOfDetail: 6 axis: Qt.YAxis effect: Effect { texture: "moon-texture.jpg" } } The convenience Sphere QML component will create a new mesh each time it is instantiated. If you have a scene with a number of similar spheres use your own Item3D elements to all refer to the same mesh - this will save on graphics memory and improve the performance of your application since there is no need to recreate many copies of the same geometry. This is true even if you want to apply different materials, effects or transformations to each sphere. To do this, first declare the SphereMesh object, outside of any Item3D so that it won't get drawn, and give it an id so you can refer to it. Then set the various effects and so on you need for each instance of the sphere. If you need different sized spheres you can use a scale, and of course you can specify materials and effects. In this case since only one copy of the triangle data for the mesh is sent to the GPU performance will generally be better. Some support for animation of the SphereMesh properties is provided by utilizing a QGraphicsScale3D to implement the radius property, and by caching levels of detail. So within limits animation of these items should provide reasonable results. Be aware that on constrained devices animation of the level of detail for many spheres could cause problems with memory usage due to the caching. The other shapes primitives are implemented differently with respect to radius, length and so on, so read the performance notes there, as they will differ from the sphere case. See also Item3D. |