Client.network.getCurrentSim().Caps.CapabilityURI("GetMesh") != null)
{
// Do we have this mesh asset in the cache?
if (Client.assets.Cache.hasAsset(meshID))
{
callback.execute(new MeshDownloadCallbackArgs(true, new AssetMesh(meshID, Client.assets.Cache.getCachedAssetBytes(meshID))));
return;
}
URI url = Client.network.getCurrentSim().Caps.CapabilityURI("GetMesh");
MethodDelegate<Void,HttpBaseRequestCompletedArg> downloadCompletedCallback = new MethodDelegate<Void,HttpBaseRequestCompletedArg>()
{
public Void execute(HttpBaseRequestCompletedArg e) {
// HttpRequestBase request = e.getRequest();
// HttpResponse response = e.getResponse();
byte[] responseData = e.getResponseData();
Exception error = e.getError();
if (error == null && responseData != null) // success
{
callback.execute(new MeshDownloadCallbackArgs(true, new AssetMesh(meshID, responseData)));
Client.assets.Cache.saveAssetToCache(meshID, responseData);
}
else // download failed
{
JLogger.warn(
String.format("Failed to fetch mesh asset %s: %s",
meshID,
(error == null) ? "" :Utils.getExceptionStackTraceAsString(error)
));
}
return null;
}
};
DownloadRequest req = new DownloadRequest(
new URI(String.format("%s/?mesh_id=%s", url.toString(), meshID.toString())),
Client.settings.CAPS_TIMEOUT,
null,
null,
downloadCompletedCallback
);
HttpDownloads.QueueDownlad(req);
}
else
{
JLogger.error("GetMesh capability not available");
callback.execute(new MeshDownloadCallbackArgs(false, null));
}
}