aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llface.cpp
diff options
context:
space:
mode:
authorMcCabe Maxsted2010-04-30 04:43:58 -0700
committerJacek Antonelli2010-06-19 02:43:28 -0500
commitb9e1ca3150cb9553bfbb7a15c90761e9a400f6b9 (patch)
tree2a99be246f51f7ba57f39857f89f7c6a2255c8fc /linden/indra/newview/llface.cpp
parentClarified the simulator version change chat message with some text (diff)
downloadmeta-impy-b9e1ca3150cb9553bfbb7a15c90761e9a400f6b9.zip
meta-impy-b9e1ca3150cb9553bfbb7a15c90761e9a400f6b9.tar.gz
meta-impy-b9e1ca3150cb9553bfbb7a15c90761e9a400f6b9.tar.bz2
meta-impy-b9e1ca3150cb9553bfbb7a15c90761e9a400f6b9.tar.xz
Applied patch for SNOW-586 by Thickbrick Sleaford: Add option to align textures across (planar-mapped, co-planar) faces
Was accidentally left out of a rebase
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llface.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/linden/indra/newview/llface.cpp b/linden/indra/newview/llface.cpp
index dab1dac..aa8cd15 100644
--- a/linden/indra/newview/llface.cpp
+++ b/linden/indra/newview/llface.cpp
@@ -801,6 +801,72 @@ LLVector2 LLFace::surfaceToTexture(LLVector2 surface_coord, LLVector3 position,
801 return tc; 801 return tc;
802} 802}
803 803
804// Returns scale compared to default texgen, and face orientation as calculated
805// by planarProjection(). This is needed to match planar texgen parameters.
806void LLFace::getPlanarProjectedParams(LLQuaternion* face_rot, LLVector3* face_pos, F32* scale) const
807{
808 const LLVolumeFace& vf = getViewerObject()->getVolume()->getVolumeFace(mTEOffset);
809 LLVector3 normal = vf.mVertices[0].mNormal;
810 LLVector3 binormal = vf.mVertices[0].mBinormal;
811 LLVector2 projected_binormal;
812 planarProjection(projected_binormal, normal, vf.mCenter, binormal);
813 projected_binormal -= LLVector2(0.5f, 0.5f); // this normally happens in xform()
814 *scale = projected_binormal.length();
815 // rotate binormal to match what planarProjection() thinks it is,
816 // then find face's rotation from normal and rotated binormal:
817 projected_binormal.normalize();
818 F32 ang = acos(projected_binormal.mV[VY]);
819 ang = (projected_binormal.mV[VX] < 0.f) ? -ang : ang;
820 binormal.rotVec(ang, normal);
821 LLQuaternion local_rot( binormal % normal, binormal, normal );
822 *face_rot = local_rot * mXform->getWorldRotation();
823 *face_pos = mXform->getWorldPosition();
824}
825
826// Returns the necessary texture transform to align this face's TE to align_to's TE
827bool LLFace::calcAlignedPlanarTE(const LLFace* align_to, LLVector2* res_st_offset,
828 LLVector2* res_st_scale, F32* res_st_rot) const
829{
830 if (!align_to)
831 {
832 return false;
833 }
834 const LLTextureEntry *orig_tep = align_to->getTextureEntry();
835 if ((orig_tep->getTexGen() != LLTextureEntry::TEX_GEN_PLANAR) ||
836 (getTextureEntry()->getTexGen() != LLTextureEntry::TEX_GEN_PLANAR))
837 {
838 return false;
839 }
840
841 LLVector3 orig_pos, this_pos;
842 LLQuaternion orig_face_rot, this_face_rot;
843 F32 orig_proj_scale, this_proj_scale;
844 align_to->getPlanarProjectedParams(&orig_face_rot, &orig_pos, &orig_proj_scale);
845 getPlanarProjectedParams(&this_face_rot, &this_pos, &this_proj_scale);
846
847 // The rotation of "this face's" texture:
848 LLQuaternion orig_st_rot = LLQuaternion(orig_tep->getRotation(), LLVector3::z_axis) * orig_face_rot;
849 LLQuaternion this_st_rot = orig_st_rot * ~this_face_rot;
850 F32 x_ang, y_ang, z_ang;
851 this_st_rot.getEulerAngles(&x_ang, &y_ang, &z_ang);
852 *res_st_rot = z_ang;
853
854 // Offset and scale of "this face's" texture:
855 LLVector3 centers_dist = (this_pos - orig_pos) * ~orig_st_rot;
856 LLVector3 st_scale(orig_tep->mScaleS, orig_tep->mScaleT, 1.f);
857 st_scale *= orig_proj_scale;
858 centers_dist.scaleVec(st_scale);
859 LLVector2 orig_st_offset(orig_tep->mOffsetS, orig_tep->mOffsetT);
860
861 *res_st_offset = orig_st_offset + (LLVector2)centers_dist;
862 res_st_offset->mV[VX] -= (S32)res_st_offset->mV[VX];
863 res_st_offset->mV[VY] -= (S32)res_st_offset->mV[VY];
864
865 st_scale /= this_proj_scale;
866 *res_st_scale = (LLVector2)st_scale;
867 return true;
868}
869
804void LLFace::updateRebuildFlags() 870void LLFace::updateRebuildFlags()
805{ 871{
806 if (!mDrawablep->isState(LLDrawable::REBUILD_VOLUME)) 872 if (!mDrawablep->isState(LLDrawable::REBUILD_VOLUME))