From c690c30ec173faf8d8087ecb38cadbb9dd1adb4e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 22 Feb 2011 18:33:33 -0600 Subject: SH-438 Use node name instead of mesh name for object names when importing meshes. --- indra/newview/llfloatermodelpreview.cpp | 187 +------------------------------- indra/newview/llfloatermodelpreview.h | 2 +- indra/newview/llmeshrepository.cpp | 2 +- indra/newview/llmeshrepository.h | 8 +- 4 files changed, 10 insertions(+), 189 deletions(-) diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp index dde470693c..cf7ac354b6 100755 --- a/indra/newview/llfloatermodelpreview.cpp +++ b/indra/newview/llfloatermodelpreview.cpp @@ -1653,7 +1653,7 @@ void LLModelLoader::run() std::vector materials; materials.resize(model->getNumVolumeFaces()); - mScene[transformation].push_back(LLModelInstance(model, transformation, materials)); + mScene[transformation].push_back(LLModelInstance(model, model->mLabel, transformation, materials)); stretch_extents(model, transformation, mExtents[0], mExtents[1], mFirstTransform); } } @@ -1944,7 +1944,8 @@ void LLModelLoader::processElement(daeElement* element) mesh_scale *= transformation; transformation = mesh_scale; - mScene[transformation].push_back(LLModelInstance(model, transformation, materials)); + std::string label = getElementLabel(instance_geo); + mScene[transformation].push_back(LLModelInstance(model, label, transformation, materials)); stretch_extents(model, transformation, mExtents[0], mExtents[1], mFirstTransform); } @@ -2615,188 +2616,6 @@ void LLModelPreview::generateNormals() } -void LLModelPreview::consolidate() -{ - std::map > composite; - - LLMatrix4 identity; - - //bake out each node in current scene to composite - for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter) - { //for each transform in current scene - LLMatrix4 mat = iter->first; - glh::matrix4f inv_trans = glh::matrix4f((F32*) mat.mMatrix).inverse().transpose(); - LLMatrix4 norm_mat(inv_trans.m); - - for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter) - { //for each instance with that transform - LLModelInstance& source_instance = *model_iter; - LLModel* source = source_instance.mModel; - - if (!validate_model(source)) - { - llerrs << "Invalid model found!" << llendl; - } - - for (S32 i = 0; i < source->getNumVolumeFaces(); ++i) - { //for each face in instance - const LLVolumeFace& src_face = source->getVolumeFace(i); - LLImportMaterial& source_material = source_instance.mMaterial[i]; - - //get model in composite that is composite for this material - LLModel* model = NULL; - - if (composite.find(source_material) != composite.end()) - { - model = composite[source_material].rbegin()->mModel; - if (model->getVolumeFace(0).mNumVertices + src_face.mNumVertices > 65535) - { - model = NULL; - } - } - - if (model == NULL) - { //no model found, make new model - std::vector materials; - materials.push_back(source_material); - LLVolumeParams volume_params; - volume_params.setType(LL_PCODE_PROFILE_SQUARE, LL_PCODE_PATH_LINE); - model = new LLModel(volume_params, 0.f); - model->mLabel = source->mLabel; - model->setNumVolumeFaces(0); - composite[source_material].push_back(LLModelInstance(model, identity, materials)); - } - - model->appendFace(src_face, source->mMaterialList[i], mat, norm_mat); - } - } - } - - - //condense composite into as few LLModel instances as possible - LLModelLoader::model_list new_model; - std::vector instance_list; - - LLVolumeParams volume_params; - volume_params.setType(LL_PCODE_PROFILE_SQUARE, LL_PCODE_PATH_LINE); - - std::vector empty_material; - LLModelInstance cur_instance(new LLModel(volume_params, 0.f), identity, empty_material); - cur_instance.mModel->setNumVolumeFaces(0); - - BOOL first_transform = TRUE; - - LLModelLoader::scene new_scene; - LLVector3 min,max; - - for (std::map >::iterator iter = composite.begin(); - iter != composite.end(); - ++iter) - { - std::map >::iterator next_iter = iter; ++next_iter; - - for (std::vector::iterator instance_iter = iter->second.begin(); - instance_iter != iter->second.end(); - ++instance_iter) - { - LLModel* source = instance_iter->mModel; - - if (instance_iter->mMaterial.size() != 1) - { - llerrs << "WTF?" << llendl; - } - - if (source->getNumVolumeFaces() != 1) - { - llerrs << "WTF?" << llendl; - } - - if (source->mMaterialList.size() != 1) - { - llerrs << "WTF?" << llendl; - } - - cur_instance.mModel->addFace(source->getVolumeFace(0)); - cur_instance.mMaterial.push_back(instance_iter->mMaterial[0]); - cur_instance.mModel->mMaterialList.push_back(source->mMaterialList[0]); - - BOOL last_model = FALSE; - - std::vector::iterator next_instance = instance_iter; ++next_instance; - - if (next_iter == composite.end() && - next_instance == iter->second.end()) - { - last_model = TRUE; - } - - if (last_model || cur_instance.mModel->getNumVolumeFaces() >= MAX_MODEL_FACES) - { - cur_instance.mModel->mLabel = source->mLabel; - - cur_instance.mModel->optimizeVolumeFaces(); - cur_instance.mModel->normalizeVolumeFaces(); - - if (!validate_model(cur_instance.mModel)) - { - llerrs << "Invalid model detected." << llendl; - } - - new_model.push_back(cur_instance.mModel); - - LLMatrix4 transformation = LLMatrix4(); - - // adjust the transformation to compensate for mesh normalization - LLVector3 mesh_scale_vector; - LLVector3 mesh_translation_vector; - cur_instance.mModel->getNormalizedScaleTranslation(mesh_scale_vector, mesh_translation_vector); - - LLMatrix4 mesh_translation; - mesh_translation.setTranslation(mesh_translation_vector); - mesh_translation *= transformation; - transformation = mesh_translation; - - LLMatrix4 mesh_scale; - mesh_scale.initScale(mesh_scale_vector); - mesh_scale *= transformation; - transformation = mesh_scale; - - cur_instance.mTransform = transformation; - - new_scene[transformation].push_back(cur_instance); - stretch_extents(cur_instance.mModel, transformation, min, max, first_transform); - - if (!last_model) - { - cur_instance = LLModelInstance(new LLModel(volume_params, 0.f), identity, empty_material); - cur_instance.mModel->setNumVolumeFaces(0); - } - } - } - } - - mScene[mPreviewLOD] = new_scene; - mModel[mPreviewLOD] = new_model; - mVertexBuffer[mPreviewLOD].clear(); - - if (mPreviewLOD == LLModel::LOD_HIGH) - { - mBaseScene = new_scene; - mBaseModel = new_model; - clearGLODGroup(); - mVertexBuffer[5].clear(); - } - - mPreviewTarget = (min+max)*0.5f; - mPreviewScale = (max-min)*0.5f; - setPreviewTarget(mPreviewScale.magVec()*2.f); - - clearIncompatible(mPreviewLOD); - - mResourceCost = calcResourceCost(); - refresh(); -} - void LLModelPreview::clearMaterials() { for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter) diff --git a/indra/newview/llfloatermodelpreview.h b/indra/newview/llfloatermodelpreview.h index 8fc85cebb9..e1c520134b 100644 --- a/indra/newview/llfloatermodelpreview.h +++ b/indra/newview/llfloatermodelpreview.h @@ -279,7 +279,7 @@ public: void loadModelCallback(S32 lod); void genLODs(S32 which_lod = -1, U32 decimation = 3, bool enforce_tri_limit = false); void generateNormals(); - void consolidate(); + void clearMaterials(); U32 calcResourceCost(); void rebuildUploadData(); diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp index a2b0ac09af..b6e3626cba 100755 --- a/indra/newview/llmeshrepository.cpp +++ b/indra/newview/llmeshrepository.cpp @@ -2981,7 +2981,7 @@ LLSD LLMeshUploadThread::createObject(LLModelInstance& instance) object_params["pos"] = ll_sd_from_vector3(position + mOrigin); object_params["rotation"] = ll_sd_from_quaternion(quat_rotation); object_params["scale"] = ll_sd_from_vector3(scale); - object_params["name"] = instance.mModel->getName(); + object_params["name"] = instance.mLabel; // load material from dae file object_params["facelist"] = LLSD::emptyArray(); diff --git a/indra/newview/llmeshrepository.h b/indra/newview/llmeshrepository.h index b642a89192..0fcb2213de 100644 --- a/indra/newview/llmeshrepository.h +++ b/indra/newview/llmeshrepository.h @@ -108,14 +108,16 @@ class LLModelInstance public: LLPointer mModel; LLPointer mLOD[5]; - + + std::string mLabel; + LLUUID mMeshID; LLMatrix4 mTransform; std::vector mMaterial; - LLModelInstance(LLModel* model, LLMatrix4& transform, std::vector& materials) - : mModel(model), mTransform(transform), mMaterial(materials) + LLModelInstance(LLModel* model, const std::string& label, LLMatrix4& transform, std::vector& materials) + : mModel(model), mLabel(label), mTransform(transform), mMaterial(materials) { } }; -- cgit v1.2.3