private GenericTask GenerateSculptOrMeshPrim(RenderPrimitive rprim, Primitive prim)
{
return new GenericTask(() =>
{
FacetedMesh mesh = null;
try
{
if (prim.Sculpt.Type != SculptType.Mesh)
{ // Regular sculptie
Image img = null;
lock (sculptCache)
{
if (sculptCache.ContainsKey(prim.Sculpt.SculptTexture))
{
img = sculptCache[prim.Sculpt.SculptTexture];
}
}
if (img == null)
{
if (LoadTexture(prim.Sculpt.SculptTexture, ref img, true))
{
sculptCache[prim.Sculpt.SculptTexture] = (Bitmap)img;
}
else
{
return;
}
}
mesh = renderer.GenerateFacetedSculptMesh(prim, (Bitmap)img, RenderSettings.SculptRenderDetail);
}
else
{ // Mesh
AutoResetEvent gotMesh = new AutoResetEvent(false);
Client.Assets.RequestMesh(prim.Sculpt.SculptTexture, (success, meshAsset) =>
{
if (!success || !FacetedMesh.TryDecodeFromAsset(prim, meshAsset, RenderSettings.MeshRenderDetail, out mesh))
{
Logger.Log("Failed to fetch or decode the mesh asset", Helpers.LogLevel.Warning, Client);
}
gotMesh.Set();
});
gotMesh.WaitOne(20 * 1000, false);
}
}
catch
{ }
if (mesh != null)
{
rprim.Faces = mesh.Faces;
CalculateBoundingBox(rprim);
rprim.Meshing = false;
rprim.Meshed = true;
}
else
{
lock (Prims)
{
Prims.Remove(rprim.BasePrim.LocalID);
}
}
});
}