Add level of detail specification to optionally reduce the number of vertices in generated prim meshes

Signed-off-by: BlueWall <jamesh@bluewallgroup.com>
bulletsim
Robert Adams 2011-08-26 21:26:26 -07:00 committed by BlueWall
parent 795b56e695
commit 80a2b81d52
2 changed files with 42 additions and 5 deletions

View File

@ -38,6 +38,17 @@ namespace OpenSim.Region.Physics.Manager
IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical);
}
// Values for level of detail to be passed to the mesher.
// Values origionally chosen for the LOD of sculpties (the sqrt(width*heigth) of sculpt texture)
// Lower level of detail reduces the number of vertices used to represent the meshed shape.
public enum LevelOfDetail
{
High = 32,
Medium = 16,
Low = 8,
VeryLow = 4
}
public interface IVertex
{
}

View File

@ -336,7 +336,7 @@ namespace OpenSim.Region.Physics.Meshing
}
else
{
if (!GenerateCoordsAndFacesFromPrimShapeData(primName, primShape, size, out coords, out faces))
if (!GenerateCoordsAndFacesFromPrimShapeData(primName, primShape, size, lod, out coords, out faces))
return null;
}
@ -616,7 +616,7 @@ namespace OpenSim.Region.Physics.Meshing
/// <param name="faces">Faces are added to this list by the method.</param>
/// <returns>true if coords and faces were successfully generated, false if not</returns>
private bool GenerateCoordsAndFacesFromPrimShapeData(
string primName, PrimitiveBaseShape primShape, Vector3 size, out List<Coord> coords, out List<Face> faces)
string primName, PrimitiveBaseShape primShape, Vector3 size, float lod, out List<Coord> coords, out List<Face> faces)
{
PrimMesh primMesh;
coords = new List<Coord>();
@ -636,13 +636,30 @@ namespace OpenSim.Region.Physics.Meshing
profileHollow = 0.95f;
int sides = 4;
LevelOfDetail iLOD = (LevelOfDetail)lod;
if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle)
sides = 3;
else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.Circle)
sides = 24;
{
switch (iLOD)
{
case LevelOfDetail.High: sides = 24; break;
case LevelOfDetail.Medium: sides = 12; break;
case LevelOfDetail.Low: sides = 6; break;
case LevelOfDetail.VeryLow: sides = 3; break;
default: sides = 24; break;
}
}
else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle)
{ // half circle, prim is a sphere
sides = 24;
switch (iLOD)
{
case LevelOfDetail.High: sides = 24; break;
case LevelOfDetail.Medium: sides = 12; break;
case LevelOfDetail.Low: sides = 6; break;
case LevelOfDetail.VeryLow: sides = 3; break;
default: sides = 24; break;
}
profileBegin = 0.5f * profileBegin + 0.5f;
profileEnd = 0.5f * profileEnd + 0.5f;
@ -650,7 +667,16 @@ namespace OpenSim.Region.Physics.Meshing
int hollowSides = sides;
if (primShape.HollowShape == HollowShape.Circle)
hollowSides = 24;
{
switch (iLOD)
{
case LevelOfDetail.High: hollowSides = 24; break;
case LevelOfDetail.Medium: hollowSides = 12; break;
case LevelOfDetail.Low: hollowSides = 6; break;
case LevelOfDetail.VeryLow: hollowSides = 3; break;
default: hollowSides = 24; break;
}
}
else if (primShape.HollowShape == HollowShape.Square)
hollowSides = 4;
else if (primShape.HollowShape == HollowShape.Triangle)