【问题标题】:Xamarin Forms - Urho - Create scene on pageXamarin Forms - Urho - 在页面上创建场景
【发布时间】:2016-11-24 03:36:35
【问题描述】:

这是我第一次使用 urhosharp,但遇到了一些问题。我尝试遵循一些示例示例,但我的应用程序崩溃了。

我安装了 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 行。未设置渲染器和上下文。我是从不使用页面的特征样本中得到的

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

【问题讨论】:

    标签: c# xamarin urhosharp urho3d


    【解决方案1】:
    1. 浮点数 平面节点比例、FogStart、FogEnd 和 FarClip 的 Vector3() 应该是浮点数。

    2. 如果我们不知道您的视口的上下文,Urho 肯定会崩溃。

    3. 通过将“var”替换为类型名称来提高应用的稳定性:节点、组件、渲染器。

      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));
      }
      
      }}
      

    【讨论】:

      猜你喜欢
      • 2020-03-16
      • 2014-09-13
      • 2017-12-21
      • 2019-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-14
      相关资源
      最近更新 更多