diff options
Diffstat (limited to 'indra/newview/llmeshrepository.cpp')
-rwxr-xr-x | indra/newview/llmeshrepository.cpp | 273 |
1 files changed, 80 insertions, 193 deletions
diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp index f5fc0de0d3..752e4c8744 100755 --- a/indra/newview/llmeshrepository.cpp +++ b/indra/newview/llmeshrepository.cpp @@ -108,19 +108,13 @@ U32 get_volume_memory_size(const LLVolume* volume) return indices*2+vertices*11+sizeof(LLVolume)+sizeof(LLVolumeFace)*volume->getNumVolumeFaces(); } -LLVertexBuffer* get_vertex_buffer_from_mesh(LLCDMeshData& mesh, F32 scale = 1.f) +void get_vertex_buffer_from_mesh(LLCDMeshData& mesh, LLModel::PhysicsMesh& res, F32 scale = 1.f) { - LLVertexBuffer* buff = new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL, 0); - buff->allocateBuffer(mesh.mNumTriangles*3, 0, true); - - LLStrider<LLVector3> pos; - LLStrider<LLVector3> norm; + res.mPositions.clear(); + res.mNormals.clear(); - buff->getVertexStrider(pos); - buff->getNormalStrider(norm); - const F32* v = mesh.mVertexBase; - + if (mesh.mIndexType == LLCDMeshData::INT_16) { U16* idx = (U16*) mesh.mIndexBase; @@ -139,13 +133,13 @@ LLVertexBuffer* get_vertex_buffer_from_mesh(LLCDMeshData& mesh, F32 scale = 1.f) LLVector3 n = (v1-v0)%(v2-v0); n.normalize(); - *pos++ = v0*scale; - *pos++ = v1*scale; - *pos++ = v2*scale; + res.mPositions.push_back(v0*scale); + res.mPositions.push_back(v1*scale); + res.mPositions.push_back(v2*scale); - *norm++ = n; - *norm++ = n; - *norm++ = n; + res.mNormals.push_back(n); + res.mNormals.push_back(n); + res.mNormals.push_back(n); } } else @@ -166,17 +160,15 @@ LLVertexBuffer* get_vertex_buffer_from_mesh(LLCDMeshData& mesh, F32 scale = 1.f) LLVector3 n = (v1-v0)%(v2-v0); n.normalize(); - *(pos++) = v0*scale; - *(pos++) = v1*scale; - *(pos++) = v2*scale; + res.mPositions.push_back(v0*scale); + res.mPositions.push_back(v1*scale); + res.mPositions.push_back(v2*scale); - *(norm++) = n; - *(norm++) = n; - *(norm++) = n; + res.mNormals.push_back(n); + res.mNormals.push_back(n); + res.mNormals.push_back(n); } } - - return buff; } S32 LLMeshRepoThread::sActiveHeaderRequests = 0; @@ -1139,119 +1131,8 @@ bool LLMeshRepoThread::decompositionReceived(const LLUUID& mesh_id, U8* data, S3 } { - LLMeshDecomposition* d = new LLMeshDecomposition(); + LLModel::Decomposition* d = new LLModel::Decomposition(decomp); d->mMeshID = mesh_id; - - if (decomp.has("HullList")) - { - // updated for const-correctness. gcc is picky about this type of thing - Nyx - const LLSD::Binary& hulls = decomp["HullList"].asBinary(); - const LLSD::Binary& position = decomp["Position"].asBinary(); - - U16* p = (U16*) &position[0]; - - d->mHull.resize(hulls.size()); - - LLVector3 min; - LLVector3 max; - LLVector3 range; - - min.setValue(decomp["Min"]); - max.setValue(decomp["Max"]); - range = max-min; - - for (U32 i = 0; i < hulls.size(); ++i) - { - U16 count = (hulls[i] == 0) ? 256 : hulls[i]; - - for (U32 j = 0; j < count; ++j) - { - d->mHull[i].push_back(LLVector3( - (F32) p[0]/65535.f*range.mV[0]+min.mV[0], - (F32) p[1]/65535.f*range.mV[1]+min.mV[1], - (F32) p[2]/65535.f*range.mV[2]+min.mV[2])); - p += 3; - } - - } - - //get mesh for decomposition - for (U32 i = 0; i < d->mHull.size(); ++i) - { - LLCDHull hull; - hull.mNumVertices = d->mHull[i].size(); - hull.mVertexBase = d->mHull[i][0].mV; - hull.mVertexStrideBytes = 12; - - LLCDMeshData mesh; - LLCDResult res = LLCD_OK; - if (LLConvexDecomposition::getInstance() != NULL) - { - res = LLConvexDecomposition::getInstance()->getMeshFromHull(&hull, &mesh); - } - if (res != LLCD_OK) - { - llwarns << "could not get mesh from hull from convex decomposition lib." << llendl; - return false; - } - - - d->mMesh.push_back(get_vertex_buffer_from_mesh(mesh)); - } - } - - if (decomp.has("Hull")) - { - const LLSD::Binary& position = decomp["Hull"].asBinary(); - - U16* p = (U16*) &position[0]; - - LLVector3 min; - LLVector3 max; - LLVector3 range; - - min.setValue(decomp["Min"]); - max.setValue(decomp["Max"]); - range = max-min; - - U16 count = position.size()/6; - - for (U32 j = 0; j < count; ++j) - { - d->mBaseHull.push_back(LLVector3( - (F32) p[0]/65535.f*range.mV[0]+min.mV[0], - (F32) p[1]/65535.f*range.mV[1]+min.mV[1], - (F32) p[2]/65535.f*range.mV[2]+min.mV[2])); - p += 3; - } - - //get mesh for decomposition - LLCDHull hull; - hull.mNumVertices = d->mBaseHull.size(); - hull.mVertexBase = d->mBaseHull[0].mV; - hull.mVertexStrideBytes = 12; - - LLCDMeshData mesh; - LLCDResult res = LLCD_OK; - if (LLConvexDecomposition::getInstance() != NULL) - { - res = LLConvexDecomposition::getInstance()->getMeshFromHull(&hull, &mesh); - } - if (res != LLCD_OK) - { - llwarns << "could not get mesh from hull from convex decomposition lib." << llendl; - return false; - } - - d->mBaseHullMesh = get_vertex_buffer_from_mesh(mesh); - } - else - { - //empty vertex buffer to indicate decomposition has been fetched - //but contains no base hull - d->mBaseHullMesh = new LLVertexBuffer(0, 0); - } - mDecompositionQ.push(d); } @@ -1262,12 +1143,12 @@ bool LLMeshRepoThread::physicsShapeReceived(const LLUUID& mesh_id, U8* data, S32 { LLSD physics_shape; - LLMeshDecomposition* d = new LLMeshDecomposition(); + LLModel::Decomposition* d = new LLModel::Decomposition(); d->mMeshID = mesh_id; if (data == NULL) { //no data, no physics shape exists - d->mPhysicsShapeMesh = new LLVertexBuffer(0,0); + d->mPhysicsShapeMesh.clear(); } else { @@ -1291,33 +1172,22 @@ bool LLMeshRepoThread::physicsShapeReceived(const LLUUID& mesh_id, U8* data, S32 index_count += face.mNumIndices; } - d->mPhysicsShapeMesh = new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX, 0); - - d->mPhysicsShapeMesh->allocateBuffer(vertex_count, index_count, true); + d->mPhysicsShapeMesh.clear(); - LLStrider<LLVector3> pos; - LLStrider<U16> idx; + std::vector<LLVector3>& pos = d->mPhysicsShapeMesh.mPositions; + std::vector<LLVector3>& norm = d->mPhysicsShapeMesh.mNormals; - d->mPhysicsShapeMesh->getVertexStrider(pos); - d->mPhysicsShapeMesh->getIndexStrider(idx); - - S32 idx_offset = 0; for (S32 i = 0; i < volume->getNumVolumeFaces(); ++i) { const LLVolumeFace& face = volume->getVolumeFace(i); - if (idx_offset + face.mNumIndices > 65535) - { //avoid 16-bit index overflow - continue; - } - - LLVector4a::memcpyNonAliased16(pos[idx_offset].mV, face.mPositions[0].getF32ptr(), face.mNumVertices*sizeof(LLVector4a)); for (S32 i = 0; i < face.mNumIndices; ++i) { - *idx++ = face.mIndices[i] + idx_offset; - } + U16 idx = face.mIndices[i]; - idx_offset += face.mNumVertices; + pos.push_back(LLVector3(face.mPositions[idx].getF32ptr())); + norm.push_back(LLVector3(face.mNormals[idx].getF32ptr())); + } } } } @@ -2428,33 +2298,7 @@ void LLMeshRepository::notifySkinInfoReceived(LLMeshSkinInfo& info) mLoadingSkins.erase(info.mMeshID); } -void LLMeshDecomposition::merge(const LLMeshDecomposition* rhs) -{ - if (!rhs) - { - return; - } - - if (mMeshID != rhs->mMeshID) - { - llerrs << "Attempted to merge with decomposition of some other mesh." << llendl; - } - - if (mBaseHull.empty()) - { //take base hull and decomposition from rhs - mHull = rhs->mHull; - mBaseHull = rhs->mBaseHull; - mMesh = rhs->mMesh; - mBaseHullMesh = rhs->mBaseHullMesh; - } - - if (mPhysicsShapeMesh.isNull()) - { //take physics shape mesh from rhs - mPhysicsShapeMesh = rhs->mPhysicsShapeMesh; - } -} - -void LLMeshRepository::notifyDecompositionReceived(LLMeshDecomposition* decomp) +void LLMeshRepository::notifyDecompositionReceived(LLModel::Decomposition* decomp) { decomposition_map::iterator iter = mDecompositionMap.find(decomp->mMeshID); if (iter == mDecompositionMap.end()) @@ -2596,7 +2440,7 @@ void LLMeshRepository::fetchPhysicsShape(const LLUUID& mesh_id) { if (mesh_id.notNull()) { - LLMeshDecomposition* decomp = NULL; + LLModel::Decomposition* decomp = NULL; decomposition_map::iterator iter = mDecompositionMap.find(mesh_id); if (iter != mDecompositionMap.end()) { @@ -2604,7 +2448,7 @@ void LLMeshRepository::fetchPhysicsShape(const LLUUID& mesh_id) } //decomposition block hasn't been fetched yet - if (!decomp || decomp->mPhysicsShapeMesh.isNull()) + if (!decomp || decomp->mPhysicsShapeMesh.empty()) { LLMutexLock lock(mMeshMutex); //add volume to list of loading meshes @@ -2619,9 +2463,9 @@ void LLMeshRepository::fetchPhysicsShape(const LLUUID& mesh_id) } -const LLMeshDecomposition* LLMeshRepository::getDecomposition(const LLUUID& mesh_id) +LLModel::Decomposition* LLMeshRepository::getDecomposition(const LLUUID& mesh_id) { - LLMeshDecomposition* ret = NULL; + LLModel::Decomposition* ret = NULL; if (mesh_id.notNull()) { @@ -2632,7 +2476,7 @@ const LLMeshDecomposition* LLMeshRepository::getDecomposition(const LLUUID& mesh } //decomposition block hasn't been fetched yet - if (!ret || ret->mBaseHullMesh.isNull()) + if (!ret || ret->mBaseHullMesh.empty()) { LLMutexLock lock(mMeshMutex); //add volume to list of loading meshes @@ -2735,8 +2579,8 @@ void LLMeshUploadThread::sendCostRequest(LLMeshUploadData& data) LLModel::convex_hull_decomposition& decomp = data.mModel[LLModel::LOD_PHYSICS].notNull() ? - data.mModel[LLModel::LOD_PHYSICS]->mConvexHullDecomp : - data.mBaseModel->mConvexHullDecomp; + data.mModel[LLModel::LOD_PHYSICS]->mPhysics.mHull : + data.mBaseModel->mPhysics.mHull; LLModel::hull dummy_hull; @@ -2836,8 +2680,8 @@ void LLMeshUploadThread::doUploadModel(LLMeshUploadData& data) LLModel::convex_hull_decomposition& decomp = data.mModel[LLModel::LOD_PHYSICS].notNull() ? - data.mModel[LLModel::LOD_PHYSICS]->mConvexHullDecomp : - data.mBaseModel->mConvexHullDecomp; + data.mModel[LLModel::LOD_PHYSICS]->mPhysics.mHull : + data.mBaseModel->mPhysics.mHull; LLModel::writeModel( ostr, @@ -3355,7 +3199,7 @@ void LLPhysicsDecomp::doDecomposition() // if LLConvexDecomposition is a stub, num_hulls should have been set to 0 above, and we should not reach this code LLConvexDecomposition::getInstance()->getMeshFromStage(stage, i, &mesh); - mCurRequest->mHullMesh[i] = get_vertex_buffer_from_mesh(mesh); + get_vertex_buffer_from_mesh(mesh, mCurRequest->mHullMesh[i]); mMutex->lock(); mCurRequest->mHull[i] = p; @@ -3628,3 +3472,46 @@ LLSD LLImportMaterial::asLLSD() return ret; } + +void LLMeshRepository::buildPhysicsMesh(LLModel::Decomposition& decomp) +{ + decomp.mMesh.resize(decomp.mHull.size());
+
+ for (U32 i = 0; i < decomp.mHull.size(); ++i)
+ {
+ LLCDHull hull; + hull.mNumVertices = decomp.mHull[i].size(); + hull.mVertexBase = decomp.mHull[i][0].mV; + hull.mVertexStrideBytes = 12; + + LLCDMeshData mesh; + LLCDResult res = LLCD_OK; + if (LLConvexDecomposition::getInstance() != NULL) + { + res = LLConvexDecomposition::getInstance()->getMeshFromHull(&hull, &mesh); + } + if (res == LLCD_OK) + { + get_vertex_buffer_from_mesh(mesh, decomp.mMesh[i]);
+ }
+ } + + if (!decomp.mBaseHull.empty() && decomp.mBaseHullMesh.empty()) + { //get mesh for base hull + LLCDHull hull; + hull.mNumVertices = decomp.mBaseHull.size(); + hull.mVertexBase = decomp.mBaseHull[0].mV; + hull.mVertexStrideBytes = 12; + + LLCDMeshData mesh; + LLCDResult res = LLCD_OK; + if (LLConvexDecomposition::getInstance() != NULL) + { + res = LLConvexDecomposition::getInstance()->getMeshFromHull(&hull, &mesh); + } + if (res == LLCD_OK) + { + get_vertex_buffer_from_mesh(mesh, decomp.mBaseHullMesh); + } + } +} |