Xamarin Forms - Urho - 创建场景网页
问题描述:
这是我第一次使用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线,因为我渐渐的错误。渲染器和上下文未设置。我从那些没有使用页面的功能样本中获得了这个功能
// var renderer = Renderer; //renderer.SetViewport(0,new Viewport(Context,scene,camera,null));
答
浮的的Vector3()为您的平面节点规模,FogStart,FogEnd和FarClip应该浮动。
如果我们不知道上下文您的视口,Urho肯定崩溃。
-
通过用typename:Node,Component,Renderer替换'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)); } }}