0

some bugs found in MeshBuilder

Anonymous 9 years ago
This discussion was imported from CodePlex

jpg99 wrote at 2012-08-15 15:17:

hello,

i'm using your toolkit for a project at work . I  have to draw 3d houses from a 2D polygon (plane section of the house), so i experimented with AddExtrudedGeometry, and encountered several difficulties. Eventually i wrote my own function for building the 3d houses, and i don't remember precisely what the problems were (sorry it was a few weeks ago), mostly problems with triangles defined in the wrong sense so that the outside / inside were  inversed.

Here is the code i corrected in MeshBuilder.cs :

```    public void AddExtrudedGeometry(IList points, Vector3D xaxis, Point3D p0, Point3D p1)
{
var ydirection = Vector3D.CrossProduct(xaxis, p0 - p1);
ydirection.Normalize();
xaxis.Normalize();

int np = 2 * points.Count;
foreach (var p in points)
{
int i0 = this.positions.Count;
var v = (xaxis * p.X) + (ydirection * p.Y);
v.Normalize();
if (this.normals != null)
{
}

if (this.textureCoordinates != null)
{
}

int i1 = i0 + 1;
int i2 = (i0 + 2) % np;
int i3 = i2 + 1;

}
}

IList fanPositions, IList fanNormals = null, IList fanTextureCoordinates = null)
{
if (this.positions == null)
{
throw new ArgumentNullException("fanPositions");
}

if (fanNormals != null && this.normals == null)
{
throw new ArgumentNullException("fanNormals");
}

if (fanTextureCoordinates != null && this.textureCoordinates == null)
{
throw new ArgumentNullException("fanTextureCoordinates");
}

int index0 = this.positions.Count;
foreach (var p in fanPositions)
{
}

if (this.textureCoordinates != null && fanTextureCoordinates != null)
{
foreach (var tc in fanTextureCoordinates)
{
}
}

if (this.normals != null && fanNormals != null)
{
foreach (var n in fanNormals)
{
}
}

int indexEnd = this.positions.Count;
for (int i = index0; i + 2 < indexEnd; i += 3)
{