{"id":1118,"date":"2024-11-04T07:28:45","date_gmt":"2024-11-04T12:28:45","guid":{"rendered":"https:\/\/stepinto.vision\/?p=1118"},"modified":"2026-01-19T09:40:44","modified_gmt":"2026-01-19T14:40:44","slug":"using-volume-baseplates","status":"publish","type":"post","link":"https:\/\/stepinto.vision\/example-code\/using-volume-baseplates\/","title":{"rendered":"Using volume baseplates"},"content":{"rendered":"\n<p>visionOS 2 brought us a new way to show users an indicator for the bottom of a Volume.<\/p>\n\n\n\n<p>This baseplate indicator can be very helpful for finding the edge of a volume. It is especially useful when the user wants to use the resize controls. Volumes will show baseplates by default, but we can hide them if needed.<\/p>\n\n\n\n<p>The <code>volumeBaseplateVisibility<\/code> modifier can be added to a view inside a volume to control visibility.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(0, 0, 0, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>struct ContentView: View {\n\n    @State var showBasePlate = true\n\n    var body: some View {\n        RealityView { content in\n\n            var groundMat = PhysicallyBasedMaterial()\n            groundMat.baseColor.tint = .init(.stepGreen)\n            groundMat.roughness = 0.5\n            groundMat.metallic = 0.0\n\n            let groundModel = ModelEntity(\n                mesh: .generateBox(size: 1, cornerRadius: 0.1),\n                materials: &#91;groundMat&#93;)\n            groundModel.scale = .init(x: 0.8, y: 0.025, z: 0.8)\n            groundModel.position = .init(x: 0, y: -0.44, z: 0)\n            content.add(groundModel)\n\n        } update: { content in\n        }\n        .toolbar() {\n            ToolbarItem(placement: .bottomOrnament, content: {\n                Button(action: {\n                    showBasePlate.toggle()\n                }, label: {\n                    Image(systemName: showBasePlate ? \"rectangle\" : \"rectangle.slash\" )\n                    Text(\"Toggle Baseplate\")\n                })\n            })\n        }\n        .volumeBaseplateVisibility(showBasePlate ? .visible : .hidden)\n\n    }\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #0000FF\">struct<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">ContentView<\/span><span style=\"color: #000000\">: View {<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #0000FF\">@State<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">var<\/span><span style=\"color: #000000\"> showBasePlate = <\/span><span style=\"color: #0000FF\">true<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #0000FF\">var<\/span><span style=\"color: #000000\"> body: some View {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        RealityView { content <\/span><span style=\"color: #AF00DB\">in<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #0000FF\">var<\/span><span style=\"color: #000000\"> groundMat = <\/span><span style=\"color: #795E26\">PhysicallyBasedMaterial<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            groundMat.<\/span><span style=\"color: #001080\">baseColor<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #001080\">tint<\/span><span style=\"color: #000000\"> = .<\/span><span style=\"color: #0000FF\">init<\/span><span style=\"color: #000000\">(.<\/span><span style=\"color: #001080\">stepGreen<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            groundMat.<\/span><span style=\"color: #001080\">roughness<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">0.5<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            groundMat.<\/span><span style=\"color: #001080\">metallic<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">0.0<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #0000FF\">let<\/span><span style=\"color: #000000\"> groundModel = <\/span><span style=\"color: #795E26\">ModelEntity<\/span><span style=\"color: #000000\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                <\/span><span style=\"color: #795E26\">mesh<\/span><span style=\"color: #000000\">: .<\/span><span style=\"color: #795E26\">generateBox<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">size<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #795E26\">cornerRadius<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #098658\">0.1<\/span><span style=\"color: #000000\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                <\/span><span style=\"color: #795E26\">materials<\/span><span style=\"color: #000000\">: &#91;groundMat&#93;)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            groundModel.<\/span><span style=\"color: #001080\">scale<\/span><span style=\"color: #000000\"> = .<\/span><span style=\"color: #0000FF\">init<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">x<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #098658\">0.8<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #795E26\">y<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #098658\">0.025<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #795E26\">z<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #098658\">0.8<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            groundModel.<\/span><span style=\"color: #001080\">position<\/span><span style=\"color: #000000\"> = .<\/span><span style=\"color: #0000FF\">init<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">x<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #795E26\">y<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #098658\">-0.44<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #795E26\">z<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            content.<\/span><span style=\"color: #795E26\">add<\/span><span style=\"color: #000000\">(groundModel)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        } update: { content <\/span><span style=\"color: #AF00DB\">in<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        .<\/span><span style=\"color: #795E26\">toolbar<\/span><span style=\"color: #000000\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #795E26\">ToolbarItem<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">placement<\/span><span style=\"color: #000000\">: .<\/span><span style=\"color: #001080\">bottomOrnament<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #795E26\">content<\/span><span style=\"color: #000000\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                <\/span><span style=\"color: #795E26\">Button<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">action<\/span><span style=\"color: #000000\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                    showBasePlate.<\/span><span style=\"color: #795E26\">toggle<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                }, <\/span><span style=\"color: #795E26\">label<\/span><span style=\"color: #000000\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                    <\/span><span style=\"color: #795E26\">Image<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">systemName<\/span><span style=\"color: #000000\">: showBasePlate ? <\/span><span style=\"color: #A31515\">&quot;rectangle&quot;<\/span><span style=\"color: #000000\"> : <\/span><span style=\"color: #A31515\">&quot;rectangle.slash&quot;<\/span><span style=\"color: #000000\"> )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                    <\/span><span style=\"color: #795E26\">Text<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Toggle Baseplate&quot;<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                })<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            })<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">        .<\/span><span style=\"color: #795E26\">volumeBaseplateVisibility<\/span><span style=\"color: #000000\">(showBasePlate ? .<\/span><span style=\"color: #001080\">visible<\/span><span style=\"color: #000000\"> : .<\/span><span style=\"color: #001080\">hidden<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n\t\t<figure class=\"wp-block-jetpack-videopress jetpack-videopress-player\" style=\"\" >\n\t\t\t<div class=\"jetpack-videopress-player__wrapper\"> <div class=\"jetpack-video-wrapper\"><iframe title=\"VideoPress Video Player\" aria-label='VideoPress Video Player' width='720' height='540' src='https:\/\/videopress.com\/embed\/6Q4NszP7?cover=1&amp;autoPlay=1&amp;controls=1&amp;loop=1&amp;muted=1&amp;persistVolume=0&amp;playsinline=0&amp;preloadContent=metadata&amp;useAverageColor=1&amp;hd=0' frameborder='0' allowfullscreen data-resize-to-parent=\"true\" allow='clipboard-write'><\/iframe><script src='https:\/\/v0.wordpress.com\/js\/next\/videopress-iframe.js?m=1739540970'><\/script><\/div><\/div>\n\t\t\t\n\t\t\t\n\t\t<\/figure>\n\t\t<div class=\"wp-video-description\" style=\"margin-top: 10px; margin-bottom: 10px; font-style: italic;\"><p>Simulator video showing volume baseplates hidden and visible.<\/p>\n<\/div>\n\n\n<p><a href=\"https:\/\/developer.apple.com\/documentation\/SwiftUI\/View\/volumeBaseplateVisibility(_:)\">https:\/\/developer.apple.com\/documentation\/SwiftUI\/View\/volumeBaseplateVisibility(_:)<\/a><\/p>\n\n\n\n<p class=\"has-theme-palette-8-background-color has-background\">Sample code is available in Garden11 in the <a href=\"https:\/\/github.com\/radicalappdev\/Step-Into-Example-Projects\">Step Into Example Projects<\/a> repo.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>visionOS 2 brought us a new way to show users an indicator for the bottom of a Volume.<\/p>\n","protected":false},"author":93705089,"featured_media":1121,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_EventAllDay":false,"_EventTimezone":"","_EventStartDate":"","_EventEndDate":"","_EventStartDateUTC":"","_EventEndDateUTC":"","_EventShowMap":false,"_EventShowMapLink":false,"_EventURL":"","_EventCost":"","_EventCostDescription":"","_EventCurrencySymbol":"","_EventCurrencyCode":"","_EventCurrencyPosition":"","_EventDateTimeSeparator":"","_EventTimeRangeSeparator":"","_EventOrganizerID":[],"_EventVenueID":[],"_OrganizerEmail":"","_OrganizerPhone":"","_OrganizerWebsite":"","_VenueAddress":"","_VenueCity":"","_VenueCountry":"","_VenueProvince":"","_VenueState":"","_VenueZip":"","_VenuePhone":"","_VenueURL":"","_VenueStateProvince":"","_VenueLat":"","_VenueLng":"","_VenueShowMap":false,"_VenueShowMapLink":false,"_kadence_starter_templates_imported_post":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2},"_wpas_customize_per_network":false,"jetpack_post_was_ever_published":false},"categories":[1365],"tags":[],"class_list":["post-1118","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-example-code"],"jetpack_publicize_connections":[],"taxonomy_info":{"category":[{"value":1365,"label":"Example Code"}]},"featured_image_src_large":["https:\/\/i0.wp.com\/stepinto.vision\/wp-content\/uploads\/2024\/11\/step-garden-11-01.jpeg?fit=1024%2C768&ssl=1",1024,768,true],"author_info":{"display_name":"Joseph Simpson","author_link":"https:\/\/stepinto.vision\/author\/vrhermit\/"},"comment_info":0,"category_info":[{"term_id":1365,"name":"Example Code","slug":"example-code","term_group":0,"term_taxonomy_id":11,"taxonomy":"category","description":"Code snippets and examples of using common APIs throughout visionOS development","parent":0,"count":187,"filter":"raw","cat_ID":1365,"category_count":187,"category_description":"Code snippets and examples of using common APIs throughout visionOS development","cat_name":"Example Code","category_nicename":"example-code","category_parent":0}],"tag_info":false,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/stepinto.vision\/wp-content\/uploads\/2024\/11\/step-garden-11-01.jpeg?fit=2732%2C2048&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/posts\/1118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/users\/93705089"}],"replies":[{"embeddable":true,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/comments?post=1118"}],"version-history":[{"count":9,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/posts\/1118\/revisions"}],"predecessor-version":[{"id":8773,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/posts\/1118\/revisions\/8773"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/media\/1121"}],"wp:attachment":[{"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/media?parent=1118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/categories?post=1118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/tags?post=1118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}