Initial work.

This commit is contained in:
Drake Arconis
2013-01-06 03:59:38 -05:00
parent cadf654fae
commit 9c1237ca05
14 changed files with 285 additions and 149 deletions

View File

@@ -65,6 +65,8 @@
#include "llinventorymodel.h"
#include "llfoldertype.h"
#include "llviewerparcelmgr.h"
#include "llassetuploadresponders.h"
#include "lluploadfloaterobservers.h"
#include "aicurl.h"
#include "boost/lexical_cast.hpp"
@@ -316,7 +318,6 @@ public:
virtual AIHTTPTimeoutPolicy const& getHTTPTimeoutPolicy(void) const { return meshPhysicsShapeResponder_timeout; }
};
#if MESH_IMPORT
void log_upload_error(S32 status, const LLSD& content, std::string stage, std::string model_name)
{
// Add notification popup.
@@ -377,7 +378,20 @@ public:
mModelData(model_data),
mObserverHandle(observer_handle)
{
if (mThread)
{
mThread->startRequest();
}
}
~LLWholeModelFeeResponder()
{
if (mThread)
{
mThread->stopRequest();
}
}
virtual void completed(U32 status,
const std::string& reason,
const LLSD& content)
@@ -388,12 +402,11 @@ public:
cc = llsd_from_file("fake_upload_error.xml");
}
mThread->mPendingUploads--;
dump_llsd_to_file(cc,make_dump_name("whole_model_fee_response_",dump_num));
LLWholeModelFeeObserver* observer = mObserverHandle.get();
if (isGoodStatus(status) &&
if (((200 <= status) && (status < 300)) &&
cc["state"].asString() == "upload")
{
mThread->mWholeModelUploadURL = cc["uploader"].asString();
@@ -432,7 +445,20 @@ public:
mModelData(model_data),
mObserverHandle(observer_handle)
{
if (mThread)
{
mThread->startRequest();
}
}
~LLWholeModelUploadResponder()
{
if (mThread)
{
mThread->stopRequest();
}
}
virtual void completed(U32 status,
const std::string& reason,
const LLSD& content)
@@ -443,15 +469,13 @@ public:
cc = llsd_from_file("fake_upload_error.xml");
}
//assert_main_thread();
mThread->mPendingUploads--;
dump_llsd_to_file(cc,make_dump_name("whole_model_upload_response_",dump_num));
LLWholeModelUploadObserver* observer = mObserverHandle.get();
// requested "mesh" asset type isn't actually the type
// of the resultant object, fix it up here.
if (isGoodStatus(status) &&
if (((200 <= status) && (status < 300)) &&
cc["state"].asString() == "complete")
{
mModelData["asset_type"] = "object";
@@ -477,7 +501,6 @@ public:
virtual AIHTTPTimeoutPolicy const& getHTTPTimeoutPolicy(void) const { return wholeModelUploadResponder_timeout; }
};
#endif //MESH_IMPORT
LLMeshRepoThread::LLMeshRepoThread()
: LLThread("mesh repo")
@@ -499,18 +522,15 @@ LLMeshRepoThread::~LLMeshRepoThread()
void LLMeshRepoThread::run()
{
#if MESH_IMPORT
LLCDResult res = LLConvexDecomposition::initThread();
if (res != LLCD_OK)
{
llwarns << "convex decomposition unable to be loaded" << llendl;
}
#endif //MESH_IMPORT
mSignal->lock();
while (!LLApp::isQuitting())
{
// Left braces in order not to change the indentation.
{
static U32 count = 0;
@@ -646,13 +666,12 @@ void LLMeshRepoThread::run()
}
mSignal->unlock();
#if MESH_IMPORT
res = LLConvexDecomposition::quitThread();
if (res != LLCD_OK)
{
llwarns << "convex decomposition unable to be quit" << llendl;
}
#endif //MESH_IMPORT
}
void LLMeshRepoThread::loadMeshSkinInfo(const LLUUID& mesh_id)
@@ -1111,13 +1130,12 @@ bool LLMeshRepoThread::headerReceived(const LLVolumeParams& mesh_params, U8* dat
}
LLMutexLock lock(mMutex); // <FS:ND/> FIRE-7182, make sure only one thread access mPendingLOD at the same time.
LLMutexLock lock(mMutex); // make sure only one thread access mPendingLOD at the same time.
//check for pending requests
pending_lod_map::iterator iter = mPendingLOD.find(mesh_params);
if (iter != mPendingLOD.end())
{
// LLMutexLock lock(mMutex); <FS:ND/> FIRE-7182, lock was moved up, before calling mPendingLOD.find
for (U32 i = 0; i < iter->second.size(); ++i)
{
LODRequest req(mesh_params, iter->second[i]);
@@ -1266,7 +1284,6 @@ bool LLMeshRepoThread::physicsShapeReceived(const LLUUID& mesh_id, U8* data, S32
return true;
}
#if MESH_IMPORT
LLMeshUploadThread::LLMeshUploadThread(LLMeshUploadThread::instance_list& data, LLVector3& scale, bool upload_textures,
bool upload_skin, bool upload_joints, std::string upload_url, bool do_upload,
LLHandle<LLWholeModelFeeObserver> fee_observer, LLHandle<LLWholeModelUploadObserver> upload_observer)
@@ -1358,7 +1375,6 @@ void LLMeshUploadThread::run()
requestWholeModelFee();
}
}
#endif //MESH_IMPORT
void dump_llsd_to_file(const LLSD& content, std::string filename)
{
@@ -1377,7 +1393,6 @@ LLSD llsd_from_file(std::string filename)
return result;
}
#if MESH_IMPORT
void LLMeshUploadThread::wholeModelToLLSD(LLSD& dest, bool include_textures)
{
LLSD result;
@@ -1433,22 +1448,22 @@ void LLMeshUploadThread::wholeModelToLLSD(LLSD& dest, bool include_textures)
std::stringstream ostr;
LLModel::Decomposition& decomp =
data.mModel[LLModel::LOD_PHYSICS].notNull() ?
data.mModel[LLModel::LOD_PHYSICS]->mPhysics :
data.mBaseModel->mPhysics;
data.mModel[LLModel::LOD_PHYSICS].notNull() ?
data.mModel[LLModel::LOD_PHYSICS]->mPhysics :
data.mBaseModel->mPhysics;
decomp.mBaseHull = mHullMap[data.mBaseModel];
decomp.mBaseHull = mHullMap[data.mBaseModel];
LLSD mesh_header = LLModel::writeModel(
ostr,
data.mModel[LLModel::LOD_PHYSICS],
data.mModel[LLModel::LOD_HIGH],
data.mModel[LLModel::LOD_MEDIUM],
data.mModel[LLModel::LOD_LOW],
data.mModel[LLModel::LOD_IMPOSTOR],
decomp,
mUploadSkin,
mUploadJoints);
LLSD mesh_header = LLModel::writeModel(
ostr,
data.mModel[LLModel::LOD_PHYSICS],
data.mModel[LLModel::LOD_HIGH],
data.mModel[LLModel::LOD_MEDIUM],
data.mModel[LLModel::LOD_LOW],
data.mModel[LLModel::LOD_IMPOSTOR],
decomp,
mUploadSkin,
mUploadJoints);
data.mAssetData = ostr.str();
std::string str = ostr.str();
@@ -1588,7 +1603,7 @@ void LLMeshUploadThread::generateHulls()
}
llassert(physics != NULL);
DecompRequest* request = new DecompRequest(physics, data.mBaseModel, this);
if(request->isValid())
{
@@ -1635,12 +1650,10 @@ void LLMeshUploadThread::requestWholeModelFee()
wholeModelToLLSD(model_data,false);
dump_llsd_to_file(model_data,make_dump_name("whole_model_fee_request_",dump_num));
mPendingUploads++;
// This might throw AICurlNoEasyHandle.
LLHTTPClient::post(mWholeModelFeeCapability, model_data,
new LLWholeModelFeeResponder(this, model_data, mFeeObserverHandle));
}
#endif //MESH_IMPORT
void LLMeshRepoThread::notifyLoadedMeshes()
{//called via gMeshRepo.notifyLoadedMeshes(). mMutex already locked
@@ -1658,7 +1671,7 @@ void LLMeshRepoThread::notifyLoadedMeshes()
else
{
gMeshRepo.notifyMeshUnavailable(mesh.mMeshParams,
LLVolumeLODGroup::getVolumeDetailFromScale(mesh.mVolume->getDetail()));
LLVolumeLODGroup::getVolumeDetailFromScale(mesh.mVolume->getDetail()));
}
}
@@ -1740,7 +1753,6 @@ S32 LLMeshRepository::getActualMeshLOD(LLSD& header, S32 lod)
return -1;
}
#if MESH_IMPORT
void LLMeshRepository::cacheOutgoingMesh(LLMeshUploadData& data, LLSD& header)
{
mThread->mMeshHeader[data.mUUID] = header;
@@ -1761,7 +1773,6 @@ void LLMeshRepository::cacheOutgoingMesh(LLMeshUploadData& data, LLSD& header)
}
}
#endif //MESH_IMPORT
void LLMeshLODResponder::completedRaw(U32 status, const std::string& reason,
const LLChannelDescriptors& channels,
@@ -2099,9 +2110,7 @@ void LLMeshRepository::init()
{
mMeshMutex = new LLMutex();
#if MESH_IMPORT
LLConvexDecomposition::getInstance()->initSystem();
#endif //MESH_IMPORT
mDecompThread = new LLPhysicsDecomp();
mDecompThread->start();
@@ -2121,13 +2130,11 @@ void LLMeshRepository::shutdown()
{
llinfos << "Shutting down mesh repository." << llendl;
#if MESH_IMPORT
for (U32 i = 0; i < mUploads.size(); ++i)
{
llinfos << "Discard the pending mesh uploads " << llendl;
mUploads[i]->discard() ; //discard the uploading requests.
}
#endif //MESH_IMPORT
mThread->mSignal->signal();
@@ -2138,7 +2145,6 @@ void LLMeshRepository::shutdown()
delete mThread;
mThread = NULL;
#if MESH_IMPORT
for (U32 i = 0; i < mUploads.size(); ++i)
{
llinfos << "Waiting for pending mesh upload " << i << "/" << mUploads.size() << llendl;
@@ -2150,7 +2156,6 @@ void LLMeshRepository::shutdown()
}
mUploads.clear();
#endif //MESH_IMPORT
delete mMeshMutex;
mMeshMutex = NULL;
@@ -2164,16 +2169,13 @@ void LLMeshRepository::shutdown()
mDecompThread = NULL;
}
#if MESH_IMPORT
LLConvexDecomposition::quitSystem();
#endif //MESH_IMPORT
}
//called in the main thread.
S32 LLMeshRepository::update()
{
S32 size = 0;
#if MESH_IMPORT
if(mUploadWaitList.empty())
{
return 0 ;
@@ -2187,7 +2189,7 @@ S32 LLMeshRepository::update()
mUploadWaitList[i]->start() ;
}
mUploadWaitList.clear() ;
#endif //MESH_IMPORT
return size ;
}
@@ -2274,13 +2276,12 @@ void LLMeshRepository::notifyLoadedMeshes()
static const LLCachedControl<U32> max_concurrent_requests("MeshMaxConcurrentRequests");
LLMeshRepoThread::sMaxConcurrentRequests = max_concurrent_requests;
#if MESH_IMPORT
//clean up completed upload threads
for (std::vector<LLMeshUploadThread*>::iterator iter = mUploads.begin(); iter != mUploads.end(); )
{
LLMeshUploadThread* thread = *iter;
if (thread->isStopped() && thread->finished())
if (thread->isStopped())
{
iter = mUploads.erase(iter);
delete thread;
@@ -2347,7 +2348,7 @@ void LLMeshRepository::notifyLoadedMeshes()
mInventoryQ.pop();
}
#endif //MESH_IMPORT
}
//call completed callbacks on finished decompositions
mDecompThread->notifyCompleted();
@@ -2710,7 +2711,7 @@ LLSD& LLMeshRepoThread::getMeshHeader(const LLUUID& mesh_id)
return dummy_ret;
}
#if MESH_IMPORT
void LLMeshRepository::uploadModel(std::vector<LLModelInstance>& data, LLVector3& scale, bool upload_textures,
bool upload_skin, bool upload_joints, std::string upload_url, bool do_upload,
LLHandle<LLWholeModelFeeObserver> fee_observer, LLHandle<LLWholeModelUploadObserver> upload_observer)
@@ -2719,7 +2720,6 @@ void LLMeshRepository::uploadModel(std::vector<LLModelInstance>& data, LLVector3
do_upload, fee_observer, upload_observer);
mUploadWaitList.push_back(thread);
}
#endif //MESH_IMPORT
S32 LLMeshRepository::getMeshSize(const LLUUID& mesh_id, S32 lod)
{
@@ -2745,8 +2745,6 @@ S32 LLMeshRepository::getMeshSize(const LLUUID& mesh_id, S32 lod)
}
#if MESH_IMPORT
void LLMeshUploadThread::decomposeMeshMatrix(LLMatrix4& transformation,
LLVector3& result_pos,
LLQuaternion& result_rot,
@@ -2787,8 +2785,6 @@ void LLMeshUploadThread::decomposeMeshMatrix(LLMatrix4& transformation,
result_rot = quat_rotation;
}
#endif //MESH_IMPORT
bool LLImportMaterial::operator<(const LLImportMaterial &rhs) const
{
if (mDiffuseMap != rhs.mDiffuseMap)
@@ -2991,8 +2987,41 @@ S32 LLPhysicsDecomp::llcdCallback(const char* status, S32 p1, S32 p2)
return 1;
}
bool needTriangles( LLConvexDecomposition *aDC )
{
if( !aDC )
return false;
LLCDParam const *pParams(0);
int nParams = aDC->getParameters( &pParams );
if( nParams <= 0 )
return false;
for( int i = 0; i < nParams; ++i )
{
if( pParams[i].mName && strcmp( "nd_AlwaysNeedTriangles", pParams[i].mName ) == 0 )
{
if( LLCDParam::LLCD_BOOLEAN == pParams[i].mType && pParams[i].mDefault.mBool )
return true;
else
return false;
}
}
return false;
}
void LLPhysicsDecomp::setMeshData(LLCDMeshData& mesh, bool vertex_based)
{
LLConvexDecomposition *pDeComp = LLConvexDecomposition::getInstance();
if( !pDeComp )
return;
if( vertex_based )
vertex_based = !needTriangles( pDeComp );
mesh.mVertexBase = mCurRequest->mPositions[0].mV;
mesh.mVertexStrideBytes = 12;
mesh.mNumVertices = mCurRequest->mPositions.size();
@@ -3006,26 +3035,20 @@ void LLPhysicsDecomp::setMeshData(LLCDMeshData& mesh, bool vertex_based)
mesh.mNumTriangles = mCurRequest->mIndices.size()/3;
}
#if MESH_IMPORT
if ((vertex_based || mesh.mNumTriangles > 0) && mesh.mNumVertices > 2)
{
LLCDResult ret = LLCD_OK;
if (LLConvexDecomposition::getInstance() != NULL)
{
ret = LLConvexDecomposition::getInstance()->setMeshData(&mesh, vertex_based);
}
ret = LLConvexDecomposition::getInstance()->setMeshData(&mesh, vertex_based);
if (ret)
{
llerrs << "Convex Decomposition thread valid but could not set mesh data" << llendl;
}
}
#endif //MESH_IMPORT
}
void LLPhysicsDecomp::doDecomposition()
{
#if MESH_IMPORT
LLCDMeshData mesh;
S32 stage = mStageID[mCurRequest->mStage];
@@ -3160,7 +3183,6 @@ void LLPhysicsDecomp::doDecomposition()
completeCurrent();
}
}
#endif //MESH_IMPORT
}
void LLPhysicsDecomp::completeCurrent()
@@ -3214,10 +3236,6 @@ void make_box(LLPhysicsDecomp::Request * request)
void LLPhysicsDecomp::doDecompositionSingleHull()
{
#if !MESH_IMPORT
return;
#endif //!MESH_IMPORT
#if MESH_IMPORT
LLConvexDecomposition* decomp = LLConvexDecomposition::getInstance();
if (decomp == NULL)
@@ -3238,11 +3256,12 @@ void LLPhysicsDecomp::doDecompositionSingleHull()
}
else
{
mMutex->lock();
mCurRequest->mHull.clear();
mCurRequest->mHull.resize(1);
mCurRequest->mHullMesh.clear();
mMutex->unlock();
{
LLMutexLock lock(mMutex);
mCurRequest->mHull.clear();
mCurRequest->mHull.resize(1);
mCurRequest->mHullMesh.clear();
}
std::vector<LLVector3> p;
LLCDHull hull;
@@ -3258,26 +3277,73 @@ void LLPhysicsDecomp::doDecompositionSingleHull()
p.push_back(vert);
v = (F32*) (((U8*) v) + hull.mVertexStrideBytes);
}
mMutex->lock();
mCurRequest->mHull[0] = p;
mMutex->unlock();
{
LLMutexLock lock(mMutex);
mCurRequest->mHull[0] = p;
}
}
{
completeCurrent();
}
#endif //MESH_IMPORT
}
#ifdef ND_HASCONVEXDECOMP_TRACER
class ndDecompTracer: public ndConvexDecompositionTracer
{
int mRefCount;
public:
ndDecompTracer()
: mRefCount(0)
{
}
virtual void trace( char const *a_strMsg )
{
llinfos << a_strMsg << llendl;
}
virtual void startTraceData( char const *a_strWhat)
{
llinfos << a_strWhat << llendl;
}
virtual void traceData( char const *a_strData )
{
llinfos << a_strData << llendl;
}
virtual void endTraceData()
{
}
virtual int getLevel()
{
return eTraceFunctions;// | eTraceData;
}
virtual void addref()
{
++mRefCount;
}
virtual void release()
{
--mRefCount;
if( mRefCount == 0 )
delete this;
}
};
#endif
void LLPhysicsDecomp::run()
{
#if !MESH_IMPORT
mInited = true;
#endif //!MESH_IMPORT
#if MESH_IMPORT
LLConvexDecomposition* decomp = LLConvexDecomposition::getInstance();
if (decomp == NULL)
{
@@ -3287,6 +3353,13 @@ void LLPhysicsDecomp::run()
return;
}
#ifdef ND_HASCONVEXDECOMP_TRACER
ndConvexDecompositionTracable *pTraceable = dynamic_cast< ndConvexDecompositionTracable* >( decomp );
if( pTraceable )
pTraceable->setTracer( new ndDecompTracer() );
#endif
decomp->initThread();
mInited = true;
@@ -3304,6 +3377,7 @@ void LLPhysicsDecomp::run()
}
mSignal->lock();
while (!mQuitting)
{
mSignal->wait();
@@ -3332,14 +3406,14 @@ void LLPhysicsDecomp::run()
}
}
}
mSignal->unlock();
decomp->quitThread();
mDone = true;
#endif //MESH_IMPORT
}
mDone = true;
}
void LLPhysicsDecomp::Request::assignData(LLModel* mdl)
{
@@ -3486,7 +3560,6 @@ void LLMeshRepository::buildPhysicsMesh(LLModel::Decomposition& decomp)
hull.mVertexBase = decomp.mHull[i][0].mV;
hull.mVertexStrideBytes = 12;
#if MESH_IMPORT
LLCDMeshData mesh;
LLCDResult res = LLCD_OK;
if (LLConvexDecomposition::getInstance() != NULL)
@@ -3497,7 +3570,6 @@ void LLMeshRepository::buildPhysicsMesh(LLModel::Decomposition& decomp)
{
get_vertex_buffer_from_mesh(mesh, decomp.mMesh[i]);
}
#endif //MESH_IMPORT
}
if (!decomp.mBaseHull.empty() && decomp.mBaseHullMesh.empty())
@@ -3507,7 +3579,6 @@ void LLMeshRepository::buildPhysicsMesh(LLModel::Decomposition& decomp)
hull.mVertexBase = decomp.mBaseHull[0].mV;
hull.mVertexStrideBytes = 12;
#if MESH_IMPORT
LLCDMeshData mesh;
LLCDResult res = LLCD_OK;
if (LLConvexDecomposition::getInstance() != NULL)
@@ -3518,7 +3589,6 @@ void LLMeshRepository::buildPhysicsMesh(LLModel::Decomposition& decomp)
{
get_vertex_buffer_from_mesh(mesh, decomp.mBaseHullMesh);
}
#endif //MESH_IMPORT
}
}