0

这是我第一次使用 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.SetViewport(0, new Viewport(Context, scene, camera, null));

4

1 回答 1

-1
  1. 浮动平面节点比例的 Vector3()、FogStart、FogEnd 和 FarClip 应该是浮动的。

  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));
    }
    
    }}
    
于 2017-06-10T19:59:05.773 回答