@@ -806,9 +806,11 @@ struct LLPanelFaceSetTEFunctor : public LLSelectedTEFunctor
806806// Functor that aligns a face to mCenterFace
807807struct LLPanelFaceSetAlignedTEFunctor : public LLSelectedTEFunctor
808808{
809- LLPanelFaceSetAlignedTEFunctor (LLPanelFace* panel, LLFace* center_face) :
809+ LLPanelFaceSetAlignedTEFunctor (LLPanelFace* panel, LLFace* center_face, bool use_pbr, LLGLTFMaterial::TextureInfo pbr_channel ) :
810810 mPanel (panel),
811- mCenterFace (center_face) {}
811+ mCenterFace (center_face),
812+ mUsePBR (use_pbr),
813+ mPBRChannel (pbr_channel) {}
812814
813815 virtual bool apply (LLViewerObject* object, S32 te)
814816 {
@@ -832,7 +834,59 @@ struct LLPanelFaceSetAlignedTEFunctor : public LLSelectedTEFunctor
832834 {
833835 LLVector2 uv_offset, uv_scale;
834836 F32 uv_rot;
837+
838+ // Store original Blinn-Phong values for restoration
839+ LLVector2 orig_offset, orig_scale;
840+ F32 orig_rot;
841+ bool need_restore = false ;
842+
843+ // For PBR materials, temporarily sync center face's Blinn-Phong to PBR
844+ // so calcAlignedPlanarTE() calculates correctly
845+ if (mUsePBR && mCenterFace )
846+ {
847+ LLViewerObject* center_obj = mCenterFace ->getViewerObject ();
848+ S32 center_te = mCenterFace ->getTEOffset ();
849+ const LLTextureEntry* center_tep = center_obj->getTE (center_te);
850+ const LLGLTFMaterial* center_mat = center_tep ? center_tep->getGLTFMaterialOverride () : nullptr ;
851+
852+ if (center_mat)
853+ {
854+ // Determine which channel to use based on selection
855+ U32 channel_idx = (mPBRChannel == LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT) ?
856+ LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR : mPBRChannel ;
857+
858+ // Store original Blinn-Phong values
859+ center_tep->getOffset (&orig_offset.mV [VX], &orig_offset.mV [VY]);
860+ center_tep->getScale (&orig_scale.mV [VX], &orig_scale.mV [VY]);
861+ orig_rot = center_tep->getRotation ();
862+ need_restore = true ;
863+
864+ // Temporarily set to PBR values for alignment calculation
865+ F32 pbr_scale_u = center_mat->mTextureTransform [channel_idx].mScale .mV [VX];
866+ F32 pbr_scale_v = center_mat->mTextureTransform [channel_idx].mScale .mV [VY];
867+ F32 pbr_rot = center_mat->mTextureTransform [channel_idx].mRotation ;
868+ F32 pbr_offset_u = center_mat->mTextureTransform [channel_idx].mOffset .mV [VX];
869+ F32 pbr_offset_v = center_mat->mTextureTransform [channel_idx].mOffset .mV [VY];
870+
871+ center_obj->setTEScale (center_te, pbr_scale_u, pbr_scale_v);
872+ center_obj->setTERotation (center_te, pbr_rot);
873+ center_obj->setTEOffset (center_te, pbr_offset_u, pbr_offset_v);
874+ }
875+ }
876+
877+ // Calculate aligned planar texture coordinates
835878 set_aligned = facep->calcAlignedPlanarTE (mCenterFace , &uv_offset, &uv_scale, &uv_rot);
879+
880+ // Restore original Blinn-Phong values if we modified them
881+ if (need_restore && mCenterFace )
882+ {
883+ LLViewerObject* center_obj = mCenterFace ->getViewerObject ();
884+ S32 center_te = mCenterFace ->getTEOffset ();
885+ center_obj->setTEScale (center_te, orig_scale.mV [VX], orig_scale.mV [VY]);
886+ center_obj->setTERotation (center_te, orig_rot);
887+ center_obj->setTEOffset (center_te, orig_offset.mV [VX], orig_offset.mV [VY]);
888+ }
889+
836890 if (set_aligned)
837891 {
838892 object->setTEOffset (te, uv_offset.mV [VX], uv_offset.mV [VY]);
@@ -851,18 +905,61 @@ struct LLPanelFaceSetAlignedTEFunctor : public LLSelectedTEFunctor
851905 LLPanelFace::LLSelectedTEMaterial::setSpecularOffsetY (mPanel , uv_offset.mV [VY], te, object->getID ());
852906 LLPanelFace::LLSelectedTEMaterial::setSpecularRepeatX (mPanel , uv_scale.mV [VX], te, object->getID ());
853907 LLPanelFace::LLSelectedTEMaterial::setSpecularRepeatY (mPanel , uv_scale.mV [VY], te, object->getID ());
908+
909+ // Also handle PBR materials if selected
910+ if (mUsePBR )
911+ {
912+ LLGLTFMaterial new_override;
913+ const LLTextureEntry* tep = object->getTE (te);
914+ if (tep->getGLTFMaterialOverride ())
915+ {
916+ new_override = *tep->getGLTFMaterialOverride ();
917+ }
918+
919+ // If channel is COUNT (4), it means "Complete material" is selected - align ALL channels
920+ if (mPBRChannel == LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT)
921+ {
922+ // Align all 4 PBR texture channels
923+ for (U32 i = 0 ; i < LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT; ++i)
924+ {
925+ new_override.mTextureTransform [i].mScale .mV [VX] = uv_scale.mV [VX];
926+ new_override.mTextureTransform [i].mScale .mV [VY] = uv_scale.mV [VY];
927+ new_override.mTextureTransform [i].mRotation = uv_rot;
928+ new_override.mTextureTransform [i].mOffset .mV [VX] = uv_offset.mV [VX];
929+ new_override.mTextureTransform [i].mOffset .mV [VY] = uv_offset.mV [VY];
930+ }
931+ }
932+ else
933+ {
934+ // Align only the selected channel
935+ new_override.mTextureTransform [mPBRChannel ].mScale .mV [VX] = uv_scale.mV [VX];
936+ new_override.mTextureTransform [mPBRChannel ].mScale .mV [VY] = uv_scale.mV [VY];
937+ new_override.mTextureTransform [mPBRChannel ].mRotation = uv_rot;
938+ new_override.mTextureTransform [mPBRChannel ].mOffset .mV [VX] = uv_offset.mV [VX];
939+ new_override.mTextureTransform [mPBRChannel ].mOffset .mV [VY] = uv_offset.mV [VY];
940+ }
941+
942+ LLGLTFMaterialList::queueModify (object, te, &new_override);
943+ }
854944 }
855945 }
856946 if (!set_aligned)
857947 {
858- LLPanelFaceSetTEFunctor setfunc (mPanel );
859- setfunc.apply (object, te);
948+ // For center face or non-alignable faces, apply current panel settings
949+ // But DON'T overwrite PBR center face with Blinn-Phong values
950+ if (!(mUsePBR && facep == mCenterFace ))
951+ {
952+ LLPanelFaceSetTEFunctor setfunc (mPanel );
953+ setfunc.apply (object, te);
954+ }
860955 }
861956 return true ;
862957 }
863958private:
864959 LLPanelFace* mPanel ;
865960 LLFace* mCenterFace ;
961+ bool mUsePBR ;
962+ LLGLTFMaterial::TextureInfo mPBRChannel ;
866963};
867964
868965struct LLPanelFaceSetAlignedConcreteTEFunctor : public LLSelectedTEFunctor
@@ -998,12 +1095,23 @@ struct LLPanelFaceSendFunctor : public LLSelectedObjectFunctor
9981095
9991096void LLPanelFace::sendTextureInfo ()
10001097{
1001- if (mPlanarAlign ->getValue ().asBoolean ())
1098+ bool planar_align = mPlanarAlign ->getValue ().asBoolean ();
1099+ bool pbr_selected = mComboMatMedia ->getCurrentIndex () == MATMEDIA_PBR;
1100+
1101+ if (planar_align)
10021102 {
10031103 LLFace* last_face = NULL ;
1004- bool identical_face =false ;
1104+ bool identical_face = false ;
10051105 LLSelectedTE::getFace (last_face, identical_face);
1006- LLPanelFaceSetAlignedTEFunctor setfunc (this , last_face);
1106+
1107+ // Get PBR texture info if PBR is selected
1108+ LLGLTFMaterial::TextureInfo pbr_channel = LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT;
1109+ if (pbr_selected)
1110+ {
1111+ pbr_channel = getPBRTextureInfo ();
1112+ }
1113+
1114+ LLPanelFaceSetAlignedTEFunctor setfunc (this , last_face, pbr_selected, pbr_channel);
10071115 LLSelectMgr::getInstance ()->getSelection ()->applyToTEs (&setfunc);
10081116 }
10091117 else
@@ -1022,8 +1130,22 @@ void LLPanelFace::alignTextureLayer()
10221130 bool identical_face = false ;
10231131 LLSelectedTE::getFace (last_face, identical_face);
10241132
1025- LLPanelFaceSetAlignedConcreteTEFunctor setfunc (this , last_face, static_cast <LLRender::eTexIndex>(mRadioMaterialType ->getSelectedIndex ()));
1026- LLSelectMgr::getInstance ()->getSelection ()->applyToTEs (&setfunc);
1133+ bool pbr_selected = mComboMatMedia ->getCurrentIndex () == MATMEDIA_PBR;
1134+
1135+ if (pbr_selected)
1136+ {
1137+ // Use unified functor with PBR support
1138+ LLGLTFMaterial::TextureInfo texture_info = getPBRTextureInfo ();
1139+ LLPanelFaceSetAlignedTEFunctor setfunc (this , last_face, true , texture_info);
1140+ LLSelectMgr::getInstance ()->getSelection ()->applyToTEs (&setfunc);
1141+ }
1142+ else
1143+ {
1144+ // Use existing concrete functor for Blinn-Phong specific alignment
1145+ S32 material_type = mRadioMaterialType ->getSelectedIndex ();
1146+ LLPanelFaceSetAlignedConcreteTEFunctor setfunc (this , last_face, static_cast <LLRender::eTexIndex>(material_type));
1147+ LLSelectMgr::getInstance ()->getSelection ()->applyToTEs (&setfunc);
1148+ }
10271149}
10281150
10291151void LLPanelFace::getState ()
@@ -3616,7 +3738,7 @@ void LLPanelFace::onCommitMaterialBumpyRot()
36163738 LLFace* last_face = NULL ;
36173739 bool identical_face = false ;
36183740 LLSelectedTE::getFace (last_face, identical_face);
3619- LLPanelFaceSetAlignedTEFunctor setfunc (this , last_face);
3741+ LLPanelFaceSetAlignedTEFunctor setfunc (this , last_face, false , LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT );
36203742 LLSelectMgr::getInstance ()->getSelection ()->applyToTEs (&setfunc);
36213743 }
36223744 else
@@ -3640,7 +3762,7 @@ void LLPanelFace::onCommitMaterialShinyRot()
36403762 LLFace* last_face = NULL ;
36413763 bool identical_face = false ;
36423764 LLSelectedTE::getFace (last_face, identical_face);
3643- LLPanelFaceSetAlignedTEFunctor setfunc (this , last_face);
3765+ LLPanelFaceSetAlignedTEFunctor setfunc (this , last_face, false , LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT );
36443766 LLSelectMgr::getInstance ()->getSelection ()->applyToTEs (&setfunc);
36453767 }
36463768 else
0 commit comments