diff options
author | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2010-11-05 16:17:54 -0400 |
---|---|---|
committer | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2010-11-05 16:17:54 -0400 |
commit | 7318214ed30f57fe04dd7828fffede949fee6245 (patch) | |
tree | 71f22a09fe50176e9b7664611f7ad3addc254ec9 /indra/llprimitive | |
parent | ddff1c68f22fbee00178d223eaac382836dba5f7 (diff) | |
parent | 4a8066856756cc9153cfab398a9a9b277a9a5e5d (diff) |
merge
Diffstat (limited to 'indra/llprimitive')
-rw-r--r-- | indra/llprimitive/llmodel.cpp | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 7fa72d82e1..f7eafb2fff 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -875,6 +875,14 @@ void LLModel::optimizeVolumeFaces() #endif } +// Shrink the model to fit +// on a 1x1x1 cube centered at the origin. +// The positions and extents +// multiplied by mNormalizedScale +// and offset by mNormalizedTranslation +// to be the "original" extents and position. +// Also, the positions will fit +// within the unit cube. void LLModel::normalizeVolumeFaces() { @@ -891,6 +899,10 @@ void LLModel::normalizeVolumeFaces() llerrs << "WTF?" << llendl; } + // For all of the volume faces + // in the model, loop over + // them and see what the extents + // of the volume along each axis. min = mVolumeFaces[0].mExtents[0]; max = mVolumeFaces[0].mExtents[1]; @@ -907,32 +919,55 @@ void LLModel::normalizeVolumeFaces() update_min_max(min, max, face.mExtents[1]); } + // Now that we have the extents of the model + // we can compute the offset needed to center + // the model at the origin. + + // Compute center of the model + // and make it negative to get translation + // needed to center at origin. LLVector4a trans; trans.setAdd(min, max); trans.mul(-0.5f); + + // Compute the total size along all + // axes of the model. LLVector4a size; size.setSub(max, min); + // To make the model fit within + // the unit cube with only the largest + // dimensions fitting on the surface of the cube, + // calculate the largest extent on any axis F32 scale = 1.f/llmax(llmax(size[0], size[1]), size[2]); for (U32 i = 0; i < mVolumeFaces.size(); ++i) { LLVolumeFace& face = mVolumeFaces[i]; - + + // We shrink the extents so + // that they fall within + // the unit cube. face.mExtents[0].add(trans); face.mExtents[0].mul(scale); face.mExtents[1].add(trans); face.mExtents[1].mul(scale); + // For all the positions, we scale + // the positions to fit within the unit cube. LLVector4a* pos = (LLVector4a*) face.mPositions; for (U32 j = 0; j < face.mNumVertices; ++j) { - pos[j].add(trans); + pos[j].add(trans); pos[j].mul(scale); } } + // mNormalizedScale is the scale at which + // we would need to multiply the model + // by to get the original size of the + // model instead of the normalized size. mNormalizedScale = LLVector3(1,1,1) / scale; mNormalizedTranslation.set(trans.getF32ptr()); mNormalizedTranslation *= -1.f; @@ -1449,9 +1484,7 @@ LLSD LLModel::writeModel( { U32 size = decomp[i].size(); total += size; - // The valid range of sizes is actually 3-256 verts. We need this to fit into a U8, - // So we just subtract 1 - hulls[i] = (U8) (size - 1); + hulls[i] = (U8) (size); for (U32 j = 0; j < decomp[i].size(); ++j) { |