シンプルなポイントクラウドビューアを作成したいと思います。私はC#とXNAを使っています。私は回転し、それにズームけどもパフォーマンスが弱いことができポイントクラウドビューアのパフォーマンスを向上させる方法
: この瞬間に私はこれを作成しました。 1,500,000ポイントのクラウドでは、回転またはズームを完了するのに約6秒かかります。それをより良くする方法は?すべてを再描画せずに回転またはズームする可能性はありますか?
図面についてのマイコードスニペット。イム使用してSpriteBatches:
ba.Begin();
for (int i = 0; i < DBmanager.data.Length; i++)
{
Vector3 screenLocation = Device.Viewport.Project(DBmanager.data[i], basicEffect.Projection, basicEffect.View, basicEffect.World);
ba.Draw(pixel, new Vector2(screenLocation.X, screenLocation.Y), Color.Orange);
}
ba.End();
移動機能:
private void move(float x,float y)
{
//currentx += x;
Debug.WriteLine(x);
Debug.WriteLine(y);
if (x == 0)
{
Vector3 target = new Vector3(Center.X, Center.Y, Center.Z);
cameraPosition = Vector3.Transform(cameraPosition - target, Matrix.CreateRotationY(y)) + target;
basicEffect.View = Matrix.CreateLookAt(cameraPosition, target, Vector3.Up);
}
if (y == 0)
{
Vector3 target = new Vector3(Center.X, Center.Y, Center.Z);
cameraPosition = Vector3.Transform(cameraPosition - target, Matrix.CreateRotationX(x)) + target;
basicEffect.View = Matrix.CreateLookAt(cameraPosition, target, Vector3.Up);
}
}
マイDraw関数:
protected override void Draw()
{
if (called)
{
Application.Idle -= IdleHandler;
timer.Stop();
SetUpVertices();
called = false;
//Invalidate();
}
// if (drawn)
// {
//Application.Idle -= IdleHandler;
//timer.Stop();
// UpdateCam();
// Debug.WriteLine("Obrót zakonczony");
//SetUpVertices();
// }
if (leftDrag)
{
Application.Idle -= IdleHandler;
timer.Stop();
UpdateCam();
//SetUpVertices();
leftDrag = false;
}
if (Zoomed)
{
Application.Idle -= IdleHandler;
timer.Stop();
Zoom(Zoomlevel);
//UpdateCam();
//SetUpVertices();
Zoomed = false;
}
}
SetupVertices:
private void SetUpVertices()
{
Device.Clear(Color.Black);
VertexPositionColor [] Verts = new VertexPositionColor [65535];
RasterizerState rasterizerState = new RasterizerState();
rasterizerState.CullMode = CullMode.None;
Device.RasterizerState = rasterizerState;
int j = 0;
for (int i = 0; i < DBmanager.data.Length; i++)
{
if (j==65535)
{
buf = new VertexBuffer(Device, typeof(VertexPositionColor), Verts.Length, BufferUsage.WriteOnly);
buf.SetData<VertexPositionColor>(Verts);
Device.SetVertexBuffer(buf);
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
Device.DrawPrimitives(PrimitiveType.TriangleList, 0, Verts.Length);
}
Verts = new VertexPositionColor[65535];
j = 0;
}
else
{
Verts[j] = new VertexPositionColor(new Vector3(DBmanager.data[i].X, DBmanager.data[i].Y, DBmanager.data[i].Z),Color.Orange);
j++;
}
}
if (!IsCenterCalculated)
{
Box = BoundingBox.CreateFromPoints(DBmanager.data);
corners = Box.GetCorners();
setCenter(CalculateCenter(corners));
IsCenterCalculated = true;
basicEffect.View = Matrix.CreateLookAt(cameraPosition, new Vector3(Center.X, Center.Y, Center.Z), Vector3.Up);
}
}
相互作用( 'Game.Update()')、データ管理、および実際の描画( 'Game.Draw()')を分離する必要があります。 'SetupVertices()'を使ってポイントクラウドを描くように見えます。これにより、常にGPUにデータ全体が送信されるため、以前と同じ問題が発生します。頂点を一度しか設定しないと、フレームごとに 'DrawPrimitives()'を行うことができます。 Btw、 'TriangleList'ではなく' PointList'ですか? –
セットアップ中に 'basicEffect.View'を呼び出すべきではありません。 – MickyD
スプライトバッチは遅く、基本的にすべての描画操作が各フレームにGPUに再送される_immediateモードです。あなたはGPUに保存されている多くのテクニックを欲しい – MickyD