Hello. Today I want to share with you my experience with simple 3D graphics at Xamarin.Forms, hopefully it will be useful to anyone. Here I will not go deep into technical nuances, rather I will leave references to, from my point of view, simple and useful materials that handle it perfectly, but to describe my impressions in general. I have been intriguing a bit by creation some 3D stuff always, but never tried it before, and, anyway, i am working with my favorite Xamarin for now. So, i decided to "mix" it.
For starters, About the choice of development tools. The best known and most accessible for Xamarin are Unity and UhoSharp. I chose the Urho series because they have a special UrhoSharp.Forms plug-in for Xamarin.Forms, and judging by the generally small amount of information on the network about working with 3D for Xamarin, it is simpler, at least in the early stages of development - for example, there is already a ready pre-set of the simplest geometric figures (pyramid, sphere, rectangular parllelipid (aka box), etc). Although, as it later turned out, Urho also has its nuances in this direction.
For starters, I decided to create a very simple geometric shape, with perhaps some simple effects on it. The following article helped me in this: https://www.xamarinhelp.com/urhosharp-3d-moving-object. It allows you create this animation in a few minutes:
All further ideas I realized on the basis of this modest experience, knowledge of geometry and method of trial and error, as subsequently discovered a shortcoming of Urho for Xamarin - no convenient documentation on it, there are only samples of code on the GitHub (for Xamarin.Forms only one): https://github.com/xamarin/urho-samples; and you can find several articles for the concept of basic functionality.
The next step, I decided to try to make a slightly more real object and try to implement it from different points of view - that would just highlight the 3D aspect. I decided to create, for example, a table, and to rotate the camera around it (the table remains still). There i have to say a few words about the general device of 3D scenes for UrhoSharp.Forms. There you have some "surface" in which you place your scene. All objects are placed by "nodes": it can be models, camera position, lighting, etc. For these nodes and components, created for them, you can assign a position in an absolute coordinate system, rotating around its axis, sizes. First, I had to think about the arrangement of the objects in the coordinate system. I decided to place the center of the model of the table at the beginning of the coordinate system and slightly shift it along the Z axis in a positive direction to simplify further calculations (0,0,5). Creating a table itself is not a problem (it is a set of simple components already integrated into UrhoSharp.Forms, about which I wrote earlier - "box" and "cylinder"). It is also easy to specify elementary camera movement - you have to move the corresponding node, of which it is a component, changing its position by property.
The circle formula from the basic course of geometry helped me with the rotation of the camera around the table. It becomes more difficult to rotate the camera, as it is implemented in UhoSharp by quaternions, and if you are not as familiar with this concept as I am, you will need to spend some time studying this applied theory. But, if you need rotate camera around only one axe, it will be more easy - it's just working with degrees. The realization of this moment became, probably, the main difficulty in realization of the project - here is the complex mathematics and absence of any explanations and documentation for Urhosharp.Forms. Also, base UrhoObject class is not inherited from BindableObject, so, you can't use Bindable Properties for it. Anyway, you can see the result below (i added coordinate axes for better visibility)
Summing Up:
In my opinion, UrhoSharp.Forms is a good tool for creating 3D models in Xamarin.Forms, at least, for no-complicated tasks. Especially, if you don't mind to spend a bit of time to understand its code by yourself. I hope this could be useful for you and help create a preview of 3D graphics in Xamrin.Forms.
More useful links:
basic introduction for UrhoSharp.Forms
https://www.xamarinexpert.it/urhosharp-tutorial-how-to-create-your-first-project-with-xamarin-forms - one more tutorial about creation UrhoHarp.Forms app.
https://github.com/NikolaiMiroshnichenko/UrhoTest3D - my repository with table model example.
Comentarios