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; public List<Triangle> triangles;
GCHandle pinnedVirtexes; GCHandle pinnedVirtexes;
GCHandle pinnedIndex; GCHandle pinnedIndex;
public PrimMesh primMesh = null;
//public float[] normals; //public float[] normals;
public Mesh() public Mesh()
@ -155,29 +156,69 @@ namespace OpenSim.Region.Physics.Meshing
public float[] getVertexListAsFloatLocked() public float[] getVertexListAsFloatLocked()
{ {
float[] result = new float[vertices.Count*3]; float[] result;
for (int i = 0; i < vertices.Count; i++)
if (primMesh == null)
{ {
Vertex v = vertices[i]; result = new float[vertices.Count * 3];
if (v == null) for (int i = 0; i < vertices.Count; i++)
continue; {
result[3*i + 0] = v.X; Vertex v = vertices[i];
result[3*i + 1] = v.Y; if (v == null)
result[3*i + 2] = v.Z; continue;
result[3 * i + 0] = v.X;
result[3 * i + 1] = v.Y;
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);
} }
pinnedVirtexes = GCHandle.Alloc(result, GCHandleType.Pinned);
return result; return result;
} }
public int[] getIndexListAsInt() public int[] getIndexListAsInt()
{ {
int[] result = new int[triangles.Count*3]; int[] result;
for (int i = 0; i < triangles.Count; i++)
if (primMesh == null)
{ {
Triangle t = triangles[i]; result = new int[triangles.Count * 3];
result[3*i + 0] = vertices.IndexOf(t.v1); for (int i = 0; i < triangles.Count; i++)
result[3*i + 1] = vertices.IndexOf(t.v2); {
result[3*i + 2] = vertices.IndexOf(t.v3); Triangle t = triangles[i];
result[3 * i + 0] = vertices.IndexOf(t.v1);
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; return result;
} }
@ -186,6 +227,9 @@ namespace OpenSim.Region.Physics.Meshing
{ {
int[] result = getIndexListAsInt(); int[] result = getIndexListAsInt();
pinnedIndex = GCHandle.Alloc(result, GCHandleType.Pinned); pinnedIndex = GCHandle.Alloc(result, GCHandleType.Pinned);
//triangles = null;
//vertices = null;
//primMesh = null;
return result; return result;
} }