Modified Mesh object to allow alternative mesher interfacing

0.6.0-stable
Dahlia Trimble 2008-08-27 06:29:34 +00:00
parent 363989195a
commit fce83731ad
1 changed files with 59 additions and 15 deletions

View File

@ -39,6 +39,7 @@ namespace OpenSim.Region.Physics.Meshing
public List<Triangle> triangles;
GCHandle pinnedVirtexes;
GCHandle pinnedIndex;
public PrimMesh primMesh = null;
//public float[] normals;
public Mesh()
@ -155,7 +156,11 @@ namespace OpenSim.Region.Physics.Meshing
public float[] getVertexListAsFloatLocked()
{
float[] result = new float[vertices.Count*3];
float[] result;
if (primMesh == null)
{
result = new float[vertices.Count * 3];
for (int i = 0; i < vertices.Count; i++)
{
Vertex v = vertices[i];
@ -166,12 +171,33 @@ namespace OpenSim.Region.Physics.Meshing
result[3 * i + 2] = v.Z;
}
pinnedVirtexes = GCHandle.Alloc(result, GCHandleType.Pinned);
}
else
{
int count = primMesh.coords.Count;
result = new float[count * 3];
for (int i = 0; i < count; i++)
{
Coord c = primMesh.coords[i];
int resultIndex = 3 * i;
result[resultIndex++] = c.X;
result[resultIndex++] = c.Y;
result[resultIndex] = c.Z;
}
primMesh.coords = null;
pinnedVirtexes = GCHandle.Alloc(result, GCHandleType.Pinned);
}
return result;
}
public int[] getIndexListAsInt()
{
int[] result = new int[triangles.Count*3];
int[] result;
if (primMesh == null)
{
result = new int[triangles.Count * 3];
for (int i = 0; i < triangles.Count; i++)
{
Triangle t = triangles[i];
@ -179,6 +205,21 @@ namespace OpenSim.Region.Physics.Meshing
result[3 * i + 1] = vertices.IndexOf(t.v2);
result[3 * i + 2] = vertices.IndexOf(t.v3);
}
}
else
{
int numFaces = primMesh.faces.Count;
result = new int[numFaces * 3];
for (int i = 0; i < numFaces; i++)
{
Face f = primMesh.faces[i];
int resultIndex = i * 3;
result[resultIndex++] = f.v1;
result[resultIndex++] = f.v2;
result[resultIndex] = f.v3;
}
primMesh.faces = null;
}
return result;
}
@ -186,6 +227,9 @@ namespace OpenSim.Region.Physics.Meshing
{
int[] result = getIndexListAsInt();
pinnedIndex = GCHandle.Alloc(result, GCHandleType.Pinned);
//triangles = null;
//vertices = null;
//primMesh = null;
return result;
}