diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 9d68333dda5b2acb61c8112cbe84011bdc32e856..c2f2013216419a5c7f3fe1177a6628e90572dbbc 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -2422,7 +2422,9 @@ bool LLVolume::unpackVolumeFacesInternal(const LLSD& mdl) { LLVolumeFace& face = mVolumeFaces[i]; - if (mdl[i].has("NoGeometry")) + const auto& mdl_face = mdl[i]; + + if (mdl_face.has("NoGeometry")) { //face has no geometry, continue face.resizeIndices(3); face.resizeVertices(1); @@ -2433,11 +2435,11 @@ bool LLVolume::unpackVolumeFacesInternal(const LLSD& mdl) continue; } - LLSD::Binary pos = mdl[i]["Position"]; - LLSD::Binary norm = mdl[i]["Normal"]; - LLSD::Binary tangent = mdl[i]["Tangent"]; - LLSD::Binary tc = mdl[i]["TexCoord0"]; - LLSD::Binary idx = mdl[i]["TriangleList"]; + const LLSD::Binary& pos = mdl_face["Position"]; + const LLSD::Binary& norm = mdl_face["Normal"]; + const LLSD::Binary& tangent = mdl_face["Tangent"]; + const LLSD::Binary& tc = mdl_face["TexCoord0"]; + const LLSD::Binary& idx = mdl_face["TriangleList"]; //copy out indices S32 num_indices = idx.size() / 2; @@ -2484,19 +2486,19 @@ bool LLVolume::unpackVolumeFacesInternal(const LLSD& mdl) LLVector2 min_tc; LLVector2 max_tc; - minp.setValue(mdl[i]["PositionDomain"]["Min"]); - maxp.setValue(mdl[i]["PositionDomain"]["Max"]); + minp.setValue(mdl_face["PositionDomain"]["Min"]); + maxp.setValue(mdl_face["PositionDomain"]["Max"]); LLVector4a min_pos, max_pos; min_pos.load3(minp.mV); max_pos.load3(maxp.mV); - min_tc.setValue(mdl[i]["TexCoord0Domain"]["Min"]); - max_tc.setValue(mdl[i]["TexCoord0Domain"]["Max"]); + min_tc.setValue(mdl_face["TexCoord0Domain"]["Min"]); + max_tc.setValue(mdl_face["TexCoord0Domain"]["Max"]); //unpack normalized scale/translation - if (mdl[i].has("NormalizedScale")) + if (mdl_face.has("NormalizedScale")) { - face.mNormalizedScale.setValue(mdl[i]["NormalizedScale"]); + face.mNormalizedScale.setValue(mdl_face["NormalizedScale"]); } else { @@ -2615,7 +2617,7 @@ bool LLVolume::unpackVolumeFacesInternal(const LLSD& mdl) } } - if (mdl[i].has("Weights")) + if (mdl_face.has("Weights")) { face.allocateWeights(num_verts); if (!face.mWeights && num_verts) @@ -2626,12 +2628,13 @@ bool LLVolume::unpackVolumeFacesInternal(const LLSD& mdl) continue; } - LLSD::Binary weights = mdl[i]["Weights"]; + const LLSD::Binary& weights = mdl_face["Weights"]; U32 idx = 0; U32 cur_vertex = 0; - while (idx < weights.size() && cur_vertex < num_verts) + size_t weight_size = weights.size(); + while (idx < weight_size && cur_vertex < num_verts) { const U8 END_INFLUENCES = 0xFF; U8 joint = weights[idx++]; @@ -2641,7 +2644,7 @@ bool LLVolume::unpackVolumeFacesInternal(const LLSD& mdl) U32 joints[4] = {0,0,0,0}; LLVector4 joints_with_weights(0,0,0,0); - while (joint != END_INFLUENCES && idx < weights.size()) + while (joint != END_INFLUENCES && idx < weight_size) { U16 influence = weights[idx++]; influence |= ((U16) weights[idx++] << 8); diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index ab58de3f586da2cc429bf2df4a8ab1bec650085b..5517159a2d9c0e7367d50699478efb9d9e29ee9c 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -991,7 +991,7 @@ LLSD LLModel::writeModelToStream(std::ostream& ostr, LLSD& mdl, BOOL nowrite, BO if (mdl.has("submodel_id")) { //write out submodel id - header["submodel_id"] = (LLSD::Integer)mdl["submodel_id"]; + header["submodel_id"] = (LLSD::Integer)mdl["submodel_id"]; } std::string out[MODEL_NAMES_LENGTH]; @@ -1172,16 +1172,20 @@ bool LLModel::loadModel(std::istream& is) } } - if (header.has("material_list")) + const auto& header_map = header.map(); + + auto it = header_map.find("material_list"); + if (it != header_map.end()) { //load material list names mMaterialList.clear(); - for (U32 i = 0; i < header["material_list"].size(); ++i) + for (U32 i = 0; i < it->second.size(); ++i) { - mMaterialList.push_back(header["material_list"][i].asString()); + mMaterialList.push_back(it->second[i].asString()); } } - mSubmodelID = header.has("submodel_id") ? header["submodel_id"].asInteger() : false; + it = header_map.find("submodel_id"); + mSubmodelID = it != header_map.end() ? it->second.asInteger() : false; static const std::array<std::string, 5> lod_name = {{ "lowest_lod", @@ -1456,9 +1460,12 @@ LLMeshSkinInfo::LLMeshSkinInfo(const LLUUID& mesh_id, const LLSD& skin) : void LLMeshSkinInfo::fromLLSD(const LLSD& skin) { - if (skin.has("joint_names")) + const auto& skin_map = skin.map(); + + auto it = skin_map.find("joint_names"); + if (it != skin_map.end()) { - const auto& joint_names = skin["joint_names"]; + const auto& joint_names = it->second; for(const auto& jnt_llsd : joint_names.array()) { mJointNames.emplace_back(jnt_llsd.asString()); @@ -1466,9 +1473,10 @@ void LLMeshSkinInfo::fromLLSD(const LLSD& skin) } } - if (skin.has("bind_shape_matrix")) + it = skin_map.find("bind_shape_matrix"); + if (it != skin_map.end()) { - const auto& bind_shape_mat = skin["bind_shape_matrix"]; + const auto& bind_shape_mat = it->second.array(); LLMatrix4 mat; for (auto j = 0; j < 4; j++) { @@ -1480,10 +1488,11 @@ void LLMeshSkinInfo::fromLLSD(const LLSD& skin) mBindShapeMatrix.loadu(mat); } - if (skin.has("inverse_bind_matrix")) + it = skin_map.find("inverse_bind_matrix"); + if (it != skin_map.end()) { - const auto& inv_bind_mat = skin["inverse_bind_matrix"]; - for (auto i = 0; i < inv_bind_mat.size(); ++i) + const auto& inv_bind_mat = it->second.array(); + for (size_t i = 0, size = inv_bind_mat.size(); i < size; ++i) { LLMatrix4 mat; for (auto j = 0; j < 4; j++) @@ -1511,10 +1520,11 @@ void LLMeshSkinInfo::fromLLSD(const LLSD& skin) } } - if (skin.has("alt_inverse_bind_matrix")) + it = skin_map.find("alt_inverse_bind_matrix"); + if (it != skin_map.end()) { - const auto& alt_inv_bind_mat = skin["alt_inverse_bind_matrix"]; - for (auto i = 0; i < alt_inv_bind_mat.size(); ++i) + const auto& alt_inv_bind_mat = it->second.array(); + for (size_t i = 0, size = alt_inv_bind_mat.size(); i < size; ++i) { LLMatrix4 mat; for (auto j = 0; j < 4; j++) @@ -1529,14 +1539,16 @@ void LLMeshSkinInfo::fromLLSD(const LLSD& skin) } } - if (skin.has("pelvis_offset")) + it = skin_map.find("pelvis_offset"); + if (it != skin_map.end()) { - mPelvisOffset = skin["pelvis_offset"].asReal(); + mPelvisOffset = it->second.asReal(); } - if (skin.has("lock_scale_if_joint_position")) + it = skin_map.find("lock_scale_if_joint_position"); + if (it != skin_map.end()) { - mLockScaleIfJointPosition = skin["lock_scale_if_joint_position"].asBoolean(); + mLockScaleIfJointPosition = it->second.asBoolean(); } else {