From 15235061e8a8f64dd94640d27eadfce23ccb76f6 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Sat, 18 Jun 2011 01:02:03 -0500 Subject: SH-828 Fix for using uninitialized data when normals or texture coordinates are absent from collada file (can now upload meshes without normals or texture coordinates). --- indra/llprimitive/llmodel.cpp | 355 +++++++++++++++++++----------------------- 1 file changed, 163 insertions(+), 192 deletions(-) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index e0cfa07614..7c9dba9597 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -27,6 +27,7 @@ #include "linden_common.h" #include "llmodel.h" +#include "llmemory.h" #include "llconvexdecomposition.h" #include "llsdserialize.h" #include "llvector4a.h" @@ -71,88 +72,10 @@ LLModel::~LLModel() } } -void load_face_from_dom_inputs(LLVolumeFace& face, const domInputLocalOffset_Array& inputs, U32 min_idx, U32 max_idx) -{ - for (U32 j = 0; j < inputs.getCount(); ++j) - { - if (strcmp(COMMON_PROFILE_INPUT_VERTEX, inputs[j]->getSemantic()) == 0) - { //found vertex array - const domURIFragmentType& uri = inputs[j]->getSource(); - daeElementRef elem = uri.getElement(); - domVertices* vertices = (domVertices*) elem.cast(); - - domInputLocal_Array& v_inp = vertices->getInput_array(); - if (inputs[j]->getOffset() != 0) - { - llerrs << "Vertex array offset MUST be zero." << llendl; - } - - for (U32 k = 0; k < v_inp.getCount(); ++k) - { - if (strcmp(COMMON_PROFILE_INPUT_POSITION, v_inp[k]->getSemantic()) == 0) - { - const domURIFragmentType& uri = v_inp[k]->getSource(); - - daeElementRef elem = uri.getElement(); - domSource* src = (domSource*) elem.cast(); - - if (src->getTechnique_common()->getAccessor()->getStride() != 3) - { - llerrs << "Vertex array stride MUST be three." << llendl; - } - - domListOfFloats& v = src->getFloat_array()->getValue(); - - LLVector4a min; - min.set(v[min_idx], v[min_idx+1], v[min_idx+2]); - LLVector4a max = min; - - for (U32 j = min_idx; j <= max_idx; ++j) - { //copy vertex array - face.mPositions[j-min_idx].set(v[j*3+0], v[j*3+1], v[j*3+2]); - update_min_max(min, max, face.mPositions[j-min_idx]); - } - - face.mExtents[0] = min; - face.mExtents[1] = max; - } - } - } - - if (strcmp(COMMON_PROFILE_INPUT_NORMAL, inputs[j]->getSemantic()) == 0) - { - //found normal array for this triangle list - const domURIFragmentType& uri = inputs[j]->getSource(); - daeElementRef elem = uri.getElement(); - domSource* src = (domSource*) elem.cast(); - domListOfFloats& n = src->getFloat_array()->getValue(); - - for (U32 j = min_idx; j <= max_idx; ++j) - { - LLVector4a* norm = (LLVector4a*) face.mNormals + (j-min_idx); - norm->set(n[j*3+0], n[j*3+1], n[j*3+2]); - norm->normalize3(); - } - } - else if (strcmp(COMMON_PROFILE_INPUT_TEXCOORD, inputs[j]->getSemantic()) == 0) - { //found texCoords - const domURIFragmentType& uri = inputs[j]->getSource(); - daeElementRef elem = uri.getElement(); - domSource* src = (domSource*) elem.cast(); - domListOfFloats& u = src->getFloat_array()->getValue(); - - for (U32 j = min_idx; j <= max_idx; ++j) - { - face.mTexCoords[j-min_idx].setVec(u[j*2+0], u[j*2+1]); - } - } - } -} bool get_dom_sources(const domInputLocalOffset_Array& inputs, S32& pos_offset, S32& tc_offset, S32& norm_offset, S32 &idx_stride, domSource* &pos_source, domSource* &tc_source, domSource* &norm_source) { - idx_stride = 0; for (U32 j = 0; j < inputs.getCount(); ++j) @@ -271,14 +194,13 @@ LLModel::EModelStatus load_face_from_dom_triangles(std::vector& fa cv.mTexCoord.setVec(tc[idx[i+tc_offset]*2+0], tc[idx[i+tc_offset]*2+1]); } - + if (norm_source) { cv.setNormal(LLVector4a(n[idx[i+norm_offset]*3+0], n[idx[i+norm_offset]*3+1], n[idx[i+norm_offset]*3+2])); } - BOOL found = FALSE; @@ -329,10 +251,22 @@ LLModel::EModelStatus load_face_from_dom_triangles(std::vector& fa { face_list.push_back(face); face_list.rbegin()->fillFromLegacyData(verts, indices); + LLVolumeFace& new_face = *face_list.rbegin(); + if (!norm_source) + { + ll_aligned_free_16(new_face.mNormals); + new_face.mNormals = NULL; + } + + if (!tc_source) + { + ll_aligned_free_16(face.mTexCoords); + new_face.mTexCoords = NULL; + } + face = LLVolumeFace(); point_map.clear(); } - } if (!verts.empty()) @@ -348,6 +282,18 @@ LLModel::EModelStatus load_face_from_dom_triangles(std::vector& fa face_list.push_back(face); face_list.rbegin()->fillFromLegacyData(verts, indices); + LLVolumeFace& new_face = *face_list.rbegin(); + if (!norm_source) + { + ll_aligned_free_16(new_face.mNormals); + new_face.mNormals = NULL; + } + + if (!tc_source) + { + ll_aligned_free_16(face.mTexCoords); + new_face.mTexCoords = NULL; + } } return LLModel::NO_ERRORS ; @@ -433,14 +379,14 @@ LLModel::EModelStatus load_face_from_dom_polylist(std::vector& fac cv.mTexCoord.setVec(tc[idx[cur_idx+tc_offset]*2+0], tc[idx[cur_idx+tc_offset]*2+1]); } - + if (norm_source) { cv.getNormal().set(n[idx[cur_idx+norm_offset]*3+0], n[idx[cur_idx+norm_offset]*3+1], n[idx[cur_idx+norm_offset]*3+2]); } - + cur_idx += idx_stride; BOOL found = FALSE; @@ -524,6 +470,19 @@ LLModel::EModelStatus load_face_from_dom_polylist(std::vector& fac { face_list.push_back(face); face_list.rbegin()->fillFromLegacyData(verts, indices); + LLVolumeFace& new_face = *face_list.rbegin(); + if (!norm_source) + { + ll_aligned_free_16(new_face.mNormals); + new_face.mNormals = NULL; + } + + if (!tc_source) + { + ll_aligned_free_16(face.mTexCoords); + new_face.mTexCoords = NULL; + } + face = LLVolumeFace(); verts.clear(); indices.clear(); @@ -540,10 +499,23 @@ LLModel::EModelStatus load_face_from_dom_polylist(std::vector& fac { material = std::string(poly->getMaterial()); } - + materials.push_back(material); face_list.push_back(face); face_list.rbegin()->fillFromLegacyData(verts, indices); + + LLVolumeFace& new_face = *face_list.rbegin(); + if (!norm_source) + { + ll_aligned_free_16(new_face.mNormals); + new_face.mNormals = NULL; + } + + if (!tc_source) + { + ll_aligned_free_16(face.mTexCoords); + new_face.mTexCoords = NULL; + } } return LLModel::NO_ERRORS ; @@ -557,7 +529,6 @@ LLModel::EModelStatus load_face_from_dom_polygons(std::vector& fac const domInputLocalOffset_Array& inputs = poly->getInput_array(); - S32 v_offset = -1; S32 n_offset = -1; S32 t_offset = -1; @@ -662,15 +633,14 @@ LLModel::EModelStatus load_face_from_dom_polygons(std::vector& fac n->get(n_idx+1), n->get(n_idx+2)); } - + if (t) { U32 t_idx = idx[j*stride+t_offset]*2; vert.mTexCoord.setVec(t->get(t_idx), t->get(t_idx+1)); } - - + verts.push_back(vert); } } @@ -733,6 +703,19 @@ LLModel::EModelStatus load_face_from_dom_polygons(std::vector& fac materials.push_back(material); face_list.push_back(face); face_list.rbegin()->fillFromLegacyData(new_verts, indices); + + LLVolumeFace& new_face = *face_list.rbegin(); + if (!n) + { + ll_aligned_free_16(new_face.mNormals); + new_face.mNormals = NULL; + } + + if (!t) + { + ll_aligned_free_16(face.mTexCoords); + new_face.mTexCoords = NULL; + } } return LLModel::NO_ERRORS ; @@ -817,9 +800,9 @@ BOOL LLModel::createVolumeFacesFromDomMesh(domMesh* mesh) if (getNumVolumeFaces() > 0) { - optimizeVolumeFaces(); normalizeVolumeFaces(); - + optimizeVolumeFaces(); + if (getNumVolumeFaces() > 0) { return TRUE; @@ -853,81 +836,10 @@ void LLModel::offsetMesh( const LLVector3& pivotPoint ) void LLModel::optimizeVolumeFaces() { -#if 0 //VECTORIZE ? - for (std::vector::iterator iter = mVolumeFaces.begin(); iter != mVolumeFaces.end(); ) - { - std::vector::iterator cur_iter = iter++; - LLVolumeFace& face = *cur_iter; - - for (S32 i = 0; i < (S32) face.mNumIndices; i += 3) - { //remove zero area triangles - U16 i0 = face.mIndices[i+0]; - U16 i1 = face.mIndices[i+1]; - U16 i2 = face.mIndices[i+2]; - - if (i0 == i1 || - i1 == i2 || - i0 == i2) - { //duplicate index in triangle, remove triangle - face.mIndices.erase(face.mIndices.begin()+i, face.mIndices.begin()+i+3); - i -= 3; - } - else - { - LLVolumeFace::VertexData& v0 = face.mVertices[i0]; - LLVolumeFace::VertexData& v1 = face.mVertices[i1]; - LLVolumeFace::VertexData& v2 = face.mVertices[i2]; - - if (v0.mPosition == v1.mPosition || - v1.mPosition == v2.mPosition || - v2.mPosition == v0.mPosition) - { //zero area triangle, delete - face.mIndices.erase(face.mIndices.begin()+i, face.mIndices.begin()+i+3); - i-=3; - } - } - } - - //remove unreference vertices - std::vector ref; - ref.resize(face.mNumVertices); - - for (U32 i = 0; i < ref.size(); ++i) - { - ref[i] = false; - } - - for (U32 i = 0; i < face.mNumIndices; ++i) - { - ref[face.mIndices[i]] = true; - } - - U32 unref_count = 0; - for (U32 i = 0; i < ref.size(); ++i) - { - if (!ref[i]) - { - //vertex is unreferenced - face.mVertices.erase(face.mVertices.begin()+(i-unref_count)); - U16 idx = (U16) (i-unref_count); - - for (U32 j = 0; j < face.mNumIndices; ++j) - { //decrement every index array value greater than idx - if (face.mIndices[j] > idx) - { - --face.mIndices[j]; - } - } - ++unref_count; - } - } - - if (face.mVertices.empty() || face.mIndices.empty()) - { //face is empty, remove it - iter = mVolumeFaces.erase(cur_iter); - } + for (U32 i = 0; i < getNumVolumeFaces(); ++i) + { + mVolumeFaces[i].optimize(); } -#endif } // Shrink the model to fit @@ -962,6 +874,25 @@ void LLModel::normalizeVolumeFaces() update_min_max(min, max, face.mExtents[0]); update_min_max(min, max, face.mExtents[1]); + + if (face.mTexCoords) + { + LLVector2& min_tc = face.mTexCoordExtents[0]; + LLVector2& max_tc = face.mTexCoordExtents[1]; + + min_tc = face.mTexCoords[0]; + max_tc = face.mTexCoords[0]; + + for (U32 j = 1; j < face.mNumVertices; ++j) + { + update_min_max(min_tc, max_tc, face.mTexCoords[j]); + } + } + else + { + face.mTexCoordExtents[0].set(0,0); + face.mTexCoordExtents[1].set(1,1); + } } // Now that we have the extents of the model @@ -1029,8 +960,11 @@ void LLModel::normalizeVolumeFaces() { pos[j].add(trans); pos[j].mul(scale); - norm[j].mul(inv_scale); - norm[j].normalize3(); + if (norm && !norm[j].equals3(LLVector4a::getZero())) + { + norm[j].mul(inv_scale); + norm[j].normalize3(); + } } } @@ -1073,8 +1007,26 @@ void LLModel::setVolumeFaceData( face.resizeIndices(num_indices); LLVector4a::memcpyNonAliased16((F32*) face.mPositions, (F32*) pos.get(), num_verts*4*sizeof(F32)); - LLVector4a::memcpyNonAliased16((F32*) face.mNormals, (F32*) norm.get(), num_verts*4*sizeof(F32)); - LLVector4a::memcpyNonAliased16((F32*) face.mTexCoords, (F32*) tc.get(), num_verts*2*sizeof(F32)); + if (norm.get()) + { + LLVector4a::memcpyNonAliased16((F32*) face.mNormals, (F32*) norm.get(), num_verts*4*sizeof(F32)); + } + else + { + ll_aligned_free_16(face.mNormals); + face.mNormals = NULL; + } + + if (tc.get()) + { + LLVector4a::memcpyNonAliased16((F32*) face.mTexCoords, (F32*) tc.get(), num_verts*2*sizeof(F32)); + } + else + { + ll_aligned_free_16(face.mTexCoords); + face.mTexCoords = NULL; + } + U32 size = (num_indices*2+0xF)&~0xF; LLVector4a::memcpyNonAliased16((F32*) face.mIndices, (F32*) ind.get(), size); } @@ -1477,9 +1429,8 @@ LLSD LLModel::writeModel( { //for each vert F32* pos = face.mPositions[j].getF32ptr(); - F32* norm = face.mNormals[j].getF32ptr(); - - //position + normal + + //position for (U32 k = 0; k < 3; ++k) { //for each component //convert to 16-bit normalized across domain @@ -1489,29 +1440,41 @@ LLSD LLModel::writeModel( //write to binary buffer verts[vert_idx++] = buff[0]; verts[vert_idx++] = buff[1]; - - //convert to 16-bit normalized - val = (U16) ((norm[k]+1.f)*0.5f*65535); + } - //write to binary buffer - normals[norm_idx++] = buff[0]; - normals[norm_idx++] = buff[1]; + if (face.mNormals) + { //normals + F32* norm = face.mNormals[j].getF32ptr(); + + for (U32 k = 0; k < 3; ++k) + { //for each component + //convert to 16-bit normalized + U16 val = (U16) ((norm[k]+1.f)*0.5f*65535); + U8* buff = (U8*) &val; + + //write to binary buffer + normals[norm_idx++] = buff[0]; + normals[norm_idx++] = buff[1]; + } } + F32* src_tc = (F32*) face.mTexCoords[j].mV; //texcoord - for (U32 k = 0; k < 2; ++k) - { //for each component - //convert to 16-bit normalized - U16 val = (U16) ((src_tc[k]-min_tc.mV[k])/tc_range.mV[k]*65535); - - U8* buff = (U8*) &val; - //write to binary buffer - tc[tc_idx++] = buff[0]; - tc[tc_idx++] = buff[1]; + if (face.mTexCoords) + { + for (U32 k = 0; k < 2; ++k) + { //for each component + //convert to 16-bit normalized + U16 val = (U16) ((src_tc[k]-min_tc.mV[k])/tc_range.mV[k]*65535); + + U8* buff = (U8*) &val; + //write to binary buffer + tc[tc_idx++] = buff[0]; + tc[tc_idx++] = buff[1]; + } } - } U32 idx_idx = 0; @@ -1525,12 +1488,20 @@ LLSD LLModel::writeModel( //write out face data mdl[model_names[idx]][i]["PositionDomain"]["Min"] = min_pos.getValue(); mdl[model_names[idx]][i]["PositionDomain"]["Max"] = max_pos.getValue(); - mdl[model_names[idx]][i]["TexCoord0Domain"]["Min"] = min_tc.getValue(); - mdl[model_names[idx]][i]["TexCoord0Domain"]["Max"] = max_tc.getValue(); - mdl[model_names[idx]][i]["Position"] = verts; - mdl[model_names[idx]][i]["Normal"] = normals; - mdl[model_names[idx]][i]["TexCoord0"] = tc; + + if (face.mNormals) + { + mdl[model_names[idx]][i]["Normal"] = normals; + } + + if (face.mTexCoords) + { + mdl[model_names[idx]][i]["TexCoord0Domain"]["Min"] = min_tc.getValue(); + mdl[model_names[idx]][i]["TexCoord0Domain"]["Max"] = max_tc.getValue(); + mdl[model_names[idx]][i]["TexCoord0"] = tc; + } + mdl[model_names[idx]][i]["TriangleList"] = indices; if (skinning) -- cgit v1.2.3 From ce02ed3118a8a84df9bcbf39b4a5531e5c698561 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 20 Jun 2011 18:55:30 -0500 Subject: SH-1880 partial fix for crashing on daes without UVs. --- indra/llprimitive/llmodel.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 859dcbd489..8f2f24b747 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -1414,13 +1414,19 @@ LLSD LLModel::writeModel( U32 tc_idx = 0; LLVector2* ftc = (LLVector2*) face.mTexCoords; - LLVector2 min_tc = ftc[0]; - LLVector2 max_tc = min_tc; - - //get texture coordinate domain - for (U32 j = 0; j < face.mNumVertices; ++j) + LLVector2 min_tc; + LLVector2 max_tc; + + if (ftc) { - update_min_max(min_tc, max_tc, ftc[j]); + min_tc = ftc[0]; + max_tc = min_tc; + + //get texture coordinate domain + for (U32 j = 0; j < face.mNumVertices; ++j) + { + update_min_max(min_tc, max_tc, ftc[j]); + } } LLVector2 tc_range = max_tc - min_tc; @@ -1457,8 +1463,7 @@ LLSD LLModel::writeModel( normals[norm_idx++] = buff[1]; } } - - + F32* src_tc = (F32*) face.mTexCoords[j].mV; //texcoord -- cgit v1.2.3 From b0fdc4495153523ff417334499ca466b0d8987c8 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 22 Jun 2011 16:08:23 -0500 Subject: SH-1815 Fix for crash when using old version slm --- indra/llprimitive/llmodel.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 8f2f24b747..f2fe20b3e7 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -1784,6 +1784,7 @@ bool LLModel::loadModel(std::istream& is) if (header[nm[lod]]["offset"].asInteger() == -1 || header[nm[lod]]["size"].asInteger() == 0 ) { //cannot load requested LOD + llwarns << "LoD data is invalid!" << llendl; return false; } @@ -1844,6 +1845,10 @@ bool LLModel::loadModel(std::istream& is) } return true; } + else + { + llwarns << "unpackVolumeFaces failed!" << llendl; + } return false; -- cgit v1.2.3 From f83b08b69c84d6df9cebb79167804cd295555481 Mon Sep 17 00:00:00 2001 From: Xiaohong Bao Date: Fri, 24 Jun 2011 15:09:10 -0600 Subject: fix for SH-1878: Viewer hang in GLOD_Group::adaptTriangleBudget during LLModelPreview::genLODs; SH-1891: viewer crashes while previewing "RYOMA 3D XML File.dae"; SH-1890: Crash loading palm tree --- indra/llprimitive/llmodel.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index f2fe20b3e7..972f256076 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -260,7 +260,7 @@ LLModel::EModelStatus load_face_from_dom_triangles(std::vector& fa if (!tc_source) { - ll_aligned_free_16(face.mTexCoords); + ll_aligned_free_16(new_face.mTexCoords); new_face.mTexCoords = NULL; } @@ -291,7 +291,7 @@ LLModel::EModelStatus load_face_from_dom_triangles(std::vector& fa if (!tc_source) { - ll_aligned_free_16(face.mTexCoords); + ll_aligned_free_16(new_face.mTexCoords); new_face.mTexCoords = NULL; } } @@ -479,7 +479,7 @@ LLModel::EModelStatus load_face_from_dom_polylist(std::vector& fac if (!tc_source) { - ll_aligned_free_16(face.mTexCoords); + ll_aligned_free_16(new_face.mTexCoords); new_face.mTexCoords = NULL; } @@ -513,7 +513,7 @@ LLModel::EModelStatus load_face_from_dom_polylist(std::vector& fac if (!tc_source) { - ll_aligned_free_16(face.mTexCoords); + ll_aligned_free_16(new_face.mTexCoords); new_face.mTexCoords = NULL; } } @@ -713,7 +713,7 @@ LLModel::EModelStatus load_face_from_dom_polygons(std::vector& fac if (!t) { - ll_aligned_free_16(face.mTexCoords); + ll_aligned_free_16(new_face.mTexCoords); new_face.mTexCoords = NULL; } } -- cgit v1.2.3 From 12e08417bfdf5d50feea544a54bbb333ad01acce Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 28 Jun 2011 12:41:12 -0500 Subject: SH-1169 Fix for convex decompositions not working post mesh-asset-deprecation work. (also default SLM usage to on) --- indra/llprimitive/llmodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 972f256076..da78b30b34 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -1798,7 +1798,7 @@ bool LLModel::loadModel(std::istream& is) is.seekg(cur_pos); } - if (lod == LLModel::LOD_PHYSICS) + if (lod == LLModel::LOD_HIGH || lod == LLModel::LOD_PHYSICS) { std::ios::pos_type cur_pos = is.tellg(); loadDecomposition(header, is); @@ -2015,7 +2015,7 @@ LLModel::Decomposition::Decomposition(LLSD& data) void LLModel::Decomposition::fromLLSD(LLSD& decomp) { - if (decomp.has("HullList")) + if (decomp.has("HullList") && decomp.has("Positions")) { // updated for const-correctness. gcc is picky about this type of thing - Nyx const LLSD::Binary& hulls = decomp["HullList"].asBinary(); -- cgit v1.2.3 From 71eb68a85d5a5157622ae8f42bac1c21f00d54cd Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 6 Jul 2011 18:54:50 -0500 Subject: Fix for "set to default" button not resetting some data. --- indra/llprimitive/llmodel.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index da78b30b34..34b81c9672 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -2171,6 +2171,8 @@ LLSD LLModel::Decomposition::asLLSD() const ret["Min"] = min.getValue(); ret["Max"] = max.getValue(); + LLVector3 range = max-min; + if (!hulls.empty()) { ret["HullList"] = hulls; @@ -2180,10 +2182,6 @@ LLSD LLModel::Decomposition::asLLSD() const { LLSD::Binary p(total*3*2); - LLVector3 min(-0.5f, -0.5f, -0.5f); - LLVector3 max(0.5f, 0.5f, 0.5f); - LLVector3 range = max-min; - U32 vert_idx = 0; for (U32 i = 0; i < mHull.size(); ++i) @@ -2195,11 +2193,11 @@ LLSD LLModel::Decomposition::asLLSD() const for (U32 j = 0; j < mHull[i].size(); ++j) { U64 test = 0; + const F32* src = mHull[i][j].mV; + for (U32 k = 0; k < 3; k++) { - F32* src = (F32*) (mHull[i][j].mV); - - llassert(src[k] <= 0.501f && src[k] >= -0.501f); + llassert(src[k] <= 0.51f && src[k] >= -0.51f); //convert to 16-bit normalized across domain U16 val = (U16) (((src[k]-min.mV[k])/range.mV[k])*65535); @@ -2239,19 +2237,17 @@ LLSD LLModel::Decomposition::asLLSD() const { LLSD::Binary p(mBaseHull.size()*3*2); - LLVector3 min(-0.5f, -0.5f, -0.5f); - LLVector3 max(0.5f, 0.5f, 0.5f); - LLVector3 range = max-min; - U32 vert_idx = 0; for (U32 j = 0; j < mBaseHull.size(); ++j) { + const F32* v = mBaseHull[j].mV; + for (U32 k = 0; k < 3; k++) { - llassert(mBaseHull[j].mV[k] <= 0.51f && mBaseHull[j].mV[k] >= -0.51f); + llassert(v[k] <= 0.51f && v[k] >= -0.51f); //convert to 16-bit normalized across domain - U16 val = (U16) (((mBaseHull[j].mV[k]-min.mV[k])/range.mV[k])*65535); + U16 val = (U16) (((v[k]-min.mV[k])/range.mV[k])*65535); U8* buff = (U8*) &val; //write to binary buffer -- cgit v1.2.3 From 9b253ccf68718dea51dc94416b3ece28b42fc32a Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 6 Jul 2011 19:27:43 -0500 Subject: SH-1972 Fix for slm messing up physics shape on second upload. --- indra/llprimitive/llmodel.cpp | 7 ++++--- indra/llprimitive/llmodel.h | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 34b81c9672..d3f42c63d5 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -1347,7 +1347,8 @@ LLSD LLModel::writeModel( const LLModel::Decomposition& decomp, BOOL upload_skin, BOOL upload_joints, - BOOL nowrite) + BOOL nowrite, + BOOL as_slm) { LLSD mdl; @@ -1371,8 +1372,8 @@ LLSD LLModel::writeModel( !decomp.mHull.empty()) { mdl["physics_convex"] = decomp.asLLSD(); - if (!decomp.mHull.empty()) - { //convex decomposition exists, physics mesh will not be used + if (!decomp.mHull.empty() && !as_slm) + { //convex decomposition exists, physics mesh will not be used (unless this is an slm file) model[LLModel::LOD_PHYSICS] = NULL; } } diff --git a/indra/llprimitive/llmodel.h b/indra/llprimitive/llmodel.h index cd9f76fcb7..1ece877f0f 100644 --- a/indra/llprimitive/llmodel.h +++ b/indra/llprimitive/llmodel.h @@ -137,7 +137,8 @@ public: const LLModel::Decomposition& decomp, BOOL upload_skin, BOOL upload_joints, - BOOL nowrite = FALSE); + BOOL nowrite = FALSE, + BOOL as_slm = FALSE); static LLSD writeModelToStream( std::ostream& ostr, -- cgit v1.2.3 From 2a6e18d147a3ef3f5a8780233c1cef2f7b69af4a Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 7 Jul 2011 18:32:42 -0500 Subject: SH-1774 Fix for preserving material assignments between multiple custom LoDs. --- indra/llprimitive/llmodel.cpp | 77 +++++++++++++++++++++++++++++++++++++++++-- indra/llprimitive/llmodel.h | 7 +++- 2 files changed, 81 insertions(+), 3 deletions(-) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index d3f42c63d5..986bde0581 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -1378,6 +1378,14 @@ LLSD LLModel::writeModel( } } + if (as_slm) + { //save material list names + for (U32 i = 0; i < high->mMaterialList.size(); ++i) + { + mdl["material_list"][i] = high->mMaterialList[i]; + } + } + for (U32 idx = 0; idx < MODEL_NAMES_LENGTH; ++idx) { if (model[idx] && model[idx]->getNumVolumeFaces() > 0) @@ -1565,10 +1573,10 @@ LLSD LLModel::writeModel( } } - return writeModelToStream(ostr, mdl, nowrite); + return writeModelToStream(ostr, mdl, nowrite, as_slm); } -LLSD LLModel::writeModelToStream(std::ostream& ostr, LLSD& mdl, BOOL nowrite) +LLSD LLModel::writeModelToStream(std::ostream& ostr, LLSD& mdl, BOOL nowrite, BOOL as_slm) { U32 bytes = 0; @@ -1576,6 +1584,11 @@ LLSD LLModel::writeModelToStream(std::ostream& ostr, LLSD& mdl, BOOL nowrite) LLSD header; + if (as_slm && mdl.has("material_list")) + { //save material binding names to header + header["material_list"] = mdl["material_list"]; + } + std::string skin; if (mdl.has("skin")) @@ -1769,6 +1782,15 @@ bool LLModel::loadModel(std::istream& is) } } + if (header.has("material_list")) + { //load material list names + mMaterialList.clear(); + for (U32 i = 0; i < header["material_list"].size(); ++i) + { + mMaterialList.push_back(header["material_list"][i].asString()); + } + } + std::string nm[] = { "lowest_lod", @@ -1855,6 +1877,57 @@ bool LLModel::loadModel(std::istream& is) } +void LLModel::matchMaterialOrder(LLModel* ref) +{ + llassert(ref->mMaterialList.size() == mMaterialList.size()); + + std::map index_map; + + //build a map of material slot names to face indexes + bool reorder = false; + std::set base_mat; + std::set cur_mat; + + for (U32 i = 0; i < mMaterialList.size(); i++) + { + index_map[ref->mMaterialList[i]] = i; + if (!reorder) + { //if any material name does not match reference, we need to reorder + reorder = ref->mMaterialList[i] != mMaterialList[i]; + } + base_mat.insert(ref->mMaterialList[i]); + cur_mat.insert(mMaterialList[i]); + } + + + if (reorder && + base_mat == cur_mat) //don't reorder if material name sets don't match + { + std::vector new_face_list; + new_face_list.resize(mVolumeFaces.size()); + + std::vector new_material_list; + new_material_list.resize(mVolumeFaces.size()); + + //rebuild face list so materials have the same order + //as the reference model + for (U32 i = 0; i < mMaterialList.size(); ++i) + { + U32 ref_idx = index_map[mMaterialList[i]]; + new_face_list[ref_idx] = mVolumeFaces[i]; + + new_material_list[ref_idx] = mMaterialList[i]; + } + + llassert(new_material_list == ref->mMaterialList); + + mVolumeFaces = new_face_list; + } + + //override material list with reference model ordering + mMaterialList = ref->mMaterialList; +} + bool LLModel::loadSkinInfo(LLSD& header, std::istream &is) { diff --git a/indra/llprimitive/llmodel.h b/indra/llprimitive/llmodel.h index 1ece877f0f..3f58eba07d 100644 --- a/indra/llprimitive/llmodel.h +++ b/indra/llprimitive/llmodel.h @@ -143,7 +143,7 @@ public: static LLSD writeModelToStream( std::ostream& ostr, LLSD& mdl, - BOOL nowrite = FALSE); + BOOL nowrite = FALSE, BOOL as_slm = FALSE); static LLModel* loadModelFromDomMesh(domMesh* mesh); static std::string getElementLabel(daeElement* element); @@ -172,6 +172,11 @@ public: void optimizeVolumeFaces(); void offsetMesh( const LLVector3& pivotPoint ); void getNormalizedScaleTranslation(LLVector3& scale_out, LLVector3& translation_out); + + //reorder face list based on mMaterialList in this and reference so + //order matches that of reference (material ordering touchup) + void matchMaterialOrder(LLModel* reference); + std::vector mMaterialList; //data used for skin weights -- cgit v1.2.3 From dc7100a63f09aa67a2fa59e354f8e681bfd7fcb9 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 8 Jul 2011 23:21:51 -0500 Subject: SH-2008 Fix for crash when generating normals on objects with no texture coordinates. --- indra/llprimitive/llmodel.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 986bde0581..ba7abd4c79 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -1209,10 +1209,23 @@ void LLModel::generateNormals(F32 angle_cutoff) LLVolumeFace::VertexData v; new_face.mPositions[i] = vol_face.mPositions[idx]; new_face.mNormals[i].clear(); - new_face.mTexCoords[i] = vol_face.mTexCoords[idx]; new_face.mIndices[i] = i; } + if (vol_face.mTexCoords) + { + for (U32 i = 0; i < vol_face.mNumIndices; i++) + { + U32 idx = vol_face.mIndices[i]; + new_face.mTexCoords[i] = vol_face.mTexCoords[idx]; + } + } + else + { + ll_aligned_free_16(new_face.mTexCoords); + new_face.mTexCoords = NULL; + } + //generate normals for new face for (U32 i = 0; i < new_face.mNumIndices; i += 3) { //for each triangle -- cgit v1.2.3 From 561d40d5c316b4879ea56965f6b320e8e1c70a88 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 14 Jul 2011 01:07:01 -0500 Subject: SH-715 Disable simplify/analyze button while counterpart is executing. --- indra/llprimitive/llmodel.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index ba7abd4c79..434fb7650b 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -2284,8 +2284,6 @@ LLSD LLModel::Decomposition::asLLSD() const for (U32 k = 0; k < 3; k++) { - llassert(src[k] <= 0.51f && src[k] >= -0.51f); - //convert to 16-bit normalized across domain U16 val = (U16) (((src[k]-min.mV[k])/range.mV[k])*65535); -- cgit v1.2.3 From 8b7e33ad36bc33c2356300f8eabc8ddae578070e Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Tue, 19 Jul 2011 15:19:07 -0400 Subject: Cherry pick of https://bitbucket.org/lindenlab/mesh-development/changeset/9cea44ebea3b by don, to fix old viewer crashes in mesh regions --- indra/llprimitive/llprimitive.h | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llprimitive.h b/indra/llprimitive/llprimitive.h index 76faa1b8c5..8903d8e049 100644 --- a/indra/llprimitive/llprimitive.h +++ b/indra/llprimitive/llprimitive.h @@ -103,6 +103,7 @@ public: PARAMS_LIGHT = 0x20, PARAMS_SCULPT = 0x30, PARAMS_LIGHT_IMAGE = 0x40, + PARAMS_MESH = 0x50, }; public: -- cgit v1.2.3 From 564087f6b01b19b1efd2e0dee72e4bfa5d7fd9e7 Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Tue, 19 Jul 2011 15:33:43 -0400 Subject: addendum to prim fix --- indra/llprimitive/llprimitive.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) mode change 100644 => 100755 indra/llprimitive/llprimitive.h (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llprimitive.h b/indra/llprimitive/llprimitive.h old mode 100644 new mode 100755 index 8903d8e049..998016f8f6 --- a/indra/llprimitive/llprimitive.h +++ b/indra/llprimitive/llprimitive.h @@ -103,7 +103,8 @@ public: PARAMS_LIGHT = 0x20, PARAMS_SCULPT = 0x30, PARAMS_LIGHT_IMAGE = 0x40, - PARAMS_MESH = 0x50, + PARAMS_RESERVED = 0x50, // Used on server-side + PARAMS_MESH = 0x60, }; public: -- cgit v1.2.3