From 9cb31845bafe9188d9f90dc1330355c73fb96851 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 4 May 2011 20:45:14 -0500 Subject: SH-1497 Update mesh asset parser to use new format restrictions. --- indra/llprimitive/llmodel.cpp | 122 ++++++++++++------------------------------ 1 file changed, 34 insertions(+), 88 deletions(-) (limited to 'indra/llprimitive/llmodel.cpp') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 794cdb83d5..66b5150ed4 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -50,7 +50,7 @@ std::string model_names[] = "low_lod", "medium_lod", "high_lod", - "physics_shape" + "physics_mesh" }; const int MODEL_NAMES_LENGTH = sizeof(model_names) / sizeof(std::string); @@ -1403,25 +1403,15 @@ LLSD LLModel::writeModel( if (!decomp.mBaseHull.empty() || !decomp.mHull.empty()) { - mdl["decomposition"] = decomp.asLLSD(); + mdl["physics_convex"] = decomp.asLLSD(); } for (U32 idx = 0; idx < MODEL_NAMES_LENGTH; ++idx) { if (model[idx] && model[idx]->getNumVolumeFaces() > 0) { - LLVector3 min_pos = LLVector3(model[idx]->getVolumeFace(0).mPositions[0].getF32ptr()); - LLVector3 max_pos = min_pos; - - //find position domain - for (S32 i = 0; i < model[idx]->getNumVolumeFaces(); ++i) - { //for each face - const LLVolumeFace& face = model[idx]->getVolumeFace(i); - for (U32 j = 0; j < face.mNumVertices; ++j) - { - update_min_max(min_pos, max_pos, face.mPositions[j].getF32ptr()); - } - } + LLVector3 min_pos(-0.5f, -0.5f, -0.5f); + LLVector3 max_pos(0.5f, 0.5f, 0.5f); LLVector3 pos_range = max_pos - min_pos; @@ -1462,6 +1452,7 @@ LLSD LLModel::writeModel( //position + normal for (U32 k = 0; k < 3; ++k) { //for each component + llassert(pos[k] <= 0.5001f && pos[k] >= -0.5001f); //convert to 16-bit normalized across domain U16 val = (U16) (((pos[k]-min_pos.mV[k])/pos_range.mV[k])*65535); @@ -1504,9 +1495,6 @@ 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(); @@ -1608,15 +1596,15 @@ LLSD LLModel::writeModelToStream(std::ostream& ostr, LLSD& mdl, BOOL nowrite) std::string decomposition; - if (mdl.has("decomposition")) + if (mdl.has("physics_convex")) { //write out convex decomposition - decomposition = zip_llsd(mdl["decomposition"]); + decomposition = zip_llsd(mdl["physics_convex"]); U32 size = decomposition.size(); if (size > 0) { - header["decomposition"]["offset"] = (LLSD::Integer) cur_offset; - header["decomposition"]["size"] = (LLSD::Integer) size; + header["physics_convex"]["offset"] = (LLSD::Integer) cur_offset; + header["physics_convex"]["size"] = (LLSD::Integer) size; cur_offset += size; bytes += size; } @@ -1637,11 +1625,6 @@ LLSD LLModel::writeModelToStream(std::ostream& ostr, LLSD& mdl, BOOL nowrite) cur_offset += size; bytes += size; } - else - { - header[model_names[i]]["offset"] = -1; - header[model_names[i]]["size"] = 0; - } } if (!nowrite) @@ -1655,7 +1638,7 @@ LLSD LLModel::writeModelToStream(std::ostream& ostr, LLSD& mdl, BOOL nowrite) if (!decomposition.empty()) { //write decomposition block - ostr.write((const char*) decomposition.data(), header["decomposition"]["size"].asInteger()); + ostr.write((const char*) decomposition.data(), header["physics_convex"]["size"].asInteger()); } for (S32 i = 0; i < MODEL_NAMES_LENGTH; i++) @@ -1794,7 +1777,7 @@ bool LLModel::loadModel(std::istream& is) "low_lod", "medium_lod", "high_lod", - "physics_shape", + "physics_mesh", }; const S32 MODEL_LODS = 5; @@ -1893,8 +1876,8 @@ bool LLModel::loadSkinInfo(LLSD& header, std::istream &is) bool LLModel::loadDecomposition(LLSD& header, std::istream& is) { - S32 offset = header["decomposition"]["offset"].asInteger(); - S32 size = header["decomposition"]["size"].asInteger(); + S32 offset = header["physics_convex"]["offset"].asInteger(); + S32 size = header["physics_convex"]["size"].asInteger(); if (offset >= 0 && size > 0) { @@ -2040,15 +2023,10 @@ void LLModel::Decomposition::fromLLSD(LLSD& decomp) mHull.resize(hulls.size()); - LLVector3 min; - LLVector3 max; - LLVector3 range; - - min.setValue(decomp["Min"]); - max.setValue(decomp["Max"]); - range = max-min; + LLVector3 min(-0.5f,-0.5f,-0.5f); + LLVector3 max(0.5f,0.5f,0.5f); + LLVector3 range = max-min; - for (U32 i = 0; i < hulls.size(); ++i) { U16 count = (hulls[i] == 0) ? 256 : hulls[i]; @@ -2064,6 +2042,7 @@ void LLModel::Decomposition::fromLLSD(LLSD& decomp) //point must be unique //llassert(valid.find(test) == valid.end()); valid.insert(test); + 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], @@ -2078,28 +2057,15 @@ void LLModel::Decomposition::fromLLSD(LLSD& decomp) } } - if (decomp.has("Hull")) + if (decomp.has("BoundingVerts")) { - const LLSD::Binary& position = decomp["Hull"].asBinary(); + const LLSD::Binary& position = decomp["BundingVerts"].asBinary(); U16* p = (U16*) &position[0]; - LLVector3 min; - LLVector3 max; - LLVector3 range; - - if (decomp.has("Min")) - { - min.setValue(decomp["Min"]); - max.setValue(decomp["Max"]); - } - else - { - min.set(-0.5f, -0.5f, -0.5f); - max.set(0.5f, 0.5f, 0.5f); - } - - range = max-min; + LLVector3 min(-0.5f,-0.5f,-0.5f); + LLVector3 max(0.5f,0.5f,0.5f); + LLVector3 range = max-min; U16 count = position.size()/6; @@ -2130,26 +2096,11 @@ LLSD LLModel::Decomposition::asLLSD() const } //write decomposition block - // ["decomposition"]["HullList"] -- list of 8 bit integers, each entry represents a hull with specified number of points - // ["decomposition"]["PositionDomain"]["Min"/"Max"] - // ["decomposition"]["Position"] -- list of 16-bit integers to be decoded to given domain, encoded 3D points - // ["decomposition"]["Hull"] -- list of 16-bit integers to be decoded to given domain, encoded 3D points representing a single hull approximation of given shape - + // ["physics_convex"]["HullList"] -- list of 8 bit integers, each entry represents a hull with specified number of points + // ["physics_convex"]["Position"] -- list of 16-bit integers to be decoded to given domain, encoded 3D points + // ["physics_convex"]["BoundingVerts"] -- list of 16-bit integers to be decoded to given domain, encoded 3D points representing a single hull approximation of given shape - //get minimum and maximum - LLVector3 min; - if (mHull.empty()) - { - min = mBaseHull[0]; - } - else - { - min = mHull[0][0]; - } - - LLVector3 max = min; - LLSD::Binary hulls(mHull.size()); U32 total = 0; @@ -2159,21 +2110,8 @@ LLSD LLModel::Decomposition::asLLSD() const U32 size = mHull[i].size(); total += size; hulls[i] = (U8) (size); - - for (U32 j = 0; j < mHull[i].size(); ++j) - { - update_min_max(min, max, mHull[i][j]); - } - } - - for (U32 i = 0; i < mBaseHull.size(); ++i) - { - update_min_max(min, max, mBaseHull[i]); } - ret["Min"] = min.getValue(); - ret["Max"] = max.getValue(); - if (!hulls.empty()) { ret["HullList"] = hulls; @@ -2183,6 +2121,8 @@ 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; @@ -2198,6 +2138,8 @@ LLSD LLModel::Decomposition::asLLSD() const U64 test = 0; for (U32 k = 0; k < 3; k++) { + llassert(mHull[i][j].mV[k] <= 0.50001f && mHull[i][j].mV[k] >= -0.50001f); + //convert to 16-bit normalized across domain U16 val = (U16) (((mHull[i][j].mV[k]-min.mV[k])/range.mV[k])*65535); @@ -2231,6 +2173,8 @@ 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; @@ -2238,6 +2182,8 @@ LLSD LLModel::Decomposition::asLLSD() const { for (U32 k = 0; k < 3; k++) { + llassert(mBaseHull[j].mV[k] <= 0.50001f && mBaseHull[j].mV[k] >= -0.50001f); + //convert to 16-bit normalized across domain U16 val = (U16) (((mBaseHull[j].mV[k]-min.mV[k])/range.mV[k])*65535); @@ -2253,7 +2199,7 @@ LLSD LLModel::Decomposition::asLLSD() const } } - ret["Hull"] = p; + ret["BoundingVerts"] = p; } return ret; -- cgit v1.2.3 From 3c516973f3a508d2bf0060d8dc70fa0d7809340f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 5 May 2011 17:12:41 -0500 Subject: SH-1497 "Positions" not "Position" for convex decomp. --- indra/llprimitive/llmodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llprimitive/llmodel.cpp') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 66b5150ed4..ebd2fc7a29 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -2017,7 +2017,7 @@ void LLModel::Decomposition::fromLLSD(LLSD& decomp) { // 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(); + const LLSD::Binary& position = decomp["Positions"].asBinary(); U16* p = (U16*) &position[0]; @@ -2166,7 +2166,7 @@ LLSD LLModel::Decomposition::asLLSD() const llassert(valid.size() > 3); } - ret["Position"] = p; + ret["Positions"] = p; } if (!mBaseHull.empty()) -- cgit v1.2.3 From ca0a568264ca1f9990b2450cc55f3cc011d59e63 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 5 May 2011 18:33:03 -0500 Subject: SH-1497 Don't upload physics mesh if decomposition exists. --- indra/llprimitive/llmodel.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'indra/llprimitive/llmodel.cpp') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index ebd2fc7a29..e9e212c5c6 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -1404,6 +1404,10 @@ LLSD LLModel::writeModel( !decomp.mHull.empty()) { mdl["physics_convex"] = decomp.asLLSD(); + if (!decomp.mHull.empty()) + { //convex decomposition exists, physics mesh will not be used + model[LLModel::LOD_PHYSICS] = NULL; + } } for (U32 idx = 0; idx < MODEL_NAMES_LENGTH; ++idx) @@ -2138,10 +2142,12 @@ LLSD LLModel::Decomposition::asLLSD() const U64 test = 0; for (U32 k = 0; k < 3; k++) { - llassert(mHull[i][j].mV[k] <= 0.50001f && mHull[i][j].mV[k] >= -0.50001f); + F32* src = (F32*) (mHull[i][j].mV); + + llassert(src[k] <= 0.501f && src[k] >= -0.501f); //convert to 16-bit normalized across domain - U16 val = (U16) (((mHull[i][j].mV[k]-min.mV[k])/range.mV[k])*65535); + U16 val = (U16) (((src[k]-min.mV[k])/range.mV[k])*65535); switch (k) { -- cgit v1.2.3 From 3acc3d39f0309a8e812838e22a8ff3eafe8da195 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 11 May 2011 19:13:18 -0500 Subject: Put back "PositionDomain" and "Min"/"Max" on convex decomposition. --- indra/llprimitive/llmodel.cpp | 82 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 10 deletions(-) (limited to 'indra/llprimitive/llmodel.cpp') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index e9e212c5c6..24d9a3a1e2 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -1414,8 +1414,18 @@ LLSD LLModel::writeModel( { if (model[idx] && model[idx]->getNumVolumeFaces() > 0) { - LLVector3 min_pos(-0.5f, -0.5f, -0.5f); - LLVector3 max_pos(0.5f, 0.5f, 0.5f); + LLVector3 min_pos = LLVector3(model[idx]->getVolumeFace(0).mPositions[0].getF32ptr()); + LLVector3 max_pos = min_pos; + + //find position domain + for (S32 i = 0; i < model[idx]->getNumVolumeFaces(); ++i) + { //for each face + const LLVolumeFace& face = model[idx]->getVolumeFace(i); + for (U32 j = 0; j < face.mNumVertices; ++j) + { + update_min_max(min_pos, max_pos, face.mPositions[j].getF32ptr()); + } + } LLVector3 pos_range = max_pos - min_pos; @@ -1456,8 +1466,6 @@ LLSD LLModel::writeModel( //position + normal for (U32 k = 0; k < 3; ++k) { //for each component - llassert(pos[k] <= 0.5001f && pos[k] >= -0.5001f); - //convert to 16-bit normalized across domain U16 val = (U16) (((pos[k]-min_pos.mV[k])/pos_range.mV[k])*65535); @@ -1499,6 +1507,8 @@ 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(); @@ -2027,9 +2037,22 @@ void LLModel::Decomposition::fromLLSD(LLSD& decomp) mHull.resize(hulls.size()); - LLVector3 min(-0.5f,-0.5f,-0.5f); - LLVector3 max(0.5f,0.5f,0.5f); - LLVector3 range = max-min; + LLVector3 min; + LLVector3 max; + LLVector3 range; + + if (decomp.has("Min")) + { + min.setValue(decomp["Min"]); + max.setValue(decomp["Max"]); + } + else + { + min.set(-0.5f, -0.5f, -0.5f); + max.set(0.5f, 0.5f, 0.5f); + } + + range = max-min; for (U32 i = 0; i < hulls.size(); ++i) { @@ -2067,9 +2090,22 @@ void LLModel::Decomposition::fromLLSD(LLSD& decomp) U16* p = (U16*) &position[0]; - LLVector3 min(-0.5f,-0.5f,-0.5f); - LLVector3 max(0.5f,0.5f,0.5f); - LLVector3 range = max-min; + LLVector3 min; + LLVector3 max; + LLVector3 range; + + if (decomp.has("Min")) + { + min.setValue(decomp["Min"]); + max.setValue(decomp["Max"]); + } + else + { + min.set(-0.5f, -0.5f, -0.5f); + max.set(0.5f, 0.5f, 0.5f); + } + + range = max-min; U16 count = position.size()/6; @@ -2104,7 +2140,20 @@ LLSD LLModel::Decomposition::asLLSD() const // ["physics_convex"]["Position"] -- list of 16-bit integers to be decoded to given domain, encoded 3D points // ["physics_convex"]["BoundingVerts"] -- list of 16-bit integers to be decoded to given domain, encoded 3D points representing a single hull approximation of given shape + //get minimum and maximum + LLVector3 min; + if (mHull.empty()) + { + min = mBaseHull[0]; + } + else + { + min = mHull[0][0]; + } + + LLVector3 max = min; + LLSD::Binary hulls(mHull.size()); U32 total = 0; @@ -2114,8 +2163,21 @@ LLSD LLModel::Decomposition::asLLSD() const U32 size = mHull[i].size(); total += size; hulls[i] = (U8) (size); + + for (U32 j = 0; j < mHull[i].size(); ++j) + { + update_min_max(min, max, mHull[i][j]); + } } + for (U32 i = 0; i < mBaseHull.size(); ++i) + { + update_min_max(min, max, mBaseHull[i]); + } + + ret["Min"] = min.getValue(); + ret["Max"] = max.getValue(); + if (!hulls.empty()) { ret["HullList"] = hulls; -- cgit v1.2.3