How to display 3d models?

mc 3,726 Reputation points
2021-02-08T05:37:04.89+00:00

I want to display 3d models in xamarin.forms.

you may say I could use urhosharp . yes but it only support one scene at the same time which means I can only display 1 items .

what I want to do is write a custom view which display the 3d model so that there can be many views which is 3d.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,301 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 69,386 Reputation points Microsoft Vendor
    2021-02-08T10:32:43.717+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    If you use urhosharp to load 3D models, you do not need to create a custom view,Install UrhoSharp.Forms in your platform and PCL projects. Put urhosharp to <StackLayout> and use <ScrollView> to contains that like following code.

       <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"  
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:urho="clr-namespace:Urho.Forms;assembly=UrhoSharp.Forms"  
                    x:Class="Urho3DDemo.MainPage">  
         
           <StackLayout>  
               <ScrollView>  
                   <StackLayout>  
                   <StackLayout>  
                       <urho:UrhoSurface x:Name="HelloWorldUrhoSurface" HorizontalOptions="FillAndExpand" HeightRequest="300"/>  
                   </StackLayout>  
                   <StackLayout>  
                       <urho:UrhoSurface x:Name="HelloWorldUrhoSurface2" HorizontalOptions="FillAndExpand" HeightRequest="300"/>  
                   </StackLayout>  
                       <StackLayout>  
                           <urho:UrhoSurface x:Name="HelloWorldUrhoSurface3" HorizontalOptions="FillAndExpand" HeightRequest="300"/>  
                       </StackLayout>  
                   </StackLayout>  
                     
               </ScrollView>  
           </StackLayout>  
         
       </ContentPage>  
    

    Here is layout background code.

       public partial class MainPage : ContentPage  
           {  
               public MainPage()  
               {  
                   InitializeComponent();  
                       
               }  
         
               protected override async void OnAppearing()  
               {  
                   base.OnAppearing();  
         
                   await HelloWorldUrhoSurface.Show<HelloWorld>(new Urho.ApplicationOptions(assetsFolder: null) { Orientation = ApplicationOptions.OrientationType.LandscapeAndPortrait });  
         
                   await HelloWorldUrhoSurface2.Show<HelloWorld>(new Urho.ApplicationOptions(assetsFolder: null) { Orientation = ApplicationOptions.OrientationType.LandscapeAndPortrait });  
         
                   await HelloWorldUrhoSurface3.Show<HelloWorld>(new Urho.ApplicationOptions(assetsFolder: null) { Orientation = ApplicationOptions.OrientationType.LandscapeAndPortrait });  
         
               }  
         
         
           }  
    

    Here is HelloWorld.cs.

       using Urho;  
       using Urho.Actions;  
       using Urho.Gui;  
         
       namespace Urho3DDemo  
       {  
           public class HelloWorld : Application  
           {  
               //public HelloWorld() { }  
               public HelloWorld(ApplicationOptions options) : base(options) { }  
         
               protected override async void Start()  
               {  
                   base.Start();  
                   
                   CreateText();  
               }  
               
               private void CreateText()  
               {  
                   // Create Text Element  
                   var text = new Text()  
                   {  
                       Value = "Hello World!",  
                       HorizontalAlignment = HorizontalAlignment.Center,  
                       VerticalAlignment = VerticalAlignment.Center  
                   };  
         
                   text.SetColor(Color.Cyan);  
                   text.SetFont(font: ResourceCache.GetFont("Fonts/Anonymous Pro.ttf"), size: 30);  
                   // Add to UI Root  
                   UI.Root.AddChild(text);  
         
               }  
         
           }  
       }  
    

    Here is running screenshot.

    65411-image.png

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful