2016-11-24 2 views
0

это первый раз, когда я использую urhosharp, и у меня есть некоторые проблемы. Я попробовал несколько примеров примеров, но мое приложение рушится.Xamarin Forms - Urho - Создать сцену на странице

Я установил NuGet UrhoSharp.Forms пакет

Я просто хочу, чтобы создать сцену с камерой в середине, что я может вращаться на 360 градусов.

Это моя страница:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

using Urho; 
using Urho.Forms; 

using Urho.Resources; 
using Urho.Gui; 

using Xamarin.Forms; 

namespace testApp.Pages.Urho 
{ 
    public partial class urhoPage : ContentPage 
    { 

     Scene scene; 
     Camera camera; 

     protected Node CameraNode { get; set; } 


     public urhoPage() 
     { 
      InitializeComponent(); 

      scene = new Scene(); 

      scene.CreateComponent<Octree>(); 
      scene.CreateComponent<DebugRenderer>(); 

      var planeNode = scene.CreateChild("Plane"); 
      planeNode.Scale = new Vector3(100, 1, 100); 
      var planeObject = planeNode.CreateComponent<StaticModel>(); 

      // Create a Zone component for ambient lighting & fog control 
      var zoneNode = scene.CreateChild("Zone"); 
      var zone = zoneNode.CreateComponent<Zone>(); 

      // Set same volume as the Octree, set a close bluish fog and some ambient light 
      zone.SetBoundingBox(new BoundingBox(-1000.0f, 1000.0f)); 
      zone.AmbientColor = new Urho.Color(0.15f, 0.15f, 0.15f); 
      zone.FogColor = new Urho.Color(0.5f, 0.5f, 0.7f); 
      zone.FogStart = 100; 
      zone.FogEnd = 300; 

      // Create the camera. Limit far clip distance to match the fog 
      CameraNode = scene.CreateChild("Camera"); 
      camera = CameraNode.CreateComponent<Camera>(); 
      camera.FarClip = 300; 

      // Set an initial position for the camera scene node above the plane 
      CameraNode.Position = new Vector3(0.0f, 5.0f, 0.0f); 

      // var renderer = Renderer; 
      //renderer.SetViewport(0, new Viewport(Context, scene, camera, null)); 


     } 
    } 
} 

мне пришлось удалить эти 2 линии, как я получаю сообщение об ошибке. Renderer и контекст не были установлены. я получил это из образцов возможностей, которые не использовали страницы

// var renderer = Renderer; //renderer.SetViewport(0, новый Viewport (Контекст, сцена, камера, null));

ответ

0
  1. поплавки The Vector3() для масштаба узла плоскости, FogStart, FogEnd и FarClip должны быть поплавки.

  2. Если мы не знаем Контекст для вашего окна просмотра, Urho аварийно завершает работу.

  3. Повысьте стабильность своего приложения, заменив «var» на имя: Node, Component, Renderer.

    using Xamarin.Forms; 
    namespace testApp.Pages.Urho 
    { 
    public partial class urhoPage : ContentPage 
    { 
    Scene scene; 
    Camera camera; 
    
    protected Node CameraNode { get; set; } 
    
    
    public urhoPage() 
    { 
        InitializeComponent(); 
    
        scene = new Scene(); 
    
        scene.CreateComponent<Octree>(); 
        scene.CreateComponent<DebugRenderer>(); 
    
        var planeNode = scene.CreateChild("Plane"); 
        planeNode.Scale = new Vector3(100f, 1f, 100f); 
        var planeObject = planeNode.CreateComponent<StaticModel>(); 
    
        // Create a Zone component for ambient lighting & fog control 
        var zoneNode = scene.CreateChild("Zone"); 
        var zone = zoneNode.CreateComponent<Zone>(); 
    
        // Set same volume as the Octree, set a close bluish fog and some ambient light 
        zone.SetBoundingBox(new BoundingBox(-1000.0f, 1000.0f)); 
        zone.AmbientColor = new Urho.Color(0.15f, 0.15f, 0.15f); 
        zone.FogColor = new Urho.Color(0.5f, 0.5f, 0.7f); 
        zone.FogStart = 100f; 
        zone.FogEnd = 300f; 
    
        // Create the camera. Limit far clip distance to match the fog 
        CameraNode = new Node(); 
        Camera camera = CameraNode.CreateComponent<Camera>(); 
        camera.FarClip = 300.0f; 
    
        // Set an initial position for the camera scene node above the plane 
        CameraNode.Position = new Vector3(0.0f, 5.0f, 0.0f); 
    
        var renderer = Application.Current.Renderer; 
        renderer.SetViewport(0, new Viewport(Application.CurrentContext, scene, CameraNode.GetComponent<Camera>(), null)); 
    } 
    
    }} 
    
Смежные вопросы