Xna 单独网格的DrawUserIndexedPrimitions

Xna 单独网格的DrawUserIndexedPrimitions,xna,c#-3.0,xna-3.0,Xna,C# 3.0,Xna 3.0,这是一个noob问题,但我已经搜索了很多遍,找不到答案 我有两个单独的网格需要在同一个窗口中绘制,都使用DrawUserIndexedPrimitives。我使用了两个基本的fect实例,它们有自己的视图和投影矩阵 但是,当渲染它们时,会有一条线将两者连接在一起。XNA认为它们是同一个网格的一部分。是否需要为每个实例使用单独的GraphicsDeviceManager实例?那似乎不对 protected override void Draw(GameTime gameTime) { Gr

这是一个noob问题,但我已经搜索了很多遍,找不到答案

我有两个单独的网格需要在同一个窗口中绘制,都使用DrawUserIndexedPrimitives。我使用了两个基本的fect实例,它们有自己的视图和投影矩阵

但是,当渲染它们时,会有一条线将两者连接在一起。XNA认为它们是同一个网格的一部分。是否需要为每个实例使用单独的GraphicsDeviceManager实例?那似乎不对

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);
    GraphicsDevice.VertexDeclaration = declaration;

    effect.Begin();
    effect.View = view;

    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
    {
        pass.Begin();
        GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, positions1, 0, positions1.Length, index1, 0, index1.Length / 3);
        pass.End();
    }

    effect.End();

    effect2.Begin();
    effect2.View = view2;

    foreach (EffectPass pass in effect2.CurrentTechnique.Passes)
    {
        pass.Begin();
        GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, positions2, 0, positions2.Length, index2, 0, index2.Length / 3);
        pass.End();
    }

    effect2.End();

    base.Draw(gameTime);
}
protected override void Draw(游戏时间游戏时间)
{
图形设备。清晰(颜色:矢车菊蓝);
GraphicsDevice.VertexDeclaration=声明;
Begin()的效果;
效果。视图=视图;
foreach(EffectPass-in-effect.currentTechnology.passs)
{
pass.Begin();
GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangelList,位置1,0,位置1.Length,索引1,0,索引1.Length/3);
pass.End();
}
效果。结束();
效应2.开始();
effect2.View=view2;
foreach(effect2.currentTechnology.passs中的EffectPass pass)
{
pass.Begin();
GraphicsDevice.DrawUserIndexedPrimitions(PrimitiveType.TriangelList,位置2,0,位置2.Length,索引2,0,索引2.Length/3);
pass.End();
}
效应2.结束();
基础。抽签(游戏时间);
}
位置S1中的最后一个三角形连接到位置S2中的第一个三角形

感谢您提供的任何帮助。

ZOMG!我明白了

看起来XNA只将指数视为基于零的(尽管大多数坐标系都是基于一的),我有这样的想法:

int[] index1 = new int[] { 1, 2, 3, ..., n };
将其更改为此解决了问题:

int[] index1 = new int[] { 0, 1, 2, ..., n - 1 };

索引不是坐标:P